Skip to content

Instantly share code, notes, and snippets.

@agl agl/cacerts.go
Created Mar 31, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.