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> |
11 #include <openssl/rsa.h> | 11 #include <openssl/rsa.h> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "crypto/openssl_util.h" | 15 #include "crypto/openssl_util.h" |
16 #include "crypto/scoped_openssl_types.h" | 16 #include "crypto/scoped_openssl_types.h" |
17 | 17 |
18 namespace crypto { | 18 namespace crypto { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 typedef ScopedOpenSSL<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>::Type | 22 using ScopedPKCS8_PRIV_KEY_INFO = |
23 ScopedPKCS8_PRIV_KEY_INFO; | 23 ScopedOpenSSL<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>; |
24 | 24 |
25 // Function pointer definition, for injecting the required key export function | 25 // Function pointer definition, for injecting the required key export function |
26 // into ExportKey, below. The supplied function should export EVP_PKEY into | 26 // into ExportKey, below. The supplied function should export EVP_PKEY into |
27 // the supplied BIO, returning 1 on success or 0 on failure. | 27 // the supplied BIO, returning 1 on success or 0 on failure. |
28 typedef int (ExportFunction)(BIO*, EVP_PKEY*); | 28 using ExportFunction = int (*)(BIO*, EVP_PKEY*); |
29 | 29 |
30 // Helper to export |key| into |output| via the specified ExportFunction. | 30 // Helper to export |key| into |output| via the specified ExportFunction. |
31 bool ExportKey(EVP_PKEY* key, | 31 bool ExportKey(EVP_PKEY* key, |
32 ExportFunction export_fn, | 32 ExportFunction export_fn, |
33 std::vector<uint8>* output) { | 33 std::vector<uint8>* output) { |
34 if (!key) | 34 if (!key) |
35 return false; | 35 return false; |
36 | 36 |
37 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 37 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
38 ScopedBIO bio(BIO_new(BIO_s_mem())); | 38 ScopedBIO bio(BIO_new(BIO_s_mem())); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |