Created
March 31, 2013 20:44
-
-
Save agl/5281933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/x509" | |
"fmt" | |
"io/ioutil" | |
"sync" | |
"strconv" | |
) | |
func worker(work chan int, wg *sync.WaitGroup) { | |
defer wg.Done() | |
for num := range work { | |
derBytes, err := ioutil.ReadFile(strconv.Itoa(num)) | |
if err != nil { | |
panic(err) | |
} | |
cert, err := x509.ParseCertificate(derBytes) | |
if err != nil { | |
// Uncomment this to report parsing errors. | |
// fmt.Printf("%d: %s\n", num, err) | |
continue | |
} | |
if cert.BasicConstraintsValid && cert.IsCA { | |
fmt.Printf("%d\n", num) | |
} | |
} | |
} | |
func main() { | |
wg := new(sync.WaitGroup) | |
work := make(chan int, 32) | |
const numWorkers = 8 | |
for i := 0; i < numWorkers; i++ { | |
go worker(work, wg) | |
wg.Add(1) | |
} | |
for i := 0; i < 844284; i++ { | |
work <- i | |
} | |
close(work) | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment