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

Side by Side Diff: crypto/ec_signature_creator_unittest.cc

Issue 2608453002: Remove the password parameter for ECPrivateKey::ExportEncryptedPrivateKey. (Closed)
Patch Set: fmt Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_signature_creator.h" 5 #include "crypto/ec_signature_creator.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "crypto/ec_private_key.h" 13 #include "crypto/ec_private_key.h"
14 #include "crypto/signature_verifier.h" 14 #include "crypto/signature_verifier.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 // TODO(rch): Add some exported keys from each to 17 // TODO(rch): Add some exported keys from each to
18 // test interop between NSS and OpenSSL. 18 // test interop between NSS and OpenSSL.
19 19
20 TEST(ECSignatureCreatorTest, BasicTest) { 20 TEST(ECSignatureCreatorTest, BasicTest) {
21 // Do a verify round trip. 21 // Do a verify round trip.
22 std::unique_ptr<crypto::ECPrivateKey> key_original( 22 std::unique_ptr<crypto::ECPrivateKey> key_original(
23 crypto::ECPrivateKey::Create()); 23 crypto::ECPrivateKey::Create());
24 ASSERT_TRUE(key_original.get()); 24 ASSERT_TRUE(key_original);
25 25
26 std::vector<uint8_t> key_info; 26 std::vector<uint8_t> key_info;
27 ASSERT_TRUE( 27 ASSERT_TRUE(key_original->ExportPrivateKey(&key_info));
28 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info));
29 std::vector<uint8_t> pubkey_info;
30 ASSERT_TRUE(key_original->ExportPublicKey(&pubkey_info));
31 28
32 std::unique_ptr<crypto::ECPrivateKey> key( 29 std::unique_ptr<crypto::ECPrivateKey> key(
33 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 30 crypto::ECPrivateKey::CreateFromPrivateKeyInfo(key_info));
34 std::string(), key_info, pubkey_info)); 31 ASSERT_TRUE(key);
35 ASSERT_TRUE(key.get()); 32 ASSERT_TRUE(key->key());
36 ASSERT_TRUE(key->key() != NULL);
37 33
38 std::unique_ptr<crypto::ECSignatureCreator> signer( 34 std::unique_ptr<crypto::ECSignatureCreator> signer(
39 crypto::ECSignatureCreator::Create(key.get())); 35 crypto::ECSignatureCreator::Create(key.get()));
40 ASSERT_TRUE(signer.get()); 36 ASSERT_TRUE(signer);
41 37
42 std::string data("Hello, World!"); 38 std::string data("Hello, World!");
43 std::vector<uint8_t> signature; 39 std::vector<uint8_t> signature;
44 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()), 40 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()),
45 data.size(), &signature)); 41 data.size(), &signature));
46 42
47 std::vector<uint8_t> public_key_info; 43 std::vector<uint8_t> public_key_info;
48 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); 44 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info));
49 45
50 crypto::SignatureVerifier verifier; 46 crypto::SignatureVerifier verifier;
51 ASSERT_TRUE(verifier.VerifyInit( 47 ASSERT_TRUE(verifier.VerifyInit(
52 crypto::SignatureVerifier::ECDSA_SHA256, &signature[0], signature.size(), 48 crypto::SignatureVerifier::ECDSA_SHA256, &signature[0], signature.size(),
53 &public_key_info.front(), public_key_info.size())); 49 &public_key_info.front(), public_key_info.size()));
54 50
55 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()), 51 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()),
56 data.size()); 52 data.size());
57 ASSERT_TRUE(verifier.VerifyFinal()); 53 ASSERT_TRUE(verifier.VerifyFinal());
58 } 54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698