OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 // Defines an in-memory private key store, primarily used for testing. | 5 // Defines an in-memory private key store, primarily used for testing. |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 | 8 |
9 #include "net/base/openssl_private_key_store.h" | 9 #include "net/base/openssl_private_key_store.h" |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/openssl_util.h" | 12 #include "base/openssl_util.h" |
13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
14 #include "net/base/x509_certificate.h" | 14 #include "net/base/x509_certificate.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class OpenSSLMemoryKeyStore : public OpenSSLPrivateKeyStore { | 20 class OpenSSLMemoryKeyStore : public OpenSSLPrivateKeyStore { |
21 public: | 21 public: |
22 OpenSSLMemoryKeyStore() {} | 22 OpenSSLMemoryKeyStore() {} |
23 | 23 |
| 24 static OpenSSLMemoryKeyStore* GetInstance() { |
| 25 return Singleton<OpenSSLMemoryKeyStore>::get(); |
| 26 } |
| 27 |
24 virtual ~OpenSSLMemoryKeyStore() { | 28 virtual ~OpenSSLMemoryKeyStore() { |
25 AutoLock lock(lock_); | 29 AutoLock lock(lock_); |
26 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); | 30 for (std::vector<EVP_PKEY*>::iterator it = keys_.begin(); |
27 it != keys_.end(); ++it) { | 31 it != keys_.end(); ++it) { |
28 EVP_PKEY_free(*it); | 32 EVP_PKEY_free(*it); |
29 } | 33 } |
30 } | 34 } |
31 | 35 |
32 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { | 36 virtual bool StorePrivateKey(const GURL& url, EVP_PKEY* pkey) { |
33 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); | 37 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
(...skipping 16 matching lines...) Expand all Loading... |
50 std::vector<EVP_PKEY*> keys_; | 54 std::vector<EVP_PKEY*> keys_; |
51 Lock lock_; | 55 Lock lock_; |
52 | 56 |
53 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore); | 57 DISALLOW_COPY_AND_ASSIGN(OpenSSLMemoryKeyStore); |
54 }; | 58 }; |
55 | 59 |
56 } // namespace | 60 } // namespace |
57 | 61 |
58 // static | 62 // static |
59 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { | 63 OpenSSLPrivateKeyStore* OpenSSLPrivateKeyStore::GetInstance() { |
60 return Singleton<OpenSSLMemoryKeyStore>::get(); | 64 return OpenSSLMemoryKeyStore::GetInstance(); |
61 } | 65 } |
62 | 66 |
63 } // namespace net | 67 } // namespace net |
64 | 68 |
OLD | NEW |