parseCertsFromPEMBundle parses a certificate bundle from top to bottom and returns a slice of x509 certificates. This function will error if no certificates are found.
(bundle []byte)
| 110 | // parseCertsFromPEMBundle parses a certificate bundle from top to bottom and returns |
| 111 | // a slice of x509 certificates. This function will error if no certificates are found. |
| 112 | func parseCertsFromPEMBundle(bundle []byte) ([]*x509.Certificate, error) { |
| 113 | var certificates []*x509.Certificate |
| 114 | var certDERBlock *pem.Block |
| 115 | for { |
| 116 | certDERBlock, bundle = pem.Decode(bundle) |
| 117 | if certDERBlock == nil { |
| 118 | break |
| 119 | } |
| 120 | if certDERBlock.Type == "CERTIFICATE" { |
| 121 | cert, err := x509.ParseCertificate(certDERBlock.Bytes) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | certificates = append(certificates, cert) |
| 126 | } |
| 127 | } |
| 128 | if len(certificates) == 0 { |
| 129 | return nil, fmt.Errorf("no certificates found in bundle") |
| 130 | } |
| 131 | return certificates, nil |
| 132 | } |
| 133 | |
| 134 | // fastHash hashes input using a hashing algorithm that |
| 135 | // is fast, and returns the hash as a hex-encoded string. |
no outgoing calls
no test coverage detected
searching dependent graphs…