Skip to content

Instantly share code, notes, and snippets.

@agl
Created March 31, 2013 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agl/5281933 to your computer and use it in GitHub Desktop.
Save agl/5281933 to your computer and use it in GitHub Desktop.
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