| OLD | NEW |
| 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 Loading... |
| 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 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { | 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 |
| 138 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { |
| 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) const { |
| 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 |
| OLD | NEW |