| 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/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/stl_util-inl.h" | |
| 14 #include "crypto/openssl_util.h" | 13 #include "crypto/openssl_util.h" |
| 15 | 14 |
| 16 namespace crypto { | 15 namespace crypto { |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 // Function pointer definition, for injecting the required key export function | 19 // Function pointer definition, for injecting the required key export function |
| 21 // into ExportKey, below. The supplied function should export EVP_PKEY into | 20 // into ExportKey, below. The supplied function should export EVP_PKEY into |
| 22 // the supplied BIO, returning 1 on success or 0 on failure. | 21 // the supplied BIO, returning 1 on success or 0 on failure. |
| 23 typedef int (ExportFunction)(BIO*, EVP_PKEY*); | 22 typedef int (ExportFunction)(BIO*, EVP_PKEY*); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 34 | 33 |
| 35 int res = export_fn(bio.get(), key); | 34 int res = export_fn(bio.get(), key); |
| 36 if (!res) | 35 if (!res) |
| 37 return false; | 36 return false; |
| 38 | 37 |
| 39 char* data = NULL; | 38 char* data = NULL; |
| 40 long len = BIO_get_mem_data(bio.get(), &data); | 39 long len = BIO_get_mem_data(bio.get(), &data); |
| 41 if (!data || len < 0) | 40 if (!data || len < 0) |
| 42 return false; | 41 return false; |
| 43 | 42 |
| 44 STLAssignToVector(output, reinterpret_cast<const uint8*>(data), len); | 43 std::vector<uint8> for_output(data, data + len); |
| 44 output->swap(for_output); |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 RSAPrivateKey* RSAPrivateKey::Create(uint16 num_bits) { | 51 RSAPrivateKey* RSAPrivateKey::Create(uint16 num_bits) { |
| 52 OpenSSLErrStackTracer err_tracer(FROM_HERE); | 52 OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 53 | 53 |
| 54 ScopedOpenSSL<RSA, RSA_free> rsa_key(RSA_new()); | 54 ScopedOpenSSL<RSA, RSA_free> rsa_key(RSA_new()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 crypto | 135 } // namespace crypto |
| OLD | NEW |