OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ssl/openssl_client_key_store.h" | 5 #include "net/ssl/openssl_client_key_store.h" |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 #include <openssl/x509.h> | 8 #include <openssl/x509.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 } | 43 } |
44 | 44 |
45 OpenSSLClientKeyStore::KeyPair::~KeyPair() { | 45 OpenSSLClientKeyStore::KeyPair::~KeyPair() { |
46 } | 46 } |
47 | 47 |
48 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) | 48 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) |
49 : public_key(EVP_PKEY_dup(other.public_key.get())), | 49 : public_key(EVP_PKEY_dup(other.public_key.get())), |
50 private_key(EVP_PKEY_dup(other.private_key.get())) { | 50 private_key(EVP_PKEY_dup(other.private_key.get())) { |
51 } | 51 } |
52 | 52 |
53 void OpenSSLClientKeyStore::KeyPair::operator=(const KeyPair& other) { | 53 void OpenSSLClientKeyStore::KeyPair::operator=(const KeyPair& other) { |
Jeffrey Yasskin
2014/09/29 17:23:19
operator= should generally be implemented with a b
Ryan Sleevi
2014/09/29 18:57:08
Except this isn't a swap. It's a copy.
Jeffrey Yasskin
2014/09/29 19:20:52
Yeah, the copy happens because the argument is pas
| |
54 // Use a temporary ScopedEVP_PKEY because scoped_ptr does not allow resetting | 54 public_key.reset(EVP_PKEY_dup(other.public_key.get())); |
55 // to the current value, even though it's safe here. | 55 private_key.reset(EVP_PKEY_dup(other.private_key.get())); |
56 crypto::ScopedEVP_PKEY public_key_tmp(EVP_PKEY_dup(other.public_key.get())); | |
57 crypto::ScopedEVP_PKEY private_key_tmp(EVP_PKEY_dup(other.private_key.get())); | |
58 public_key.reset(); | |
59 public_key = public_key_tmp.Pass(); | |
60 private_key.reset(); | |
61 private_key = private_key_tmp.Pass(); | |
62 } | 56 } |
63 | 57 |
64 int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) { | 58 int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) { |
65 if (!public_key) | 59 if (!public_key) |
66 return -1; | 60 return -1; |
67 for (size_t n = 0; n < pairs_.size(); ++n) { | 61 for (size_t n = 0; n < pairs_.size(); ++n) { |
68 if (EVP_PKEY_cmp(pairs_[n].public_key.get(), public_key) == 1) | 62 if (EVP_PKEY_cmp(pairs_[n].public_key.get(), public_key) == 1) |
69 return static_cast<int>(n); | 63 return static_cast<int>(n); |
70 } | 64 } |
71 return -1; | 65 return -1; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 pairs_.clear(); | 110 pairs_.clear(); |
117 } | 111 } |
118 | 112 |
119 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { | 113 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { |
120 return Singleton<OpenSSLClientKeyStore>::get(); | 114 return Singleton<OpenSSLClientKeyStore>::get(); |
121 } | 115 } |
122 | 116 |
123 } // namespace net | 117 } // namespace net |
124 | 118 |
125 | 119 |
OLD | NEW |