certgen/tls-leaf.go

22 lines
407 B
Go
Raw Permalink Normal View History

2022-03-13 01:45:20 +00:00
package certgen
import (
"crypto/tls"
"crypto/x509"
)
func TlsLeaf(cert *tls.Certificate) *x509.Certificate {
// return the existing leaf
2022-03-13 01:45:20 +00:00
if cert.Leaf != nil {
return cert.Leaf
}
2022-03-13 01:45:20 +00:00
if len(cert.Certificate) >= 1 {
// if there is a certificate then validate, parse and set the leaf
2022-03-13 01:45:20 +00:00
if a, err := x509.ParseCertificate(cert.Certificate[0]); err == nil {
cert.Leaf = a
}
}
return cert.Leaf
}