Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/temporary_root_certs.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "net/base/x509_certificate.h" | |
| 9 | |
| 10 namespace net { | |
| 11 | |
| 12 bool TemporaryRootCerts::Add(X509Certificate* certificate) { | |
| 13 BOOL ok = CertAddCertificateContextToStore( | |
| 14 temporary_roots_, certificate->os_cert_handle(), | |
| 15 CERT_STORE_ADD_NEW, NULL); | |
| 16 if (!ok) { | |
| 17 if (GetLastError() == CRYPT_E_EXISTS) | |
|
wtc
2010/11/16 23:24:01
Nit: you can just say
if (!ok) {
// If certi
| |
| 18 return true; // Certificate is already added. | |
| 19 return false; | |
| 20 } | |
| 21 | |
| 22 ++cert_count_; | |
| 23 return true; | |
| 24 } | |
| 25 | |
| 26 void TemporaryRootCerts::Remove(X509Certificate* certificate) { | |
| 27 PCCERT_CONTEXT cert = CertFindCertificateInStore( | |
| 28 temporary_roots_, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, | |
| 29 0, CERT_FIND_EXISTING, certificate->os_cert_handle(), NULL); | |
| 30 if (cert) { | |
| 31 CertDeleteCertificateFromStore(cert); | |
| 32 DCHECK_GT(cert_count_, 0U); | |
| 33 --cert_count_; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 TemporaryRootCerts::TemporaryRootCerts() | |
| 38 : temporary_roots_(NULL), cert_count_(0) { | |
|
bulach
2010/11/09 16:21:09
nit: I think it's either all in one line (includin
| |
| 39 temporary_roots_ = CertOpenStore( | |
| 40 CERT_STORE_PROV_MEMORY, 0, NULL, | |
| 41 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); | |
| 42 DCHECK(temporary_roots_); | |
| 43 } | |
| 44 | |
| 45 TemporaryRootCerts::~TemporaryRootCerts() { | |
| 46 CertCloseStore(temporary_roots_, 0); | |
| 47 } | |
| 48 | |
| 49 } // namespace net | |
| OLD | NEW |