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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "crypto/openssl_util.h" | 14 #include "crypto/openssl_util.h" |
15 #include "crypto/scoped_openssl_types.h" | 15 #include "crypto/scoped_openssl_types.h" |
16 | 16 |
17 namespace crypto { | 17 namespace crypto { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Function pointer definition, for injecting the required key export function | 21 // Function pointer definition, for injecting the required key export function |
22 // into ExportKeyWithBio, below. |bio| is a temporary memory BIO object, and | 22 // into ExportKeyWithBio, below. |bio| is a temporary memory BIO object, and |
23 // |key| is a handle to the input key object. Return 1 on success, 0 otherwise. | 23 // |key| is a handle to the input key object. Return 1 on success, 0 otherwise. |
24 // NOTE: Used with OpenSSL functions, which do not comply with the Chromium | 24 // NOTE: Used with OpenSSL functions, which do not comply with the Chromium |
25 // style guide, hence the unusual parameter placement / types. | 25 // style guide, hence the unusual parameter placement / types. |
26 typedef int (*ExportBioFunction)(BIO* bio, const void* key); | 26 typedef int (*ExportBioFunction)(BIO* bio, const void* key); |
27 | 27 |
28 typedef ScopedOpenSSL<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>::Type | 28 using ScopedPKCS8_PRIV_KEY_INFO = |
29 ScopedPKCS8_PRIV_KEY_INFO; | 29 ScopedOpenSSL<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>; |
30 typedef ScopedOpenSSL<X509_SIG, X509_SIG_free>::Type ScopedX509_SIG; | 30 using ScopedX509_SIG = ScopedOpenSSL<X509_SIG, X509_SIG_free>; |
31 | 31 |
32 // Helper to export |key| into |output| via the specified ExportBioFunction. | 32 // Helper to export |key| into |output| via the specified ExportBioFunction. |
33 bool ExportKeyWithBio(const void* key, | 33 bool ExportKeyWithBio(const void* key, |
34 ExportBioFunction export_fn, | 34 ExportBioFunction export_fn, |
35 std::vector<uint8>* output) { | 35 std::vector<uint8>* output) { |
36 if (!key) | 36 if (!key) |
37 return false; | 37 return false; |
38 | 38 |
39 ScopedBIO bio(BIO_new(BIO_s_mem())); | 39 ScopedBIO bio(BIO_new(BIO_s_mem())); |
40 if (!bio.get()) | 40 if (!bio.get()) |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 222 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
223 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); | 223 ScopedEC_KEY ec_key(EVP_PKEY_get1_EC_KEY(key_)); |
224 return ExportKey(ec_key.get(), | 224 return ExportKey(ec_key.get(), |
225 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), | 225 reinterpret_cast<ExportDataFunction>(i2d_ECParameters), |
226 output); | 226 output); |
227 } | 227 } |
228 | 228 |
229 ECPrivateKey::ECPrivateKey() : key_(NULL) {} | 229 ECPrivateKey::ECPrivateKey() : key_(NULL) {} |
230 | 230 |
231 } // namespace crypto | 231 } // namespace crypto |
OLD | NEW |