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

Side by Side Diff: crypto/rsa_private_key_nss.cc

Issue 14941007: Add RSAPrivateKey::CreateFromKeypair() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add NULL checks for key_, public_key_ Created 7 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « crypto/rsa_private_key.h ('k') | crypto/rsa_private_key_nss_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 <cryptohi.h> 7 #include <cryptohi.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 #include <secmod.h> 10 #include <secmod.h>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 // static 75 // static
76 RSAPrivateKey* RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo( 76 RSAPrivateKey* RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(
77 const std::vector<uint8>& input) { 77 const std::vector<uint8>& input) {
78 return CreateFromPrivateKeyInfoWithParams(input, 78 return CreateFromPrivateKeyInfoWithParams(input,
79 PR_TRUE /* permanent */, 79 PR_TRUE /* permanent */,
80 PR_TRUE /* sensitive */); 80 PR_TRUE /* sensitive */);
81 } 81 }
82 82
83 // static 83 // static
84 RSAPrivateKey* RSAPrivateKey::CreateFromKey(SECKEYPrivateKey* key) {
85 DCHECK(key);
86 if (SECKEY_GetPrivateKeyType(key) != rsaKey)
87 return NULL;
88 RSAPrivateKey* copy = new RSAPrivateKey();
89 copy->key_ = SECKEY_CopyPrivateKey(key);
90 copy->public_key_ = SECKEY_ConvertToPublicKey(key);
91 if (!copy->key_ || !copy->public_key_) {
92 NOTREACHED();
93 delete copy;
94 return NULL;
95 }
96 return copy;
97 }
98
99 // static
84 RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo( 100 RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo(
85 const std::vector<uint8>& input) { 101 const std::vector<uint8>& input) {
86 EnsureNSSInit(); 102 EnsureNSSInit();
87 103
88 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); 104 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
89 105
90 // First, decode and save the public key. 106 // First, decode and save the public key.
91 SECItem key_der; 107 SECItem key_der;
92 key_der.type = siBuffer; 108 key_der.type = siBuffer;
93 key_der.data = const_cast<unsigned char*>(&input[0]); 109 key_der.data = const_cast<unsigned char*>(&input[0]);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); 258 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_);
243 if (!result->public_key_) { 259 if (!result->public_key_) {
244 NOTREACHED(); 260 NOTREACHED();
245 return NULL; 261 return NULL;
246 } 262 }
247 263
248 return result.release(); 264 return result.release();
249 } 265 }
250 266
251 } // namespace crypto 267 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key.h ('k') | crypto/rsa_private_key_nss_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698