| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 : key_(NULL) { | 100 : key_(NULL) { |
| 101 } | 101 } |
| 102 | 102 |
| 103 RSAPrivateKey::~RSAPrivateKey() { | 103 RSAPrivateKey::~RSAPrivateKey() { |
| 104 if (key_) | 104 if (key_) |
| 105 EVP_PKEY_free(key_); | 105 EVP_PKEY_free(key_); |
| 106 } | 106 } |
| 107 | 107 |
| 108 RSAPrivateKey* RSAPrivateKey::Copy() const { | 108 RSAPrivateKey* RSAPrivateKey::Copy() const { |
| 109 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); | 109 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); |
| 110 RSA* rsa = EVP_PKEY_get1_RSA(key_); | 110 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_)); |
| 111 if (!rsa) | 111 if (!rsa) |
| 112 return NULL; | 112 return NULL; |
| 113 copy->key_ = EVP_PKEY_new(); | 113 copy->key_ = EVP_PKEY_new(); |
| 114 if (!EVP_PKEY_set1_RSA(copy->key_, rsa)) | 114 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get())) |
| 115 return NULL; | 115 return NULL; |
| 116 return copy.release(); | 116 return copy.release(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { | 119 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { |
| 120 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); | 120 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { | 123 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { |
| 124 return ExportKey(key_, i2d_PUBKEY_bio, output); | 124 return ExportKey(key_, i2d_PUBKEY_bio, output); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace crypto | 127 } // namespace crypto |
| OLD | NEW |