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

Side by Side Diff: crypto/rsa_private_key_openssl.cc

Issue 8727014: Implement RSAPrivateKey::Copy() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years 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 | Annotate | Revision Log
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/evp.h> 7 #include <openssl/evp.h>
8 #include <openssl/pkcs12.h> 8 #include <openssl/pkcs12.h>
9 #include <openssl/rsa.h> 9 #include <openssl/rsa.h>
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 RSAPrivateKey::RSAPrivateKey() 118 RSAPrivateKey::RSAPrivateKey()
119 : key_(NULL) { 119 : key_(NULL) {
120 } 120 }
121 121
122 RSAPrivateKey::~RSAPrivateKey() { 122 RSAPrivateKey::~RSAPrivateKey() {
123 if (key_) 123 if (key_)
124 EVP_PKEY_free(key_); 124 EVP_PKEY_free(key_);
125 } 125 }
126 126
127 RSAPrivateKey* RSAPrivateKey::Copy() const {
128 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey());
129 RSA* rsa = EVP_PKEY_get1_RSA(key_);
130 if (!rsa)
131 return NULL;
132 copy->key_ = EVP_PKEY_new();
133 if (!EVP_PKEY_set1_RSA(copy->key_, rsa))
134 return NULL;
135 return copy.release();
136 }
137
127 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { 138 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) {
128 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); 139 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output);
129 } 140 }
130 141
131 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { 142 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) {
132 return ExportKey(key_, i2d_PUBKEY_bio, output); 143 return ExportKey(key_, i2d_PUBKEY_bio, output);
133 } 144 }
134 145
135 } // namespace crypto 146 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698