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 "base/crypto/rsa_private_key.h" | 5 #include "base/crypto/rsa_private_key.h" |
6 | 6 |
7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
8 #include <openssl/pkcs12.h> | 8 #include <openssl/pkcs12.h> |
9 #include <openssl/rsa.h> | 9 #include <openssl/rsa.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/openssl_util.h" | 13 #include "base/openssl_util.h" |
14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
15 | 15 |
16 namespace base { | 16 namespace crypto { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Function pointer definition, for injecting the required key export function | 20 // Function pointer definition, for injecting the required key export function |
21 // into ExportKey, below. The supplied function should export EVP_PKEY into | 21 // into ExportKey, below. The supplied function should export EVP_PKEY into |
22 // the supplied BIO, returning 1 on success or 0 on failure. | 22 // the supplied BIO, returning 1 on success or 0 on failure. |
23 typedef int (ExportFunction)(BIO*, EVP_PKEY*); | 23 typedef int (ExportFunction)(BIO*, EVP_PKEY*); |
24 | 24 |
25 // Helper to export |key| into |output| via the specified ExportFunction. | 25 // Helper to export |key| into |output| via the specified ExportFunction. |
26 bool ExportKey(EVP_PKEY* key, | 26 bool ExportKey(EVP_PKEY* key, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 125 } |
126 | 126 |
127 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { | 127 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { |
128 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); | 128 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); |
129 } | 129 } |
130 | 130 |
131 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { | 131 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { |
132 return ExportKey(key_, i2d_PUBKEY_bio, output); | 132 return ExportKey(key_, i2d_PUBKEY_bio, output); |
133 } | 133 } |
134 | 134 |
135 } // namespace base | 135 } // namespace crypto |
OLD | NEW |