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/bn.h> | 7 #include <openssl/bn.h> |
8 #include <openssl/bytestring.h> | 8 #include <openssl/bytestring.h> |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 #include <openssl/mem.h> | 10 #include <openssl/mem.h> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 result->key_ = pkey.release(); | 55 result->key_ = pkey.release(); |
56 return result; | 56 return result; |
57 } | 57 } |
58 | 58 |
59 // static | 59 // static |
60 std::unique_ptr<RSAPrivateKey> RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { | 60 std::unique_ptr<RSAPrivateKey> RSAPrivateKey::CreateFromKey(EVP_PKEY* key) { |
61 DCHECK(key); | 61 DCHECK(key); |
62 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) | 62 if (EVP_PKEY_type(key->type) != EVP_PKEY_RSA) |
63 return nullptr; | 63 return nullptr; |
64 std::unique_ptr<RSAPrivateKey> copy(new RSAPrivateKey); | 64 std::unique_ptr<RSAPrivateKey> copy(new RSAPrivateKey); |
65 copy->key_ = EVP_PKEY_up_ref(key); | 65 EVP_PKEY_up_ref(key); |
| 66 copy->key_ = key; |
66 return copy; | 67 return copy; |
67 } | 68 } |
68 | 69 |
69 RSAPrivateKey::RSAPrivateKey() : key_(nullptr) {} | 70 RSAPrivateKey::RSAPrivateKey() : key_(nullptr) {} |
70 | 71 |
71 RSAPrivateKey::~RSAPrivateKey() { | 72 RSAPrivateKey::~RSAPrivateKey() { |
72 if (key_) | 73 if (key_) |
73 EVP_PKEY_free(key_); | 74 EVP_PKEY_free(key_); |
74 } | 75 } |
75 | 76 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 !EVP_marshal_public_key(cbb.get(), key_) || | 109 !EVP_marshal_public_key(cbb.get(), key_) || |
109 !CBB_finish(cbb.get(), &der, &der_len)) { | 110 !CBB_finish(cbb.get(), &der, &der_len)) { |
110 return false; | 111 return false; |
111 } | 112 } |
112 output->assign(der, der + der_len); | 113 output->assign(der, der + der_len); |
113 OPENSSL_free(der); | 114 OPENSSL_free(der); |
114 return true; | 115 return true; |
115 } | 116 } |
116 | 117 |
117 } // namespace crypto | 118 } // namespace crypto |
OLD | NEW |