Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: crypto/rsa_private_key_openssl.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/rsa_private_key_nss.cc ('k') | crypto/rsa_private_key_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo( 76 RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo(
77 const std::vector<uint8>& input) { 77 const std::vector<uint8>& input) {
78 if (input.empty()) 78 if (input.empty())
79 return NULL; 79 return NULL;
80 80
81 OpenSSLErrStackTracer err_tracer(FROM_HERE); 81 OpenSSLErrStackTracer err_tracer(FROM_HERE);
82 82
83 // Importing is a little more involved than exporting, as we must first 83 // Importing is a little more involved than exporting, as we must first
84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key 84 // PKCS#8 decode the input, and then import the EVP_PKEY from Private Key
85 // Info structure returned. 85 // Info structure returned.
86 //
87 // TODO(davidben): This should check that |ptr| advanced to the end of |input|
88 // to ensure there is no trailing data.
89 const uint8_t* ptr = &input[0]; 86 const uint8_t* ptr = &input[0];
90 ScopedPKCS8_PRIV_KEY_INFO p8inf( 87 ScopedPKCS8_PRIV_KEY_INFO p8inf(
91 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size())); 88 d2i_PKCS8_PRIV_KEY_INFO(nullptr, &ptr, input.size()));
92 if (!p8inf.get()) 89 if (!p8inf.get() || ptr != &input[0] + input.size())
93 return NULL; 90 return NULL;
94 91
95 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); 92 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
96 result->key_ = EVP_PKCS82PKEY(p8inf.get()); 93 result->key_ = EVP_PKCS82PKEY(p8inf.get());
97 if (!result->key_) 94 if (!result->key_)
98 return NULL; 95 return NULL;
99 96
100 return result.release(); 97 return result.release();
101 } 98 }
102 99
(...skipping 29 matching lines...) Expand all
132 129
133 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { 130 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
134 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); 131 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output);
135 } 132 }
136 133
137 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { 134 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
138 return ExportKey(key_, i2d_PUBKEY_bio, output); 135 return ExportKey(key_, i2d_PUBKEY_bio, output);
139 } 136 }
140 137
141 } // namespace crypto 138 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_nss.cc ('k') | crypto/rsa_private_key_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698