| 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/ec_private_key.h" | 5 #include "crypto/ec_private_key.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 EXPECT_TRUE(keypair4->ExportPublicKey(&pubkey4)); | 75 EXPECT_TRUE(keypair4->ExportPublicKey(&pubkey4)); |
| 76 EXPECT_TRUE(keypair3->ExportRawPublicKey(&raw_pubkey3)); | 76 EXPECT_TRUE(keypair3->ExportRawPublicKey(&raw_pubkey3)); |
| 77 EXPECT_TRUE(keypair4->ExportRawPublicKey(&raw_pubkey4)); | 77 EXPECT_TRUE(keypair4->ExportRawPublicKey(&raw_pubkey4)); |
| 78 | 78 |
| 79 EXPECT_EQ(pubkey1, pubkey3); | 79 EXPECT_EQ(pubkey1, pubkey3); |
| 80 EXPECT_EQ(pubkey2, pubkey4); | 80 EXPECT_EQ(pubkey2, pubkey4); |
| 81 EXPECT_EQ(raw_pubkey1, raw_pubkey3); | 81 EXPECT_EQ(raw_pubkey1, raw_pubkey3); |
| 82 EXPECT_EQ(raw_pubkey2, raw_pubkey4); | 82 EXPECT_EQ(raw_pubkey2, raw_pubkey4); |
| 83 } | 83 } |
| 84 | 84 |
| 85 #if !defined(USE_OPENSSL) | |
| 86 TEST(ECPrivateKeyUnitTest, Copy) { | 85 TEST(ECPrivateKeyUnitTest, Copy) { |
| 87 scoped_ptr<crypto::ECPrivateKey> keypair1(crypto::ECPrivateKey::Create()); | 86 scoped_ptr<crypto::ECPrivateKey> keypair1(crypto::ECPrivateKey::Create()); |
| 88 scoped_ptr<crypto::ECPrivateKey> keypair2(keypair1->Copy()); | 87 scoped_ptr<crypto::ECPrivateKey> keypair2(keypair1->Copy()); |
| 89 ASSERT_TRUE(keypair1.get()); | 88 ASSERT_TRUE(keypair1.get()); |
| 90 ASSERT_TRUE(keypair2.get()); | 89 ASSERT_TRUE(keypair2.get()); |
| 91 | 90 |
| 92 std::vector<uint8> key1value; | 91 std::vector<uint8> key1value; |
| 93 std::vector<uint8> key2value; | 92 std::vector<uint8> key2value; |
| 94 EXPECT_TRUE(keypair1->ExportValue(&key1value)); | 93 EXPECT_TRUE(keypair1->ExportValue(&key1value)); |
| 95 EXPECT_TRUE(keypair2->ExportValue(&key2value)); | 94 EXPECT_TRUE(keypair2->ExportValue(&key2value)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 106 EXPECT_TRUE(keypair1->ExportPublicKey(&pubkey1)); | 105 EXPECT_TRUE(keypair1->ExportPublicKey(&pubkey1)); |
| 107 EXPECT_TRUE(keypair2->ExportPublicKey(&pubkey2)); | 106 EXPECT_TRUE(keypair2->ExportPublicKey(&pubkey2)); |
| 108 EXPECT_EQ(pubkey1, pubkey2); | 107 EXPECT_EQ(pubkey1, pubkey2); |
| 109 | 108 |
| 110 std::string raw_pubkey1; | 109 std::string raw_pubkey1; |
| 111 std::string raw_pubkey2; | 110 std::string raw_pubkey2; |
| 112 EXPECT_TRUE(keypair1->ExportRawPublicKey(&raw_pubkey1)); | 111 EXPECT_TRUE(keypair1->ExportRawPublicKey(&raw_pubkey1)); |
| 113 EXPECT_TRUE(keypair2->ExportRawPublicKey(&raw_pubkey2)); | 112 EXPECT_TRUE(keypair2->ExportRawPublicKey(&raw_pubkey2)); |
| 114 EXPECT_EQ(raw_pubkey1, raw_pubkey2); | 113 EXPECT_EQ(raw_pubkey1, raw_pubkey2); |
| 115 } | 114 } |
| 116 #endif // !defined(USE_OPENSSL) | |
| 117 | 115 |
| 118 TEST(ECPrivateKeyUnitTest, BadPasswordTest) { | 116 TEST(ECPrivateKeyUnitTest, BadPasswordTest) { |
| 119 const std::string password1; | 117 const std::string password1; |
| 120 const std::string password2 = "test"; | 118 const std::string password2 = "test"; |
| 121 | 119 |
| 122 scoped_ptr<crypto::ECPrivateKey> keypair1( | 120 scoped_ptr<crypto::ECPrivateKey> keypair1( |
| 123 crypto::ECPrivateKey::Create()); | 121 crypto::ECPrivateKey::Create()); |
| 124 ASSERT_TRUE(keypair1.get()); | 122 ASSERT_TRUE(keypair1.get()); |
| 125 | 123 |
| 126 std::vector<uint8> privkey1; | 124 std::vector<uint8> privkey1; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 scoped_ptr<crypto::ECPrivateKey> keypair_openssl( | 285 scoped_ptr<crypto::ECPrivateKey> keypair_openssl( |
| 288 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | 286 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
| 289 "", | 287 "", |
| 290 std::vector<uint8>(openssl_key, openssl_key + arraysize(openssl_key)), | 288 std::vector<uint8>(openssl_key, openssl_key + arraysize(openssl_key)), |
| 291 std::vector<uint8>(openssl_pub_key, | 289 std::vector<uint8>(openssl_pub_key, |
| 292 openssl_pub_key + arraysize(openssl_pub_key)))); | 290 openssl_pub_key + arraysize(openssl_pub_key)))); |
| 293 | 291 |
| 294 EXPECT_TRUE(keypair_openssl.get()); | 292 EXPECT_TRUE(keypair_openssl.get()); |
| 295 } | 293 } |
| 296 #endif // defined(USE_OPENSSL) | 294 #endif // defined(USE_OPENSSL) |
| OLD | NEW |