OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/cert_store_impl.h" | 5 #include "content/browser/cert_store_impl.h" |
6 | 6 |
7 namespace content { | 7 namespace content { |
8 | 8 |
9 // static | 9 // static |
10 CertStore* CertStore::GetInstance() { | 10 CertStore* CertStore::GetInstance() { |
11 return CertStoreImpl::GetInstance(); | 11 return CertStoreImpl::GetInstance(); |
12 } | 12 } |
13 | 13 |
14 // static | 14 // static |
15 CertStoreImpl* CertStoreImpl::GetInstance() { | 15 CertStoreImpl* CertStoreImpl::GetInstance() { |
16 return base::Singleton<CertStoreImpl>::get(); | 16 return base::Singleton<CertStoreImpl>::get(); |
17 } | 17 } |
18 | 18 |
| 19 int CertStoreImpl::StoreCert(net::X509Certificate* cert, int process_id) { |
| 20 scoped_refptr<HashAndCert> hash_and_cert(new HashAndCert); |
| 21 hash_and_cert->chain_hash = |
| 22 net::X509Certificate::CalculateChainFingerprint256( |
| 23 cert->os_cert_handle(), cert->GetIntermediateCertificates()); |
| 24 hash_and_cert->cert = cert; |
| 25 return store_.Store(hash_and_cert.get(), process_id); |
| 26 } |
| 27 |
| 28 bool CertStoreImpl::RetrieveCert(int cert_id, |
| 29 scoped_refptr<net::X509Certificate>* cert) { |
| 30 scoped_refptr<HashAndCert> hash_and_cert; |
| 31 if (store_.Retrieve(cert_id, &hash_and_cert)) { |
| 32 *cert = hash_and_cert->cert; |
| 33 return true; |
| 34 } |
| 35 return false; |
| 36 } |
| 37 |
19 CertStoreImpl::CertStoreImpl() {} | 38 CertStoreImpl::CertStoreImpl() {} |
20 | 39 |
21 CertStoreImpl::~CertStoreImpl() {} | 40 CertStoreImpl::~CertStoreImpl() {} |
22 | 41 |
23 int CertStoreImpl::StoreCert(net::X509Certificate* cert, int process_id) { | 42 CertStoreImpl::HashAndCert::HashAndCert() = default; |
24 return store_.Store(cert, process_id); | 43 |
| 44 bool CertStoreImpl::HashAndCert::LessThan::operator()( |
| 45 const scoped_refptr<HashAndCert>& lhs, |
| 46 const scoped_refptr<HashAndCert>& rhs) const { |
| 47 return net::SHA256HashValueLessThan()(lhs->chain_hash, rhs->chain_hash); |
25 } | 48 } |
26 | 49 |
27 bool CertStoreImpl::RetrieveCert(int cert_id, | 50 CertStoreImpl::HashAndCert::~HashAndCert() = default; |
28 scoped_refptr<net::X509Certificate>* cert) { | |
29 return store_.Retrieve(cert_id, cert); | |
30 } | |
31 | 51 |
32 } // namespace content | 52 } // namespace content |
OLD | NEW |