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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: crypto/rsa_private_key_mac.cc
diff --git a/crypto/rsa_private_key_mac.cc b/crypto/rsa_private_key_mac.cc
index 85dadfa9ee67fe4df267514d845a48e2c4f9cd60..61ff7200e6a48bc5c25c4b1806f1de0b297559ba 100644
--- a/crypto/rsa_private_key_mac.cc
+++ b/crypto/rsa_private_key_mac.cc
@@ -10,6 +10,23 @@
#include "base/memory/scoped_ptr.h"
#include "crypto/cssm_init.h"
+namespace {
+
+bool CopyCssmKey(const CSSM_KEY& source, CSSM_KEY* destination) {
wtc 2011/11/30 00:58:10 Nit: CopyCssmKey => CopyCSSMKey rsleevi: is there
Ryan Sleevi 2011/11/30 02:05:09 No. Further, it's not necessarily safe to copy Ke
Sergey Ulanov 2011/11/30 22:30:03 Removed this function
+ destination->KeyHeader = source.KeyHeader;
+ destination->KeyData.Length = source.KeyData.Length;
+ destination->KeyData.Data =
+ reinterpret_cast<uint8*>(crypto::CSSMMalloc(source.KeyData.Length));
+ if (!destination->KeyData.Data) {
+ NOTREACHED() << "CSSMMalloc failed";
+ return false;
+ }
+ memcpy(destination->KeyData.Data, source.KeyData.Data, source.KeyData.Length);
+ return true;
+}
+
+} // namespace
+
namespace crypto {
// static
@@ -174,13 +191,22 @@ RSAPrivateKey::~RSAPrivateKey() {
}
}
+RSAPrivateKey* RSAPrivateKey::Copy() const {
+ scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey());
+ if (!CopyCssmKey(key_, &copy->key_) ||
+ !CopyCssmKey(public_key_, &copy->public_key_)) {
+ return NULL;
+ }
+ return copy.release();
+}
+
bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) {
if (!key_.KeyData.Data || !key_.KeyData.Length) {
return false;
}
output->clear();
output->insert(output->end(), key_.KeyData.Data,
- key_.KeyData.Data + key_.KeyData.Length);
+ key_.KeyData.Data + key_.KeyData.Length);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698