Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: crypto/secure_hash_unittest.cc

Issue 8588057: Added serialization to SecureHash. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added iterator to Deserialize, applied comments from agl. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/secure_hash_openssl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/secure_hash_unittest.cc
diff --git a/crypto/secure_hash_unittest.cc b/crypto/secure_hash_unittest.cc
index 6ac92852162945bf7653a8d070ef96bf62f09e85..2adddfb98ebcabaf52c927b5b9654279e6801ae7 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,41 @@ 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));
+ 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));
+
+ void* data_iterator = NULL;
+ EXPECT_TRUE(ctx2->Deserialize(&data_iterator, &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));
+}
« no previous file with comments | « crypto/secure_hash_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698