Chromium Code Reviews| Index: net/base/temporary_root_certs_win.cc |
| diff --git a/net/base/temporary_root_certs_win.cc b/net/base/temporary_root_certs_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..06d91ffb5eb467e1d8630472a386eae95e26f898 |
| --- /dev/null |
| +++ b/net/base/temporary_root_certs_win.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/base/temporary_root_certs.h" |
| + |
| +#include "base/logging.h" |
| +#include "net/base/x509_certificate.h" |
| + |
| +namespace net { |
| + |
| +bool TemporaryRootCerts::Add(X509Certificate* certificate) { |
| + BOOL ok = CertAddCertificateContextToStore( |
| + temporary_roots_, certificate->os_cert_handle(), |
| + CERT_STORE_ADD_NEW, NULL); |
| + if (!ok) { |
| + if (GetLastError() == CRYPT_E_EXISTS) |
|
wtc
2010/11/16 23:24:01
Nit: you can just say
if (!ok) {
// If certi
|
| + return true; // Certificate is already added. |
| + return false; |
| + } |
| + |
| + ++cert_count_; |
| + return true; |
| +} |
| + |
| +void TemporaryRootCerts::Remove(X509Certificate* certificate) { |
| + PCCERT_CONTEXT cert = CertFindCertificateInStore( |
| + temporary_roots_, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, |
| + 0, CERT_FIND_EXISTING, certificate->os_cert_handle(), NULL); |
| + if (cert) { |
| + CertDeleteCertificateFromStore(cert); |
| + DCHECK_GT(cert_count_, 0U); |
| + --cert_count_; |
| + } |
| +} |
| + |
| +TemporaryRootCerts::TemporaryRootCerts() |
| + : temporary_roots_(NULL), cert_count_(0) { |
|
bulach
2010/11/09 16:21:09
nit: I think it's either all in one line (includin
|
| + temporary_roots_ = CertOpenStore( |
| + CERT_STORE_PROV_MEMORY, 0, NULL, |
| + CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL); |
| + DCHECK(temporary_roots_); |
| +} |
| + |
| +TemporaryRootCerts::~TemporaryRootCerts() { |
| + CertCloseStore(temporary_roots_, 0); |
| +} |
| + |
| +} // namespace net |