| 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 <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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |