Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: net/base/x509_certificate.cc

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/upload_data_stream.cc ('k') | net/disk_cache/backend_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 bool X509Certificate::LessThan::operator()(X509Certificate* lhs, 115 bool X509Certificate::LessThan::operator()(X509Certificate* lhs,
116 X509Certificate* rhs) const { 116 X509Certificate* rhs) const {
117 if (lhs == rhs) 117 if (lhs == rhs)
118 return false; 118 return false;
119 119
120 SHA1FingerprintLessThan fingerprint_functor; 120 SHA1FingerprintLessThan fingerprint_functor;
121 return fingerprint_functor(lhs->fingerprint_, rhs->fingerprint_); 121 return fingerprint_functor(lhs->fingerprint_, rhs->fingerprint_);
122 } 122 }
123 123
124 X509Certificate::X509Certificate(const std::string& subject,
125 const std::string& issuer,
126 base::Time start_date,
127 base::Time expiration_date)
128 : subject_(subject),
129 issuer_(issuer),
130 valid_start_(start_date),
131 valid_expiry_(expiration_date),
132 cert_handle_(NULL),
133 source_(SOURCE_UNUSED) {
134 memset(fingerprint_.data, 0, sizeof(fingerprint_.data));
135 }
136
124 // static 137 // static
125 X509Certificate* X509Certificate::CreateFromHandle( 138 X509Certificate* X509Certificate::CreateFromHandle(
126 OSCertHandle cert_handle, 139 OSCertHandle cert_handle,
127 Source source, 140 Source source,
128 const OSCertHandles& intermediates) { 141 const OSCertHandles& intermediates) {
129 DCHECK(cert_handle); 142 DCHECK(cert_handle);
130 DCHECK(source != SOURCE_UNUSED); 143 DCHECK(source != SOURCE_UNUSED);
131 144
132 // Check if we already have this certificate in memory. 145 // Check if we already have this certificate in memory.
133 X509CertificateCache* cache = g_x509_certificate_cache.Pointer(); 146 X509CertificateCache* cache = g_x509_certificate_cache.Pointer();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 it != certificates.end(); ++it) { 289 it != certificates.end(); ++it) {
277 X509Certificate* result = CreateFromHandle(*it, SOURCE_LONE_CERT_IMPORT, 290 X509Certificate* result = CreateFromHandle(*it, SOURCE_LONE_CERT_IMPORT,
278 OSCertHandles()); 291 OSCertHandles());
279 results.push_back(scoped_refptr<X509Certificate>(result)); 292 results.push_back(scoped_refptr<X509Certificate>(result));
280 FreeOSCertHandle(*it); 293 FreeOSCertHandle(*it);
281 } 294 }
282 295
283 return results; 296 return results;
284 } 297 }
285 298
286 X509Certificate::X509Certificate(OSCertHandle cert_handle,
287 Source source,
288 const OSCertHandles& intermediates)
289 : cert_handle_(DupOSCertHandle(cert_handle)),
290 source_(source) {
291 // Copy/retain the intermediate cert handles.
292 for (size_t i = 0; i < intermediates.size(); ++i)
293 intermediate_ca_certs_.push_back(DupOSCertHandle(intermediates[i]));
294 // Platform-specific initialization.
295 Initialize();
296 }
297
298 X509Certificate::X509Certificate(const std::string& subject,
299 const std::string& issuer,
300 base::Time start_date,
301 base::Time expiration_date)
302 : subject_(subject),
303 issuer_(issuer),
304 valid_start_(start_date),
305 valid_expiry_(expiration_date),
306 cert_handle_(NULL),
307 source_(SOURCE_UNUSED) {
308 memset(fingerprint_.data, 0, sizeof(fingerprint_.data));
309 }
310
311 X509Certificate::~X509Certificate() {
312 // We might not be in the cache, but it is safe to remove ourselves anyway.
313 g_x509_certificate_cache.Get().Remove(this);
314 if (cert_handle_)
315 FreeOSCertHandle(cert_handle_);
316 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i)
317 FreeOSCertHandle(intermediate_ca_certs_[i]);
318 }
319
320 bool X509Certificate::HasExpired() const { 299 bool X509Certificate::HasExpired() const {
321 return base::Time::Now() > valid_expiry(); 300 return base::Time::Now() > valid_expiry();
322 } 301 }
323 302
324 bool X509Certificate::Equals(const X509Certificate* other) const { 303 bool X509Certificate::Equals(const X509Certificate* other) const {
325 return IsSameOSCert(cert_handle_, other->cert_handle_); 304 return IsSameOSCert(cert_handle_, other->cert_handle_);
326 } 305 }
327 306
328 bool X509Certificate::HasIntermediateCertificate(OSCertHandle cert) { 307 bool X509Certificate::HasIntermediateCertificate(OSCertHandle cert) {
329 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_OPENSSL) 308 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_OPENSSL)
330 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) { 309 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i) {
331 if (IsSameOSCert(cert, intermediate_ca_certs_[i])) 310 if (IsSameOSCert(cert, intermediate_ca_certs_[i]))
332 return true; 311 return true;
333 } 312 }
334 return false; 313 return false;
335 #else 314 #else
336 return true; 315 return true;
337 #endif 316 #endif
338 } 317 }
339 318
340 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) { 319 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) {
341 for (size_t i = 0; i < certs.size(); ++i) { 320 for (size_t i = 0; i < certs.size(); ++i) {
342 if (!HasIntermediateCertificate(certs[i])) 321 if (!HasIntermediateCertificate(certs[i]))
343 return false; 322 return false;
344 } 323 }
345 return true; 324 return true;
346 } 325 }
347 326
327 X509Certificate::X509Certificate(OSCertHandle cert_handle,
328 Source source,
329 const OSCertHandles& intermediates)
330 : cert_handle_(DupOSCertHandle(cert_handle)),
331 source_(source) {
332 // Copy/retain the intermediate cert handles.
333 for (size_t i = 0; i < intermediates.size(); ++i)
334 intermediate_ca_certs_.push_back(DupOSCertHandle(intermediates[i]));
335 // Platform-specific initialization.
336 Initialize();
337 }
338
339 X509Certificate::~X509Certificate() {
340 // We might not be in the cache, but it is safe to remove ourselves anyway.
341 g_x509_certificate_cache.Get().Remove(this);
342 if (cert_handle_)
343 FreeOSCertHandle(cert_handle_);
344 for (size_t i = 0; i < intermediate_ca_certs_.size(); ++i)
345 FreeOSCertHandle(intermediate_ca_certs_[i]);
346 }
347
348 } // namespace net 348 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_data_stream.cc ('k') | net/disk_cache/backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698