OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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" | 7 #include "base/crypto/signature_creator.h" |
8 #include "base/crypto/signature_verifier.h" | 8 #include "base/crypto/signature_verifier.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.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<base::RSAPrivateKey> key_original( |
15 base::RSAPrivateKey::Create(1024)); | 15 base::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<base::RSAPrivateKey> key( |
21 base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); | 21 base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); |
| 22 ASSERT_TRUE(key.get()); |
22 | 23 |
23 scoped_ptr<base::SignatureCreator> signer( | 24 scoped_ptr<base::SignatureCreator> signer( |
24 base::SignatureCreator::Create(key.get())); | 25 base::SignatureCreator::Create(key.get())); |
25 ASSERT_TRUE(signer.get()); | 26 ASSERT_TRUE(signer.get()); |
26 | 27 |
27 std::string data("Hello, World!"); | 28 std::string data("Hello, World!"); |
28 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()), | 29 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()), |
29 data.size())); | 30 data.size())); |
30 | 31 |
31 std::vector<uint8> signature; | 32 std::vector<uint8> signature; |
(...skipping 11 matching lines...) Expand all Loading... |
43 base::SignatureVerifier verifier; | 44 base::SignatureVerifier verifier; |
44 ASSERT_TRUE(verifier.VerifyInit( | 45 ASSERT_TRUE(verifier.VerifyInit( |
45 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), | 46 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), |
46 &signature.front(), signature.size(), | 47 &signature.front(), signature.size(), |
47 &public_key_info.front(), public_key_info.size())); | 48 &public_key_info.front(), public_key_info.size())); |
48 | 49 |
49 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 50 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
50 data.size()); | 51 data.size()); |
51 ASSERT_TRUE(verifier.VerifyFinal()); | 52 ASSERT_TRUE(verifier.VerifyFinal()); |
52 } | 53 } |
OLD | NEW |