Skip to content

Commit

Permalink
Add Sum() and Size() to CertPool (#53)
Browse files Browse the repository at this point in the history
Sum() returns a new CertPool that is the union of two pools. Size()
returns the number of certificates in a pool. Both are used by the
verifier.
  • Loading branch information
dadrian authored May 15, 2017
1 parent 18e6fdb commit 4ef5c76
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions x509/cert_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,26 @@ func (s *CertPool) Certificates() []*Certificate {
out = append(out, s.certs...)
return out
}

// Size returns the number of unique certificates in the CertPool.
func (s *CertPool) Size() int {
if s == nil {
return 0
}
return len(s.certs)
}

// Sum returns the union of two certificate pools as a new certificate pool.
func (s *CertPool) Sum(other *CertPool) (sum *CertPool) {
sum = NewCertPool()
for _, c := range s.certs {
sum.AddCert(c)
}
if other == nil {
return
}
for _, c := range other.certs {
sum.AddCert(c)
}
return
}

0 comments on commit 4ef5c76

Please sign in to comment.