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

Side by Side Diff: crypto/ec_private_key_unittest.cc

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 months 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 | « courgette/bsdiff_memory_unittest.cc ('k') | crypto/ec_signature_creator_unittest.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/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 #if defined(USE_OPENSSL)
13 // Once ECPrivateKey is implemented for OpenSSL, remove this #if block. 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 14 // TODO(mattm): When that happens, also add some exported keys from each to test
15 // interop between NSS and OpenSSL. 15 // interop between NSS and OpenSSL.
16 TEST(ECPrivateKeyUnitTest, OpenSSLStub) { 16 TEST(ECPrivateKeyUnitTest, OpenSSLStub) {
17 scoped_ptr<crypto::ECPrivateKey> keypair1( 17 scoped_ptr<crypto::ECPrivateKey> keypair1(
18 crypto::ECPrivateKey::Create()); 18 crypto::ECPrivateKey::Create());
19 ASSERT_FALSE(keypair1.get()); 19 ASSERT_FALSE(keypair1.get());
20 } 20 }
21 #else 21 #else
22 // Generate random private keys. Export, then re-import. We should get 22 // 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 23 // back the same exact public key, and the private key should have the same
24 // value and elliptic curve params. 24 // value and elliptic curve params.
25 TEST(ECPrivateKeyUnitTest, InitRandomTest) { 25 TEST(ECPrivateKeyUnitTest, InitRandomTest) {
26 const std::string password1 = ""; 26 const std::string password1;
27 const std::string password2 = "test"; 27 const std::string password2 = "test";
28 28
29 scoped_ptr<crypto::ECPrivateKey> keypair1( 29 scoped_ptr<crypto::ECPrivateKey> keypair1(
30 crypto::ECPrivateKey::Create()); 30 crypto::ECPrivateKey::Create());
31 scoped_ptr<crypto::ECPrivateKey> keypair2( 31 scoped_ptr<crypto::ECPrivateKey> keypair2(
32 crypto::ECPrivateKey::Create()); 32 crypto::ECPrivateKey::Create());
33 ASSERT_TRUE(keypair1.get()); 33 ASSERT_TRUE(keypair1.get());
34 ASSERT_TRUE(keypair2.get()); 34 ASSERT_TRUE(keypair2.get());
35 35
36 std::vector<uint8> key1value; 36 std::vector<uint8> key1value;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 std::vector<uint8> pubkey3; 79 std::vector<uint8> pubkey3;
80 std::vector<uint8> pubkey4; 80 std::vector<uint8> pubkey4;
81 EXPECT_TRUE(keypair3->ExportPublicKey(&pubkey3)); 81 EXPECT_TRUE(keypair3->ExportPublicKey(&pubkey3));
82 EXPECT_TRUE(keypair4->ExportPublicKey(&pubkey4)); 82 EXPECT_TRUE(keypair4->ExportPublicKey(&pubkey4));
83 83
84 EXPECT_EQ(pubkey1, pubkey3); 84 EXPECT_EQ(pubkey1, pubkey3);
85 EXPECT_EQ(pubkey2, pubkey4); 85 EXPECT_EQ(pubkey2, pubkey4);
86 } 86 }
87 87
88 TEST(ECPrivateKeyUnitTest, BadPasswordTest) { 88 TEST(ECPrivateKeyUnitTest, BadPasswordTest) {
89 const std::string password1 = ""; 89 const std::string password1;
90 const std::string password2 = "test"; 90 const std::string password2 = "test";
91 91
92 scoped_ptr<crypto::ECPrivateKey> keypair1( 92 scoped_ptr<crypto::ECPrivateKey> keypair1(
93 crypto::ECPrivateKey::Create()); 93 crypto::ECPrivateKey::Create());
94 ASSERT_TRUE(keypair1.get()); 94 ASSERT_TRUE(keypair1.get());
95 95
96 std::vector<uint8> privkey1; 96 std::vector<uint8> privkey1;
97 std::vector<uint8> pubkey1; 97 std::vector<uint8> pubkey1;
98 ASSERT_TRUE(keypair1->ExportEncryptedPrivateKey( 98 ASSERT_TRUE(keypair1->ExportEncryptedPrivateKey(
99 password1, 1, &privkey1)); 99 password1, 1, &privkey1));
100 ASSERT_TRUE(keypair1->ExportPublicKey(&pubkey1)); 100 ASSERT_TRUE(keypair1->ExportPublicKey(&pubkey1));
101 101
102 scoped_ptr<crypto::ECPrivateKey> keypair2( 102 scoped_ptr<crypto::ECPrivateKey> keypair2(
103 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 103 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
104 password2, privkey1, pubkey1)); 104 password2, privkey1, pubkey1));
105 ASSERT_FALSE(keypair2.get()); 105 ASSERT_FALSE(keypair2.get());
106 } 106 }
107 #endif // !defined(USE_OPENSSL) 107 #endif // !defined(USE_OPENSSL)
OLDNEW
« no previous file with comments | « courgette/bsdiff_memory_unittest.cc ('k') | crypto/ec_signature_creator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698