// worker does all the parsing and validation of the certificate(s)
// contained in a single file. It first reads all the data in the
// file, then begins parsing certificates in the file. Those
// certificates are then checked for revocation.
worker does all the parsing and validation of the certificate(s)
contained in a single file. It first reads all the data in the
file, then begins parsing certificates in the file. Those
certificates are then checked for revocation.
// worker does all the parsing and validation of the certificate ( s ) // contained in a single file . It first reads all the data in the // file then begins parsing certificates in the file . Those // certificates are then checked for revocation .
func worker(paths chan string, bundler chan *x509.Certificate, pool *sync.WaitGroup) {
	defer (*pool).Done()
	for {
		path, ok := <-paths
		if !ok {
			return
		}
		log.Infof("Loading %s", path)
		fileData, err := ioutil.ReadFile(path)
		if err != nil {
			log.Warningf("%v", err)
			continue
		}
		for {
			var block *pem.Block
			if len(fileData) == 0 {
				break
			}
			block, fileData = pem.Decode(fileData)
			if block == nil {
				log.Warningf("%s: no PEM data found", path)
				break
			} else if block.Type != "CERTIFICATE" {
				log.Info("Skipping non-certificate")
				continue
			}
			cert, err := x509.ParseCertificate(block.Bytes)
			if err != nil {
				log.Warningf("Invalid certificate: %v", err)
				continue
			}
			log.Infof("Validating %+v", cert.Subject)
			revoked, ok := revoke.VerifyCertificate(cert)
			if !ok {
				log.Warning("Failed to verify certificate.")
			} else if !revoked {
				bundler <- cert
			} else {
				log.Info("Skipping revoked certificate")
			}
		}
	}
}
func worker ( paths chan string , bundler chan * x509 . Certificate , pool * sync . WaitGroup ) { defer ( * pool ) . Done ( ) for { path , ok := <- paths if ! ok { return } log . Infof ( " " , path ) fileData , err := ioutil . ReadFile ( path ) if err != nil { log . Warningf ( " " , err ) continue } for { var block * pem . Block if len ( fileData ) == 0 { break } block , fileData = pem . Decode ( fileData ) if block == nil { log . Warningf ( " " , path ) break } else if block . Type != " " { log . Info ( " " ) continue } cert , err := x509 . ParseCertificate ( block . Bytes ) if err != nil { log . Warningf ( " " , err ) continue } log . Infof ( " " , cert . Subject ) revoked , ok := revoke . VerifyCertificate ( cert ) if ! ok { log . Warning ( " " ) } else if ! revoked { bundler <- cert } else { log . Info ( " " ) } } } }
worker does all the parsing and validation of the certificate(s)
contained in a single file.
worker does all the parsing and validation of the certificate ( s ) contained in a single file .