Commit e6bf56c0 authored by nharper's avatar nharper Committed by Commit bot

Add support for crypto::ECPrivateKey::Copy when built with BoringSSL

BUG=457566

Review URL: https://codereview.chromium.org/1133303003

Cr-Commit-Position: refs/heads/master@{#329527}
parent 0ebc6991
...@@ -66,10 +66,10 @@ class CRYPTO_EXPORT ECPrivateKey { ...@@ -66,10 +66,10 @@ class CRYPTO_EXPORT ECPrivateKey {
bool sensitive, bool sensitive,
SECKEYPrivateKey** key, SECKEYPrivateKey** key,
SECKEYPublicKey** public_key); SECKEYPublicKey** public_key);
#endif
// Returns a copy of the object. // Returns a copy of the object.
ECPrivateKey* Copy() const; ECPrivateKey* Copy() const;
#endif
#if defined(USE_OPENSSL) #if defined(USE_OPENSSL)
EVP_PKEY* key() { return key_; } EVP_PKEY* key() { return key_; }
......
...@@ -85,6 +85,13 @@ ECPrivateKey::~ECPrivateKey() { ...@@ -85,6 +85,13 @@ ECPrivateKey::~ECPrivateKey() {
EVP_PKEY_free(key_); EVP_PKEY_free(key_);
} }
ECPrivateKey* ECPrivateKey::Copy() const {
scoped_ptr<ECPrivateKey> copy(new ECPrivateKey);
if (key_)
copy->key_ = EVP_PKEY_dup(key_);
return copy.release();
}
// static // static
bool ECPrivateKey::IsSupported() { return true; } bool ECPrivateKey::IsSupported() { return true; }
......
...@@ -82,7 +82,6 @@ TEST(ECPrivateKeyUnitTest, InitRandomTest) { ...@@ -82,7 +82,6 @@ TEST(ECPrivateKeyUnitTest, InitRandomTest) {
EXPECT_EQ(raw_pubkey2, raw_pubkey4); EXPECT_EQ(raw_pubkey2, raw_pubkey4);
} }
#if !defined(USE_OPENSSL)
TEST(ECPrivateKeyUnitTest, Copy) { TEST(ECPrivateKeyUnitTest, Copy) {
scoped_ptr<crypto::ECPrivateKey> keypair1(crypto::ECPrivateKey::Create()); scoped_ptr<crypto::ECPrivateKey> keypair1(crypto::ECPrivateKey::Create());
scoped_ptr<crypto::ECPrivateKey> keypair2(keypair1->Copy()); scoped_ptr<crypto::ECPrivateKey> keypair2(keypair1->Copy());
...@@ -113,7 +112,6 @@ TEST(ECPrivateKeyUnitTest, Copy) { ...@@ -113,7 +112,6 @@ TEST(ECPrivateKeyUnitTest, Copy) {
EXPECT_TRUE(keypair2->ExportRawPublicKey(&raw_pubkey2)); EXPECT_TRUE(keypair2->ExportRawPublicKey(&raw_pubkey2));
EXPECT_EQ(raw_pubkey1, raw_pubkey2); EXPECT_EQ(raw_pubkey1, raw_pubkey2);
} }
#endif // !defined(USE_OPENSSL)
TEST(ECPrivateKeyUnitTest, BadPasswordTest) { TEST(ECPrivateKeyUnitTest, BadPasswordTest) {
const std::string password1; const std::string password1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment