Chromium Code Reviews| Index: crypto/signature_creator_unittest.cc |
| diff --git a/crypto/signature_creator_unittest.cc b/crypto/signature_creator_unittest.cc |
| index 2d69223f748a51c3df3b3a8eae5a42799f35ed50..e77e79c4485669d7f9d6284c3fa62f857aabdcf6 100644 |
| --- a/crypto/signature_creator_unittest.cc |
| +++ b/crypto/signature_creator_unittest.cc |
| @@ -5,11 +5,23 @@ |
| #include <vector> |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/sha1.h" |
| #include "crypto/rsa_private_key.h" |
| #include "crypto/signature_creator.h" |
| #include "crypto/signature_verifier.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +namespace { |
| + |
| +// This is the algorithm ID for SHA-1 with RSA encryption. |
| +// TODO(aa): Factor this out into some shared location. |
|
Ryan Sleevi
2013/07/08 21:56:20
comment nit: remove the TODO. Ain't gonna happen a
pfeldman
2013/07/09 05:21:07
Done.
|
| +const uint8 kSHA1WithRSAAlgorithmID[] = { |
| + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
| + 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00 |
| +}; |
| + |
| +} |
| + |
| TEST(SignatureCreatorTest, BasicTest) { |
| // Do a verify round trip. |
| scoped_ptr<crypto::RSAPrivateKey> key_original( |
| @@ -36,12 +48,43 @@ TEST(SignatureCreatorTest, BasicTest) { |
| std::vector<uint8> public_key_info; |
| ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); |
| - // This is the algorithm ID for SHA-1 with RSA encryption. |
| - // TODO(aa): Factor this out into some shared location. |
| - const uint8 kSHA1WithRSAAlgorithmID[] = { |
| - 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
| - 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00 |
| - }; |
| + crypto::SignatureVerifier verifier; |
| + ASSERT_TRUE(verifier.VerifyInit( |
| + kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), |
| + &signature.front(), signature.size(), |
| + &public_key_info.front(), public_key_info.size())); |
| + |
| + verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
| + data.size()); |
| + ASSERT_TRUE(verifier.VerifyFinal()); |
| +} |
| + |
| +TEST(SignatureCreatorTest, SignDigestTest) { |
| + // Do a verify round trip. |
| + scoped_ptr<crypto::RSAPrivateKey> key_original( |
| + crypto::RSAPrivateKey::Create(1024)); |
| + ASSERT_TRUE(key_original.get()); |
| + |
| + std::vector<uint8> key_info; |
| + key_original->ExportPrivateKey(&key_info); |
| + scoped_ptr<crypto::RSAPrivateKey> key( |
| + crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); |
| + ASSERT_TRUE(key.get()); |
| + |
| + std::string data("Hello, World!"); |
| + std::string sha1 = base::SHA1HashString(data); |
| + // Sign sha1 of the input data. |
| + std::vector<uint8> signature; |
| + ASSERT_TRUE(crypto::SignatureCreator::Sign( |
| + key.get(), |
| + reinterpret_cast<const uint8*>(sha1.c_str()), |
| + sha1.size(), |
| + &signature)); |
|
Ryan Sleevi
2013/07/08 21:57:25
style nit: I think it's only four spaces indent he
pfeldman
2013/07/09 05:21:07
Done.
|
| + |
| + std::vector<uint8> public_key_info; |
| + ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); |
| + |
| + // Verify the input data. |
| crypto::SignatureVerifier verifier; |
| ASSERT_TRUE(verifier.VerifyInit( |
| kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), |