Chromium Code Reviews| Index: crypto/secure_hash_unittest.cc |
| diff --git a/crypto/secure_hash_unittest.cc b/crypto/secure_hash_unittest.cc |
| index 6ac92852162945bf7653a8d070ef96bf62f09e85..38e09b864a0fe218a969936bc2e4808cbd6307e3 100644 |
| --- a/crypto/secure_hash_unittest.cc |
| +++ b/crypto/secure_hash_unittest.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/basictypes.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/pickle.h" |
| #include "crypto/sha2.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -32,3 +33,40 @@ TEST(SecureHashTest, TestUpdate) { |
| for (size_t i = 0; i < crypto::kSHA256Length; i++) |
| EXPECT_EQ(expected3[i], static_cast<int>(output3[i])); |
| } |
| + |
| +// Save the crypto state mid-stream, and create another instance with the |
| +// saved state. Then feed the same data afterwards to both. |
| +// When done, both should have the same hash value. |
| +TEST(SecureHashTest, TestSerialization) { |
| + std::string input1(10001, 'a'); // 'a' repeated 10001 times |
| + std::string input2(10001, 'b'); // 'b' repeated 10001 times |
| + std::string input3(10001, 'c'); // 'c' repeated 10001 times |
| + std::string input4(10001, 'd'); // 'd' repeated 10001 times |
| + std::string input5(10001, 'e'); // 'e' repeated 10001 times |
| + |
| + uint8 output1[crypto::kSHA256Length]; |
| + uint8 output2[crypto::kSHA256Length]; |
| + |
| + scoped_ptr<crypto::SecureHash> ctx1(crypto::SecureHash::Create( |
| + crypto::SecureHash::SHA256)); |
|
Randy Smith (Not in Mondays)
2011/11/18 19:01:47
Don't we want to have a similar test for the SSL h
ahendrickson
2011/11/18 19:47:00
I believe one or the other hash types (NSS or Open
|
| + scoped_ptr<crypto::SecureHash> ctx2(crypto::SecureHash::Create( |
| + crypto::SecureHash::SHA256)); |
| + Pickle pickle; |
| + ctx1->Update(input1.data(), input1.size()); |
| + ctx1->Update(input2.data(), input2.size()); |
| + ctx1->Update(input3.data(), input3.size()); |
| + |
| + EXPECT_TRUE(ctx1->Serialize(&Pickle)); |
| + ctx1->Update(input4.data(), input4.size()); |
| + ctx1->Update(input5.data(), input5.size()); |
| + |
| + ctx1->Finish(output1, sizeof(output1)); |
| + |
| + EXPECT_TRUE(ctx2->Deserialize(&Pickle)); |
| + ctx2->Update(input4.data(), input4.size()); |
| + ctx2->Update(input5.data(), input5.size()); |
| + |
| + ctx2->Finish(output2, sizeof(output2)); |
| + |
| + EXPECT_EQ(0, memcmp(output1, output2, crypto::kSHA256Length)); |
| +} |