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

Side by Side Diff: crypto/rsa_private_key_openssl.cc

Issue 559623002: Allow a crypto::RSAPrivateKey object to be wrapped round a pre-existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ouch, try again for the neither NSS nor openssl case Created 6 years, 3 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/rsa_private_key_nss_unittest.cc ('k') | crypto/rsa_private_key_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/bio.h> 7 #include <openssl/bio.h>
8 #include <openssl/bn.h> 8 #include <openssl/bn.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <openssl/pkcs12.h> 10 #include <openssl/pkcs12.h>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return NULL; 91 return NULL;
92 92
93 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); 93 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
94 result->key_ = EVP_PKCS82PKEY(p8inf.get()); 94 result->key_ = EVP_PKCS82PKEY(p8inf.get());
95 if (!result->key_) 95 if (!result->key_)
96 return NULL; 96 return NULL;
97 97
98 return result.release(); 98 return result.release();
99 } 99 }
100 100
101 // static
102 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) {
103 DCHECK(key);
104 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA)
105 return NULL;
106 RSAPrivateKey* copy = new RSAPrivateKey();
107 copy->key_ = EVP_PKEY_dup(key);
108 return copy;
109 }
110
101 RSAPrivateKey::RSAPrivateKey() 111 RSAPrivateKey::RSAPrivateKey()
102 : key_(NULL) { 112 : key_(NULL) {
103 } 113 }
104 114
105 RSAPrivateKey::~RSAPrivateKey() { 115 RSAPrivateKey::~RSAPrivateKey() {
106 if (key_) 116 if (key_)
107 EVP_PKEY_free(key_); 117 EVP_PKEY_free(key_);
108 } 118 }
109 119
110 RSAPrivateKey* RSAPrivateKey::Copy() const { 120 RSAPrivateKey* RSAPrivateKey::Copy() const {
111 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); 121 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey());
112 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_)); 122 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_));
113 if (!rsa) 123 if (!rsa)
114 return NULL; 124 return NULL;
115 copy->key_ = EVP_PKEY_new(); 125 copy->key_ = EVP_PKEY_new();
116 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get())) 126 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get()))
117 return NULL; 127 return NULL;
118 return copy.release(); 128 return copy.release();
119 } 129 }
120 130
121 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { 131 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
122 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); 132 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output);
123 } 133 }
124 134
125 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { 135 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
126 return ExportKey(key_, i2d_PUBKEY_bio, output); 136 return ExportKey(key_, i2d_PUBKEY_bio, output);
127 } 137 }
128 138
129 } // namespace crypto 139 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_nss_unittest.cc ('k') | crypto/rsa_private_key_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698