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

Side by Side Diff: base/crypto/signature_creator_unittest.cc

Issue 118277: Introduce SignatureCreator. (Closed)
Patch Set: Responses to feedback Created 11 years, 6 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 | « base/crypto/signature_creator.h ('k') | base/crypto/signature_creator_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "base/crypto/signature_creator.h"
8 #include "base/crypto/signature_verifier.h"
9 #include "base/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 TEST(SignatureCreatorTest, BasicTest) {
13 // Do a verify round trip.
14 scoped_ptr<base::RSAPrivateKey> key(base::RSAPrivateKey::Create(1024));
15 ASSERT_TRUE(key.get());
16
17 scoped_ptr<base::SignatureCreator> signer(
18 base::SignatureCreator::Create(key.get()));
19 ASSERT_TRUE(signer.get());
20
21 std::string data("Hello, world!");
22 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()),
23 data.size()));
24
25 std::vector<uint8> signature;
26 ASSERT_TRUE(signer->Final(&signature));
27
28 std::vector<uint8> public_key_info;
29 ASSERT_TRUE(key->ExportPublicKey(&public_key_info));
30
31 // This is the algorithm ID for SHA-1 with RSA encryption.
32 // TODO(aa): Factor this out into some shared location.
33 const uint8 kSHA1WithRSAAlgorithmID[] = {
34 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
35 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00
36 };
37 base::SignatureVerifier verifier;
38 ASSERT_TRUE(verifier.VerifyInit(
39 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID),
40 &signature.front(), signature.size(),
41 &public_key_info.front(), public_key_info.size()));
42 }
43
44 // TODO(aa): Would be nice to test some well-known signatures.
OLDNEW
« no previous file with comments | « base/crypto/signature_creator.h ('k') | base/crypto/signature_creator_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698