Remove tlsconfigutil.CABundle.IsEqual and ensure that tlsconfigutil.NewCABundle handles nil/empty input

Co-authored-by: Ryan Richard <richardry@vmware.com>
This commit is contained in:
Joshua Casey
2024-08-05 11:32:20 -07:00
committed by Ryan Richard
co-authored by Ryan Richard
parent fcceeed9fa
commit 99cfc4fbce
3 changed files with 67 additions and 81 deletions
@@ -16,12 +16,19 @@ type CABundle struct {
}
func NewCABundle(caBundle []byte) (*CABundle, bool) {
certPool := x509.NewCertPool()
var certPool *x509.CertPool
ok := true
if len(caBundle) > 0 {
certPool = x509.NewCertPool()
ok = certPool.AppendCertsFromPEM(caBundle)
}
return &CABundle{
caBundle: caBundle,
sha256: sha256.Sum256(caBundle),
certPool: certPool,
}, certPool.AppendCertsFromPEM(caBundle)
}, ok
}
// PEMBytes returns the CA certificate bundle PEM bytes.
@@ -59,8 +66,3 @@ func (c *CABundle) Hash() [32]byte {
}
return c.sha256 // note that this will always return the same hash for nil input
}
// IsEqual returns whether a CABundle has the same CA certificate bundle as another.
func (c *CABundle) IsEqual(other *CABundle) bool {
return c.Hash() == other.Hash()
}