Golang crypto/x509.ParseCRL function example

package crypto/x509

ParseCRL parses a CRL from the given bytes. It's often the case that PEM encoded CRLs will appear where they should be DER encoded, so this function will transparently handle PEM encoding as long as there isn't any leading garbage.

Golang crypto/x509.ParseCRL function usage example

 package main

 import (
 "crypto/x509"
 "os"
 "fmt"
 )

 func main() {

 var crlBytes = `-----BEGIN X509 CRL-----
 MIIBmjCCAQMwDQYJKoZIhvcNAQEEBQAwgb0xCzAJBgNVBAYTAlVTMRMwEQYDVQQI
 EwpDYWxpZm9ybmlhMRAwDgYDVQQHEwdPYWtsYW5kMRYwFAYDVQQKEw1SZWQgSGF0
 LCBJbmMuMSIwIAYDVQQLFBlHbG9iYWwgU2VydmljZXMgJiBTdXBwb3J0MR0wGwYD
 VQQDExRSZWQgSGF0IFRlc3QgUm9vdCBDQTEsMCoGCSqGSIb3DQEJARYdc3Ryb25n
 aG9sZC1zdXBwb3J0QHJlZGhhdC5jb20XDTAwMTExMzIwNTcyNVoXDTAwMTIxMzIw
 NTcyNVowFDASAgEBFw0wMDA4MzEyMTE5MTdaMA0GCSqGSIb3DQEBBAUAA4GBAIge
 X5VaOkNOKn8MrbxFiqpOrH/M9Vocu9oDeQ6EMTeA5xIWBGN53BZ/HUJ1NjS32VDG
 waM3P6DXud4xKXauVgAXyH6D6xEDBt5GIBTFrWKIDKGOkvRChTUvzObmx9ZVSMMg
 5xvAbsaFgJx3RBbznySlqVU4APYE0W2/xL0/8fzM
 -----END X509 CRL-----`


 certList, err := x509.ParseCRL([]byte(crlBytes))

 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

 fmt.Printf("TBSCertList : %v\n\n", certList.TBSCertList)
 fmt.Printf("SignatureAlgorithm : %v\n\n", certList.SignatureAlgorithm)
 fmt.Printf("SignatureValue : %v\n\n", certList.SignatureValue)
 }

Reference :

http://www.apacheweek.com/features/crl

http://golang.org/pkg/crypto/x509/#ParseCRL

Advertisement