chore: only init cert.Leaf when not populated

since Go 1.23, cert.Leaf will be populated after loaded.

see doc of tls.LoadX509KeyPair for details
This commit is contained in:
Haruue 2024-08-24 13:41:46 +08:00
parent 45893b5d1e
commit bcf830c29a
No known key found for this signature in database
GPG Key ID: F6083B28CBCBC148

View File

@ -94,9 +94,12 @@ func (l *LocalCertificateLoader) makeCache() (cache *localCertificateCache, err
return return
} }
c.certificate = &cert c.certificate = &cert
c.certificate.Leaf, err = x509.ParseCertificate(cert.Certificate[0]) if c.certificate.Leaf == nil {
if err != nil { // certificate.Leaf was left nil by tls.LoadX509KeyPair before Go 1.23
return c.certificate.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
if err != nil {
return
}
} }
cache = c cache = c