Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: net/ssl/openssl_client_key_store.cc

Issue 610533003: Allow custom deleters to opt out of self reset checks for scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a header + guard Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <algorithm>
9 10
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
12 #include "net/cert/x509_certificate.h" 13 #include "net/cert/x509_certificate.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 namespace { 17 namespace {
17 18
18 // Return the EVP_PKEY holding the public key of a given certificate. 19 // Return the EVP_PKEY holding the public key of a given certificate.
(...skipping 24 matching lines...) Expand all
43 } 44 }
44 45
45 OpenSSLClientKeyStore::KeyPair::~KeyPair() { 46 OpenSSLClientKeyStore::KeyPair::~KeyPair() {
46 } 47 }
47 48
48 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) 49 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other)
49 : public_key(EVP_PKEY_dup(other.public_key.get())), 50 : public_key(EVP_PKEY_dup(other.public_key.get())),
50 private_key(EVP_PKEY_dup(other.private_key.get())) { 51 private_key(EVP_PKEY_dup(other.private_key.get())) {
51 } 52 }
52 53
53 void OpenSSLClientKeyStore::KeyPair::operator=(const KeyPair& other) { 54 void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) {
54 // Use a temporary ScopedEVP_PKEY because scoped_ptr does not allow resetting 55 this->swap(other);
55 // to the current value, even though it's safe here. 56 }
56 crypto::ScopedEVP_PKEY public_key_tmp(EVP_PKEY_dup(other.public_key.get())); 57
57 crypto::ScopedEVP_PKEY private_key_tmp(EVP_PKEY_dup(other.private_key.get())); 58 // 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
58 public_key.reset(); 59 void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) {
59 public_key = public_key_tmp.Pass(); 60 using std::swap;
60 private_key.reset(); 61 swap(public_key, other.public_key);
61 private_key = private_key_tmp.Pass(); 62 swap(private_key, other.private_key);
62 } 63 }
63 64
64 int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) { 65 int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) {
65 if (!public_key) 66 if (!public_key)
66 return -1; 67 return -1;
67 for (size_t n = 0; n < pairs_.size(); ++n) { 68 for (size_t n = 0; n < pairs_.size(); ++n) {
68 if (EVP_PKEY_cmp(pairs_[n].public_key.get(), public_key) == 1) 69 if (EVP_PKEY_cmp(pairs_[n].public_key.get(), public_key) == 1)
69 return static_cast<int>(n); 70 return static_cast<int>(n);
70 } 71 }
71 return -1; 72 return -1;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 pairs_.clear(); 117 pairs_.clear();
117 } 118 }
118 119
119 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { 120 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() {
120 return Singleton<OpenSSLClientKeyStore>::get(); 121 return Singleton<OpenSSLClientKeyStore>::get();
121 } 122 }
122 123
123 } // namespace net 124 } // namespace net
124 125
125 126
OLDNEW
« base/memory/scoped_ptr_unittest.cc ('K') | « net/ssl/openssl_client_key_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698