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

Side by Side Diff: crypto/rsa_private_key.cc

Issue 2113143004: Switch to OpenSSL's |EVP_PKEY_up_ref| signature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « crypto/ec_private_key.cc ('k') | net/socket/ssl_server_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "crypto/rsa_private_key.h" 5 #include "crypto/rsa_private_key.h"
6 6
7 #include <openssl/bn.h> 7 #include <openssl/bn.h>
8 #include <openssl/bytestring.h> 8 #include <openssl/bytestring.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <openssl/mem.h> 10 #include <openssl/mem.h>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 result->key_ = pkey.release(); 55 result->key_ = pkey.release();
56 return result; 56 return result;
57 } 57 }
58 58
59 // static 59 // static
60 std::unique_ptr<RSAPrivateKey> RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { 60 std::unique_ptr<RSAPrivateKey> RSAPrivateKey::CreateFromKey(EVP_PKEY* key) {
61 DCHECK(key); 61 DCHECK(key);
62 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) 62 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
63 return nullptr; 63 return nullptr;
64 std::unique_ptr<RSAPrivateKey> copy(new RSAPrivateKey); 64 std::unique_ptr<RSAPrivateKey> copy(new RSAPrivateKey);
65 copy->key_ = EVP_PKEY_up_ref(key); 65 EVP_PKEY_up_ref(key);
66 copy->key_ = key;
66 return copy; 67 return copy;
67 } 68 }
68 69
69 RSAPrivateKey::RSAPrivateKey() : key_(nullptr) {} 70 RSAPrivateKey::RSAPrivateKey() : key_(nullptr) {}
70 71
71 RSAPrivateKey::~RSAPrivateKey() { 72 RSAPrivateKey::~RSAPrivateKey() {
72 if (key_) 73 if (key_)
73 EVP_PKEY_free(key_); 74 EVP_PKEY_free(key_);
74 } 75 }
75 76
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 !EVP_marshal_public_key(cbb.get(), key_) || 109 !EVP_marshal_public_key(cbb.get(), key_) ||
109 !CBB_finish(cbb.get(), &der, &der_len)) { 110 !CBB_finish(cbb.get(), &der, &der_len)) {
110 return false; 111 return false;
111 } 112 }
112 output->assign(der, der + der_len); 113 output->assign(der, der + der_len);
113 OPENSSL_free(der); 114 OPENSSL_free(der);
114 return true; 115 return true;
115 } 116 }
116 117
117 } // namespace crypto 118 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/ec_private_key.cc ('k') | net/socket/ssl_server_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698