package tls
import (
)
type weakCertCache struct{ sync.Map }
func ( *weakCertCache) ( []byte) (*x509.Certificate, error) {
if , := .Load(string()); {
if := .(weak.Pointer[x509.Certificate]).Value(); != nil {
return , nil
}
}
, := x509.ParseCertificate()
if != nil {
return nil,
}
:= weak.Make()
if , := .LoadOrStore(string(), ); ! {
runtime.AddCleanup(, func( any) { .CompareAndDelete(string(), ) }, any(string()))
} else if := .(weak.Pointer[x509.Certificate]).Value(); != nil {
return , nil
} else {
if .CompareAndSwap(string(), , ) {
runtime.AddCleanup(, func( any) { .CompareAndDelete(string(), ) }, any(string()))
}
}
return , nil
}
var globalCertCache = new(weakCertCache)