| 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/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 return result.release(); | 97 return result.release(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { | 101 RSAPrivateKey* RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { |
| 102 DCHECK(key); | 102 DCHECK(key); |
| 103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) | 103 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) |
| 104 return NULL; | 104 return NULL; |
| 105 RSAPrivateKey* copy = new RSAPrivateKey(); | 105 RSAPrivateKey* copy = new RSAPrivateKey(); |
| 106 copy->key_ = EVP_PKEY_dup(key); | 106 copy->key_ = EVP_PKEY_up_ref(key); |
| 107 return copy; | 107 return copy; |
| 108 } | 108 } |
| 109 | 109 |
| 110 RSAPrivateKey::RSAPrivateKey() | 110 RSAPrivateKey::RSAPrivateKey() |
| 111 : key_(NULL) { | 111 : key_(NULL) { |
| 112 } | 112 } |
| 113 | 113 |
| 114 RSAPrivateKey::~RSAPrivateKey() { | 114 RSAPrivateKey::~RSAPrivateKey() { |
| 115 if (key_) | 115 if (key_) |
| 116 EVP_PKEY_free(key_); | 116 EVP_PKEY_free(key_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 | 129 |
| 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { | 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { |
| 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); | 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { | 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { |
| 135 return ExportKey(key_, i2d_PUBKEY_bio, output); | 135 return ExportKey(key_, i2d_PUBKEY_bio, output); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace crypto | 138 } // namespace crypto |
| OLD | NEW |