OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "crypto/secure_hash.h" | 5 #include "crypto/secure_hash.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 std::string input4(10001, 'd'); // 'd' repeated 10001 times | 46 std::string input4(10001, 'd'); // 'd' repeated 10001 times |
47 std::string input5(10001, 'e'); // 'e' repeated 10001 times | 47 std::string input5(10001, 'e'); // 'e' repeated 10001 times |
48 | 48 |
49 uint8 output1[crypto::kSHA256Length]; | 49 uint8 output1[crypto::kSHA256Length]; |
50 uint8 output2[crypto::kSHA256Length]; | 50 uint8 output2[crypto::kSHA256Length]; |
51 | 51 |
52 scoped_ptr<crypto::SecureHash> ctx1(crypto::SecureHash::Create( | 52 scoped_ptr<crypto::SecureHash> ctx1(crypto::SecureHash::Create( |
53 crypto::SecureHash::SHA256)); | 53 crypto::SecureHash::SHA256)); |
54 scoped_ptr<crypto::SecureHash> ctx2(crypto::SecureHash::Create( | 54 scoped_ptr<crypto::SecureHash> ctx2(crypto::SecureHash::Create( |
55 crypto::SecureHash::SHA256)); | 55 crypto::SecureHash::SHA256)); |
56 Pickle pickle; | 56 base::Pickle pickle; |
57 ctx1->Update(input1.data(), input1.size()); | 57 ctx1->Update(input1.data(), input1.size()); |
58 ctx1->Update(input2.data(), input2.size()); | 58 ctx1->Update(input2.data(), input2.size()); |
59 ctx1->Update(input3.data(), input3.size()); | 59 ctx1->Update(input3.data(), input3.size()); |
60 | 60 |
61 EXPECT_TRUE(ctx1->Serialize(&pickle)); | 61 EXPECT_TRUE(ctx1->Serialize(&pickle)); |
62 ctx1->Update(input4.data(), input4.size()); | 62 ctx1->Update(input4.data(), input4.size()); |
63 ctx1->Update(input5.data(), input5.size()); | 63 ctx1->Update(input5.data(), input5.size()); |
64 | 64 |
65 ctx1->Finish(output1, sizeof(output1)); | 65 ctx1->Finish(output1, sizeof(output1)); |
66 | 66 |
67 PickleIterator data_iterator(pickle); | 67 base::PickleIterator data_iterator(pickle); |
68 EXPECT_TRUE(ctx2->Deserialize(&data_iterator)); | 68 EXPECT_TRUE(ctx2->Deserialize(&data_iterator)); |
69 ctx2->Update(input4.data(), input4.size()); | 69 ctx2->Update(input4.data(), input4.size()); |
70 ctx2->Update(input5.data(), input5.size()); | 70 ctx2->Update(input5.data(), input5.size()); |
71 | 71 |
72 ctx2->Finish(output2, sizeof(output2)); | 72 ctx2->Finish(output2, sizeof(output2)); |
73 | 73 |
74 EXPECT_EQ(0, memcmp(output1, output2, crypto::kSHA256Length)); | 74 EXPECT_EQ(0, memcmp(output1, output2, crypto::kSHA256Length)); |
75 } | 75 } |
OLD | NEW |