| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 ck_id.get(), NULL); | 131 ck_id.get(), NULL); |
| 132 if (result->key_) | 132 if (result->key_) |
| 133 return result.release(); | 133 return result.release(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 // We didn't find the key. | 137 // We didn't find the key. |
| 138 return NULL; | 138 return NULL; |
| 139 } | 139 } |
| 140 | 140 |
| 141 RSAPrivateKey* RSAPrivateKey::Copy() const { |
| 142 RSAPrivateKey* copy = new RSAPrivateKey(); |
| 143 copy->key_ = SECKEY_CopyPrivateKey(key_); |
| 144 copy->public_key_ = SECKEY_CopyPublicKey(public_key_); |
| 145 return copy; |
| 146 } |
| 141 | 147 |
| 142 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { | 148 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { |
| 143 PrivateKeyInfoCodec private_key_info(true); | 149 PrivateKeyInfoCodec private_key_info(true); |
| 144 | 150 |
| 145 // Manually read the component attributes of the private key and build up | 151 // Manually read the component attributes of the private key and build up |
| 146 // the PrivateKeyInfo. | 152 // the PrivateKeyInfo. |
| 147 if (!ReadAttribute(key_, CKA_MODULUS, private_key_info.modulus()) || | 153 if (!ReadAttribute(key_, CKA_MODULUS, private_key_info.modulus()) || |
| 148 !ReadAttribute(key_, CKA_PUBLIC_EXPONENT, | 154 !ReadAttribute(key_, CKA_PUBLIC_EXPONENT, |
| 149 private_key_info.public_exponent()) || | 155 private_key_info.public_exponent()) || |
| 150 !ReadAttribute(key_, CKA_PRIVATE_EXPONENT, | 156 !ReadAttribute(key_, CKA_PRIVATE_EXPONENT, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); | 242 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); |
| 237 if (!result->public_key_) { | 243 if (!result->public_key_) { |
| 238 NOTREACHED(); | 244 NOTREACHED(); |
| 239 return NULL; | 245 return NULL; |
| 240 } | 246 } |
| 241 | 247 |
| 242 return result.release(); | 248 return result.release(); |
| 243 } | 249 } |
| 244 | 250 |
| 245 } // namespace crypto | 251 } // namespace crypto |
| OLD | NEW |