Source File
cert_pool.go
Belonging Package
crypto/x509
getCert func() (*Certificate, error)
}
func ( *CertPool) ( int) (*Certificate, error) {
return .lazyCerts[].getCert()
}
func ( *CertPool) () *CertPool {
:= &CertPool{
byName: make(map[string][]int, len(.byName)),
lazyCerts: make([]lazyCert, len(.lazyCerts)),
haveSum: make(map[sum224]bool, len(.haveSum)),
}
for , := range .byName {
:= make([]int, len())
copy(, )
.byName[] =
}
for := range .haveSum {
.haveSum[] = true
}
copy(.lazyCerts, .lazyCerts)
return
}
return nil, errors.New("crypto/x509: system root pool is not available on Windows")
}
if := systemRootsPool(); != nil {
return .copy(), nil
}
return loadSystemRoots()
}
func ( *CertPool) ( *Certificate) []*Certificate {
if == nil {
return nil
}
var , , []*Certificate
for , := range .byName[string(.RawIssuer)] {
, := .cert()
if != nil {
continue
}
:= bytes.Equal(.SubjectKeyId, .AuthorityKeyId)
switch {
case :
= append(, )
case (len(.SubjectKeyId) == 0 && len(.AuthorityKeyId) > 0) ||
(len(.SubjectKeyId) > 0 && len(.AuthorityKeyId) == 0):
= append(, )
default:
= append(, )
}
}
:= len() + len() + len()
if == 0 {
return nil
}
:= make([]*Certificate, 0, )
= append(, ...)
= append(, ...)
= append(, ...)
return
}
func ( *CertPool) ( *Certificate) bool {
if == nil {
return false
}
return .haveSum[sha256.Sum224(.Raw)]
}
func ( *CertPool) ( *Certificate) {
if == nil {
panic("adding nil Certificate to CertPool")
}
.addCertFunc(sha256.Sum224(.Raw), string(.RawSubject), func() (*Certificate, error) {
return , nil
})
}
func ( *CertPool) ( []byte) ( bool) {
for len() > 0 {
var *pem.Block
, = pem.Decode()
if == nil {
break
}
if .Type != "CERTIFICATE" || len(.Headers) != 0 {
continue
}
:= .Bytes
, := ParseCertificate()
if != nil {
continue
}
var struct {
sync.Once
*Certificate
}
.addCertFunc(sha256.Sum224(.Raw), string(.RawSubject), func() (*Certificate, error) {
., _ = ParseCertificate()
= nil
})
return ., nil
})
= true
}
return
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |