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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return private_key_info.Export(output); | 161 return private_key_info.Export(output); |
162 } | 162 } |
163 | 163 |
164 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { | 164 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { |
165 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_)); | 165 ScopedSECItem der_pubkey(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key_)); |
166 if (!der_pubkey.get()) { | 166 if (!der_pubkey.get()) { |
167 NOTREACHED(); | 167 NOTREACHED(); |
168 return false; | 168 return false; |
169 } | 169 } |
170 | 170 |
171 for (size_t i = 0; i < der_pubkey->len; ++i) | 171 output->assign(der_pubkey->data, der_pubkey->data + der_pubkey->len); |
172 output->push_back(der_pubkey->data[i]); | |
173 | |
174 return true; | 172 return true; |
175 } | 173 } |
176 | 174 |
177 RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) { | 175 RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) { |
178 EnsureNSSInit(); | 176 EnsureNSSInit(); |
179 } | 177 } |
180 | 178 |
181 // static | 179 // static |
182 RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits, | 180 RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits, |
183 bool permanent, | 181 bool permanent, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); | 236 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); |
239 if (!result->public_key_) { | 237 if (!result->public_key_) { |
240 NOTREACHED(); | 238 NOTREACHED(); |
241 return NULL; | 239 return NULL; |
242 } | 240 } |
243 | 241 |
244 return result.release(); | 242 return result.release(); |
245 } | 243 } |
246 | 244 |
247 } // namespace crypto | 245 } // namespace crypto |
OLD | NEW |