OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ec_private_key.h" | 5 #include "crypto/ec_private_key.h" |
6 | 6 |
7 #include <openssl/ec.h> | 7 #include <openssl/ec.h> |
8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
9 #include <openssl/pkcs12.h> | 9 #include <openssl/pkcs12.h> |
10 #include <openssl/x509.h> | 10 #include <openssl/x509.h> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 ECPrivateKey::~ECPrivateKey() { | 83 ECPrivateKey::~ECPrivateKey() { |
84 if (key_) | 84 if (key_) |
85 EVP_PKEY_free(key_); | 85 EVP_PKEY_free(key_); |
86 } | 86 } |
87 | 87 |
88 ECPrivateKey* ECPrivateKey::Copy() const { | |
89 scoped_ptr<ECPrivateKey> copy(new ECPrivateKey); | |
90 if (key_) { | |
91 copy->key_ = EVP_PKEY_up_ref(key_); | |
92 if (!copy->key_) | |
93 return NULL; | |
davidben
2015/05/12 21:55:06
You can drop these two lines. EVP_PKEY_up_ref can'
nharper
2015/05/12 22:07:29
Done.
| |
94 } | |
95 return copy.release(); | |
96 } | |
97 | |
88 // static | 98 // static |
89 bool ECPrivateKey::IsSupported() { return true; } | 99 bool ECPrivateKey::IsSupported() { return true; } |
90 | 100 |
91 // static | 101 // static |
92 ECPrivateKey* ECPrivateKey::Create() { | 102 ECPrivateKey* ECPrivateKey::Create() { |
93 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 103 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
94 | 104 |
95 ScopedEC_KEY ec_key(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1)); | 105 ScopedEC_KEY ec_key(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1)); |
96 if (!ec_key.get() || !EC_KEY_generate_key(ec_key.get())) | 106 if (!ec_key.get() || !EC_KEY_generate_key(ec_key.get())) |
97 return NULL; | 107 return NULL; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 232 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
223 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); | 233 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); |
224 return ExportKey(ec_key.get(), | 234 return ExportKey(ec_key.get(), |
225 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), | 235 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), |
226 output); | 236 output); |
227 } | 237 } |
228 | 238 |
229 ECPrivateKey::ECPrivateKey() : key_(NULL) {} | 239 ECPrivateKey::ECPrivateKey() : key_(NULL) {} |
230 | 240 |
231 } // namespace crypto | 241 } // namespace crypto |
OLD | NEW |