| Index: crypto/secure_hash_unittest.cc
|
| diff --git a/crypto/secure_hash_unittest.cc b/crypto/secure_hash_unittest.cc
|
| index df0afa6248a3340b9586f77cc1c90d0848fbf213..0fab17b6b6a221c3b5b69767d59252cab53f7d8d 100644
|
| --- a/crypto/secure_hash_unittest.cc
|
| +++ b/crypto/secure_hash_unittest.cc
|
| @@ -10,7 +10,6 @@
|
| #include <string>
|
|
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/pickle.h"
|
| #include "crypto/sha2.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -38,40 +37,53 @@ TEST(SecureHashTest, TestUpdate) {
|
| 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) {
|
| +TEST(SecureHashTest, TestClone) {
|
| 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
|
| + std::string input2(10001, 'd'); // 'd' repeated 10001 times
|
| +
|
| + uint8_t expected_sha256_hash_of_input1[crypto::kSHA256Length] = {
|
| + 0x0c, 0xab, 0x99, 0xa0, 0x58, 0x60, 0x0f, 0xfa, 0xad, 0x12, 0x92,
|
| + 0xd0, 0xc5, 0x3c, 0x05, 0x48, 0xeb, 0xaf, 0x88, 0xdd, 0x1d, 0x01,
|
| + 0x03, 0x03, 0x45, 0x70, 0x5f, 0x01, 0x8a, 0x81, 0x39, 0x09
|
| + };
|
| + uint8_t expected_sha256_hash_of_inputs1and2[crypto::kSHA256Length] = {
|
| + 0x4c, 0x8e, 0x26, 0x5a, 0xc3, 0x85, 0x1f, 0x1f, 0xa5, 0x04, 0x1c,
|
| + 0xc7, 0x88, 0x53, 0x1c, 0xc7, 0x80, 0x47, 0x15, 0xfb, 0x47, 0xff,
|
| + 0x72, 0xb1, 0x28, 0x37, 0xb0, 0x4d, 0x6e, 0x22, 0x2e, 0x4d
|
| + };
|
|
|
| uint8_t output1[crypto::kSHA256Length];
|
| uint8_t output2[crypto::kSHA256Length];
|
| + uint8_t output3[crypto::kSHA256Length];
|
|
|
| scoped_ptr<crypto::SecureHash> ctx1(crypto::SecureHash::Create(
|
| crypto::SecureHash::SHA256));
|
| - scoped_ptr<crypto::SecureHash> ctx2(crypto::SecureHash::Create(
|
| - crypto::SecureHash::SHA256));
|
| - base::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());
|
| + scoped_ptr<crypto::SecureHash> ctx2(ctx1->Clone());
|
| + scoped_ptr<crypto::SecureHash> ctx3(ctx2->Clone());
|
| + // At this point, ctx1, ctx2, and ctx3 are all equivalent and represent the
|
| + // state after hashing input1.
|
|
|
| + // Updating ctx1 and ctx2 with input2 should produce equivalent results.
|
| + ctx1->Update(input2.data(), input2.size());
|
| ctx1->Finish(output1, sizeof(output1));
|
|
|
| - base::PickleIterator data_iterator(pickle);
|
| - EXPECT_TRUE(ctx2->Deserialize(&data_iterator));
|
| - ctx2->Update(input4.data(), input4.size());
|
| - ctx2->Update(input5.data(), input5.size());
|
| -
|
| + ctx2->Update(input2.data(), input2.size());
|
| ctx2->Finish(output2, sizeof(output2));
|
|
|
| EXPECT_EQ(0, memcmp(output1, output2, crypto::kSHA256Length));
|
| + EXPECT_EQ(0, memcmp(output1, expected_sha256_hash_of_inputs1and2,
|
| + crypto::kSHA256Length));
|
| +
|
| + // Finish() ctx3, which should produce the hash of input1.
|
| + ctx3->Finish(&output3, sizeof(output3));
|
| + EXPECT_EQ(0, memcmp(output3, expected_sha256_hash_of_input1,
|
| + crypto::kSHA256Length));
|
| +}
|
| +
|
| +TEST(SecureHashTest, TestLength) {
|
| + scoped_ptr<crypto::SecureHash> ctx(
|
| + crypto::SecureHash::Create(crypto::SecureHash::SHA256));
|
| + EXPECT_EQ(crypto::kSHA256Length, ctx->GetHashLength());
|
| }
|
|
|