MCPcopy
hub / github.com/caddyserver/certmagic / parseCertsFromPEMBundle

Function parseCertsFromPEMBundle

crypto.go:112–132  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
112func 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.

Callers 5

getOCSPForCertFunction · 0.85
selectPreferredChainMethod · 0.85
RevokeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…