From 78960959e8d38e5a0ecc53f0b3b4f26692c1e069 Mon Sep 17 00:00:00 2001 From: David Adrian Date: Mon, 15 May 2017 11:48:51 -0400 Subject: [PATCH] Add Sum() and Size() to CertPool 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 +}