Skip to content

Commit

Permalink
crypto/x509: use Certificate.Equals and CertPool.contains.
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
agl authored and bradfitz committed Oct 26, 2016
1 parent f697cf2 commit 4f1e7be
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/crypto/x509/cert_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package x509

import (
"bytes"
"encoding/pem"
)
import "encoding/pem"

// CertPool is a set of certificates.
type CertPool struct {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 4f1e7be

Please sign in to comment.