Chromium Code Reviews| Index: net/ssl/openssl_client_key_store.cc |
| diff --git a/net/ssl/openssl_client_key_store.cc b/net/ssl/openssl_client_key_store.cc |
| index b0b5eb3d4753d14a8ae186ba4fabfae1b927d243..ae2da60491fecd282fa0bce1b42bc75212e195fe 100644 |
| --- a/net/ssl/openssl_client_key_store.cc |
| +++ b/net/ssl/openssl_client_key_store.cc |
| @@ -6,6 +6,7 @@ |
| #include <openssl/evp.h> |
| #include <openssl/x509.h> |
| +#include <algorithm> |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/singleton.h" |
| @@ -50,15 +51,15 @@ OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) |
| private_key(EVP_PKEY_dup(other.private_key.get())) { |
| } |
| -void OpenSSLClientKeyStore::KeyPair::operator=(const KeyPair& other) { |
| - // Use a temporary ScopedEVP_PKEY because scoped_ptr does not allow resetting |
| - // to the current value, even though it's safe here. |
| - crypto::ScopedEVP_PKEY public_key_tmp(EVP_PKEY_dup(other.public_key.get())); |
| - crypto::ScopedEVP_PKEY private_key_tmp(EVP_PKEY_dup(other.private_key.get())); |
| - public_key.reset(); |
| - public_key = public_key_tmp.Pass(); |
| - private_key.reset(); |
| - private_key = private_key_tmp.Pass(); |
| +void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) { |
| + this->swap(other); |
| +} |
| + |
| +// Intentionally pass by value, in order to use the copy-and-swap idiom. |
|
pneubeck (no reviews)
2014/10/07 09:30:09
should this comment better be at the operator= fun
dcheng
2014/10/07 22:40:37
I'm ambivalent on this. I felt like it was better
|
| +void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) { |
| + using std::swap; |
| + swap(public_key, other.public_key); |
| + swap(private_key, other.private_key); |
| } |
| int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) { |