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

Side by Side Diff: crypto/signature_creator_unittest.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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
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 <vector> 5 #include <vector>
6 6
7 #include "base/crypto/signature_creator.h"
8 #include "base/crypto/signature_verifier.h"
9 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "crypto/signature_creator.h"
9 #include "crypto/signature_verifier.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 TEST(SignatureCreatorTest, BasicTest) { 12 TEST(SignatureCreatorTest, BasicTest) {
13 // Do a verify round trip. 13 // Do a verify round trip.
14 scoped_ptr<base::RSAPrivateKey> key_original( 14 scoped_ptr<crypto::RSAPrivateKey> key_original(
15 base::RSAPrivateKey::Create(1024)); 15 crypto::RSAPrivateKey::Create(1024));
16 ASSERT_TRUE(key_original.get()); 16 ASSERT_TRUE(key_original.get());
17 17
18 std::vector<uint8> key_info; 18 std::vector<uint8> key_info;
19 key_original->ExportPrivateKey(&key_info); 19 key_original->ExportPrivateKey(&key_info);
20 scoped_ptr<base::RSAPrivateKey> key( 20 scoped_ptr<crypto::RSAPrivateKey> key(
21 base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); 21 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info));
22 ASSERT_TRUE(key.get()); 22 ASSERT_TRUE(key.get());
23 23
24 scoped_ptr<base::SignatureCreator> signer( 24 scoped_ptr<crypto::SignatureCreator> signer(
25 base::SignatureCreator::Create(key.get())); 25 crypto::SignatureCreator::Create(key.get()));
26 ASSERT_TRUE(signer.get()); 26 ASSERT_TRUE(signer.get());
27 27
28 std::string data("Hello, World!"); 28 std::string data("Hello, World!");
29 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()), 29 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()),
30 data.size())); 30 data.size()));
31 31
32 std::vector<uint8> signature; 32 std::vector<uint8> signature;
33 ASSERT_TRUE(signer->Final(&signature)); 33 ASSERT_TRUE(signer->Final(&signature));
34 34
35 std::vector<uint8> public_key_info; 35 std::vector<uint8> public_key_info;
36 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); 36 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info));
37 37
38 // This is the algorithm ID for SHA-1 with RSA encryption. 38 // This is the algorithm ID for SHA-1 with RSA encryption.
39 // TODO(aa): Factor this out into some shared location. 39 // TODO(aa): Factor this out into some shared location.
40 const uint8 kSHA1WithRSAAlgorithmID[] = { 40 const uint8 kSHA1WithRSAAlgorithmID[] = {
41 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 41 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
42 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00 42 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00
43 }; 43 };
44 base::SignatureVerifier verifier; 44 crypto::SignatureVerifier verifier;
45 ASSERT_TRUE(verifier.VerifyInit( 45 ASSERT_TRUE(verifier.VerifyInit(
46 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), 46 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID),
47 &signature.front(), signature.size(), 47 &signature.front(), signature.size(),
48 &public_key_info.front(), public_key_info.size())); 48 &public_key_info.front(), public_key_info.size()));
49 49
50 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), 50 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()),
51 data.size()); 51 data.size());
52 ASSERT_TRUE(verifier.VerifyFinal()); 52 ASSERT_TRUE(verifier.VerifyFinal());
53 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698