]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509: use Certificate.Equals and CertPool.contains.
authorAdam Langley <agl@golang.org>
Wed, 26 Oct 2016 20:51:44 +0000 (13:51 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 26 Oct 2016 22:58:21 +0000 (22:58 +0000)
By using these utility functions, the code can be made a little shorter.
Thanks to Omar Shafie for pointing this out in
https://golang.org/cl/27393/.

Change-Id: I33fd97cf7d60a31d0844ec16c12bba530dcc6f6d
Reviewed-on: https://go-review.googlesource.com/32120
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/crypto/x509/cert_pool.go

index 8508cbacd773f2d072a6ba10f3a45595776af10d..fea33df379aebdce57f78c6cc6a412e61acea99d 100644 (file)
@@ -4,10 +4,7 @@
 
 package x509
 
-import (
-       "bytes"
-       "encoding/pem"
-)
+import "encoding/pem"
 
 // CertPool is a set of certificates.
 type CertPool struct {
@@ -67,7 +64,7 @@ func (s *CertPool) contains(cert *Certificate) bool {
 
        candidates := s.byName[string(cert.RawSubject)]
        for _, c := range candidates {
-               if bytes.Equal(cert.Raw, s.certs[c].Raw) {
+               if s.certs[c].Equal(cert) {
                        return true
                }
        }
@@ -82,10 +79,8 @@ func (s *CertPool) AddCert(cert *Certificate) {
        }
 
        // Check that the certificate isn't being added twice.
-       for _, c := range s.certs {
-               if c.Equal(cert) {
-                       return
-               }
+       if s.contains(cert) {
+               return
        }
 
        n := len(s.certs)