@@ -143,12 +143,9 @@ func (s *CertPool) AddCert(cert *Certificate) {
143
143
if cert == nil {
144
144
panic ("adding nil Certificate to CertPool" )
145
145
}
146
- err := s .addCertFunc (sha256 .Sum224 (cert .Raw ), string (cert .RawSubject ), string (cert .SubjectKeyId ), func () (* Certificate , error ) {
146
+ s .addCertFunc (sha256 .Sum224 (cert .Raw ), string (cert .RawSubject ), string (cert .SubjectKeyId ), func () (* Certificate , error ) {
147
147
return cert , nil
148
148
})
149
- if err != nil {
150
- panic (err .Error ())
151
- }
152
149
}
153
150
154
151
// addCertFunc adds metadata about a certificate to a pool, along with
@@ -157,25 +154,31 @@ func (s *CertPool) AddCert(cert *Certificate) {
157
154
// The rawSubject is Certificate.RawSubject and must be non-empty.
158
155
// The subjectKeyID is Certificate.SubjectKeyId and may be empty.
159
156
// The getCert func may be called 0 or more times.
160
- func (s * CertPool ) addCertFunc (rawSum224 sum224 , rawSubject , subjectKeyID string , getCert func () (* Certificate , error )) error {
157
+ func (s * CertPool ) addCertFunc (rawSum224 sum224 , rawSubject , subjectKeyID string , getCert func () (* Certificate , error )) {
161
158
if getCert == nil {
162
159
panic ("getCert can't be nil" )
163
160
}
164
161
165
162
// Check that the certificate isn't being added twice.
166
163
if s .haveSum [rawSum224 ] {
167
- return nil
164
+ return
168
165
}
169
- n := len (s .getCert )
170
166
s .haveSum [rawSum224 ] = true
167
+ s .addCertFuncNotDup (rawSubject , subjectKeyID , getCert )
168
+ }
169
+
170
+ func (s * CertPool ) addCertFuncNotDup (rawSubject , subjectKeyID string , getCert func () (* Certificate , error )) {
171
+ if getCert == nil {
172
+ panic ("getCert can't be nil" )
173
+ }
174
+ n := len (s .getCert )
171
175
s .getCert = append (s .getCert , getCert )
172
176
173
177
if subjectKeyID != "" {
174
178
s .bySubjectKeyId [subjectKeyID ] = append (s .bySubjectKeyId [subjectKeyID ], n )
175
179
}
176
180
s .byName [rawSubject ] = append (s .byName [rawSubject ], n )
177
181
s .rawSubjects = append (s .rawSubjects , []byte (rawSubject ))
178
- return nil
179
182
}
180
183
181
184
// AppendCertsFromPEM attempts to parse a series of PEM encoded certificates.
0 commit comments