From 4ef5c7619ba9e40b97f2db1a7354dc66b52e4339 Mon Sep 17 00:00:00 2001 From: David Adrian Date: Mon, 15 May 2017 12:26:44 -0400 Subject: [PATCH] Add Sum() and Size() to CertPool (#53) 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. --- x509/cert_pool.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/x509/cert_pool.go b/x509/cert_pool.go index 0a553d5c..18159984 100644 --- a/x509/cert_pool.go +++ b/x509/cert_pool.go @@ -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 +}