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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 #if defined(USE_OPENSSL) | 12 // TODO(mattm): also add some exported keys from each to test |
wtc
2013/10/14 21:45:07
Nit: remove "also".
digit1
2013/10/15 11:43:44
Done.
| |
13 // Once ECPrivateKey is implemented for OpenSSL, remove this #if block. | |
14 // TODO(mattm): When that happens, also add some exported keys from each to test | |
15 // interop between NSS and OpenSSL. | 13 // interop between NSS and OpenSSL. |
16 TEST(ECPrivateKeyUnitTest, OpenSSLStub) { | 14 |
17 scoped_ptr<crypto::ECPrivateKey> keypair1( | |
18 crypto::ECPrivateKey::Create()); | |
19 ASSERT_FALSE(keypair1.get()); | |
20 } | |
21 #else | |
22 // Generate random private keys. Export, then re-import. We should get | 15 // Generate random private keys. Export, then re-import. We should get |
23 // back the same exact public key, and the private key should have the same | 16 // back the same exact public key, and the private key should have the same |
24 // value and elliptic curve params. | 17 // value and elliptic curve params. |
25 TEST(ECPrivateKeyUnitTest, InitRandomTest) { | 18 TEST(ECPrivateKeyUnitTest, InitRandomTest) { |
26 const std::string password1; | 19 const std::string password1; |
27 const std::string password2 = "test"; | 20 const std::string password2 = "test"; |
28 | 21 |
29 scoped_ptr<crypto::ECPrivateKey> keypair1( | 22 scoped_ptr<crypto::ECPrivateKey> keypair1( |
30 crypto::ECPrivateKey::Create()); | 23 crypto::ECPrivateKey::Create()); |
31 scoped_ptr<crypto::ECPrivateKey> keypair2( | 24 scoped_ptr<crypto::ECPrivateKey> keypair2( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 std::vector<uint8> privkey1; | 89 std::vector<uint8> privkey1; |
97 std::vector<uint8> pubkey1; | 90 std::vector<uint8> pubkey1; |
98 ASSERT_TRUE(keypair1->ExportEncryptedPrivateKey( | 91 ASSERT_TRUE(keypair1->ExportEncryptedPrivateKey( |
99 password1, 1, &privkey1)); | 92 password1, 1, &privkey1)); |
100 ASSERT_TRUE(keypair1->ExportPublicKey(&pubkey1)); | 93 ASSERT_TRUE(keypair1->ExportPublicKey(&pubkey1)); |
101 | 94 |
102 scoped_ptr<crypto::ECPrivateKey> keypair2( | 95 scoped_ptr<crypto::ECPrivateKey> keypair2( |
103 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | 96 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
104 password2, privkey1, pubkey1)); | 97 password2, privkey1, pubkey1)); |
105 ASSERT_FALSE(keypair2.get()); | 98 ASSERT_FALSE(keypair2.get()); |
106 } | 99 } |
107 #endif // !defined(USE_OPENSSL) | |
OLD | NEW |