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

Side by Side Diff: crypto/ec_signature_creator_unittest.cc

Issue 1870233002: Convert crypto to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 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
« no previous file with comments | « crypto/ec_private_key_unittest.cc ('k') | crypto/encryptor.h » ('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) 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 <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/memory/scoped_ptr.h"
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 scoped_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.get());
25 25
26 std::vector<uint8_t> key_info; 26 std::vector<uint8_t> key_info;
27 ASSERT_TRUE( 27 ASSERT_TRUE(
28 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info)); 28 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info));
29 std::vector<uint8_t> pubkey_info; 29 std::vector<uint8_t> pubkey_info;
30 ASSERT_TRUE(key_original->ExportPublicKey(&pubkey_info)); 30 ASSERT_TRUE(key_original->ExportPublicKey(&pubkey_info));
31 31
32 scoped_ptr<crypto::ECPrivateKey> key( 32 std::unique_ptr<crypto::ECPrivateKey> key(
33 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 33 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
34 std::string(), key_info, pubkey_info)); 34 std::string(), key_info, pubkey_info));
35 ASSERT_TRUE(key.get()); 35 ASSERT_TRUE(key.get());
36 ASSERT_TRUE(key->key() != NULL); 36 ASSERT_TRUE(key->key() != NULL);
37 37
38 scoped_ptr<crypto::ECSignatureCreator> signer( 38 std::unique_ptr<crypto::ECSignatureCreator> signer(
39 crypto::ECSignatureCreator::Create(key.get())); 39 crypto::ECSignatureCreator::Create(key.get()));
40 ASSERT_TRUE(signer.get()); 40 ASSERT_TRUE(signer.get());
41 41
42 std::string data("Hello, World!"); 42 std::string data("Hello, World!");
43 std::vector<uint8_t> signature; 43 std::vector<uint8_t> signature;
44 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()), 44 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()),
45 data.size(), &signature)); 45 data.size(), &signature));
46 46
47 std::vector<uint8_t> public_key_info; 47 std::vector<uint8_t> public_key_info;
48 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); 48 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info));
49 49
50 crypto::SignatureVerifier verifier; 50 crypto::SignatureVerifier verifier;
51 ASSERT_TRUE(verifier.VerifyInit( 51 ASSERT_TRUE(verifier.VerifyInit(
52 crypto::SignatureVerifier::ECDSA_SHA256, &signature[0], signature.size(), 52 crypto::SignatureVerifier::ECDSA_SHA256, &signature[0], signature.size(),
53 &public_key_info.front(), public_key_info.size())); 53 &public_key_info.front(), public_key_info.size()));
54 54
55 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()), 55 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()),
56 data.size()); 56 data.size());
57 ASSERT_TRUE(verifier.VerifyFinal()); 57 ASSERT_TRUE(verifier.VerifyFinal());
58 } 58 }
OLDNEW
« no previous file with comments | « crypto/ec_private_key_unittest.cc ('k') | crypto/encryptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698