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

Side by Side Diff: crypto/rsa_private_key_mac.cc

Issue 8727014: Implement RSAPrivateKey::Copy() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years 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.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 <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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 RSAPrivateKey::~RSAPrivateKey() { 168 RSAPrivateKey::~RSAPrivateKey() {
169 if (key_.KeyData.Data) { 169 if (key_.KeyData.Data) {
170 CSSM_FreeKey(GetSharedCSPHandle(), NULL, &key_, CSSM_FALSE); 170 CSSM_FreeKey(GetSharedCSPHandle(), NULL, &key_, CSSM_FALSE);
171 } 171 }
172 if (public_key_.KeyData.Data) { 172 if (public_key_.KeyData.Data) {
173 CSSM_FreeKey(GetSharedCSPHandle(), NULL, &public_key_, CSSM_FALSE); 173 CSSM_FreeKey(GetSharedCSPHandle(), NULL, &public_key_, CSSM_FALSE);
174 } 174 }
175 } 175 }
176 176
177 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { 177 RSAPrivateKey* RSAPrivateKey::Copy() const {
178 std::vector<uint8> key_bytes;
179 if (!ExportPrivateKey(&key_bytes))
180 return NULL;
181 return CreateFromPrivateKeyInfo(key_bytes);
182 }
183
184 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
178 if (!key_.KeyData.Data || !key_.KeyData.Length) { 185 if (!key_.KeyData.Data || !key_.KeyData.Length) {
179 return false; 186 return false;
180 } 187 }
181 output->clear(); 188 output->clear();
182 output->insert(output->end(), key_.KeyData.Data, 189 output->insert(output->end(), key_.KeyData.Data,
183 key_.KeyData.Data + key_.KeyData.Length); 190 key_.KeyData.Data + key_.KeyData.Length);
184 return true; 191 return true;
185 } 192 }
186 193
187 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) { 194 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
188 PrivateKeyInfoCodec private_key_info(true); 195 PrivateKeyInfoCodec private_key_info(true);
189 std::vector<uint8> private_key_data; 196 std::vector<uint8> private_key_data;
190 private_key_data.assign(key_.KeyData.Data, 197 private_key_data.assign(key_.KeyData.Data,
191 key_.KeyData.Data + key_.KeyData.Length); 198 key_.KeyData.Data + key_.KeyData.Length);
192 return (private_key_info.Import(private_key_data) && 199 return (private_key_info.Import(private_key_data) &&
193 private_key_info.ExportPublicKeyInfo(output)); 200 private_key_info.ExportPublicKeyInfo(output));
194 } 201 }
195 202
196 } // namespace crypto 203 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/rsa_private_key.h ('k') | crypto/rsa_private_key_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698