Chromium Code Reviews| 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 <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 127 |
| 128 RSAPrivateKey::RSAPrivateKey() : provider_(NULL), key_(NULL) {} | 128 RSAPrivateKey::RSAPrivateKey() : provider_(NULL), key_(NULL) {} |
| 129 | 129 |
| 130 RSAPrivateKey::~RSAPrivateKey() {} | 130 RSAPrivateKey::~RSAPrivateKey() {} |
| 131 | 131 |
| 132 bool RSAPrivateKey::InitProvider() { | 132 bool RSAPrivateKey::InitProvider() { |
| 133 return FALSE != CryptAcquireContext(provider_.receive(), NULL, NULL, | 133 return FALSE != CryptAcquireContext(provider_.receive(), NULL, NULL, |
| 134 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); | 134 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); |
| 135 } | 135 } |
| 136 | 136 |
| 137 RSAPrivateKey* RSAPrivateKey::Copy() const { | |
| 138 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); | |
| 139 if (!copy->InitProvider()) | |
|
wtc
2011/11/30 00:58:10
Instead of calling copy->InitProvider(), I think i
Sergey Ulanov
2011/11/30 22:30:03
Done.
| |
| 140 return NULL; | |
| 141 if (!CryptDuplicateKey(key_.get(), NULL, 0, copy->key_.receive())) | |
| 142 return NULL; | |
| 143 return copy.release(); | |
| 144 } | |
| 145 | |
| 137 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { | 146 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { |
| 138 // Export the key | 147 // Export the key |
| 139 DWORD blob_length = 0; | 148 DWORD blob_length = 0; |
| 140 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, NULL, &blob_length)) { | 149 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, NULL, &blob_length)) { |
| 141 NOTREACHED(); | 150 NOTREACHED(); |
| 142 return false; | 151 return false; |
| 143 } | 152 } |
| 144 | 153 |
| 145 scoped_array<uint8> blob(new uint8[blob_length]); | 154 scoped_array<uint8> blob(new uint8[blob_length]); |
| 146 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, blob.get(), &blob_length)) { | 155 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, blob.get(), &blob_length)) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 &encoded_length)) { | 229 &encoded_length)) { |
| 221 NOTREACHED(); | 230 NOTREACHED(); |
| 222 return false; | 231 return false; |
| 223 } | 232 } |
| 224 | 233 |
| 225 output->assign(encoded.get(), encoded.get() + encoded_length); | 234 output->assign(encoded.get(), encoded.get() + encoded_length); |
| 226 return true; | 235 return true; |
| 227 } | 236 } |
| 228 | 237 |
| 229 } // namespace crypto | 238 } // namespace crypto |
| OLD | NEW |