summaryrefslogtreecommitdiffstats
path: root/base/sha2_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/sha2_unittest.cc')
-rw-r--r--base/sha2_unittest.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/base/sha2_unittest.cc b/base/sha2_unittest.cc
index a6844dd..b0321e8 100644
--- a/base/sha2_unittest.cc
+++ b/base/sha2_unittest.cc
@@ -30,6 +30,25 @@ TEST(Sha256Test, Test1) {
EXPECT_EQ(expected1[i], static_cast<int>(output_truncated1[i]));
}
+TEST(Sha256Test, Test1_String) {
+ // Same as the above, but using the wrapper that returns a std::string.
+ // Example B.1 from FIPS 180-2: one-block message.
+ std::string input1 = "abc";
+ int expected1[] = { 0xba, 0x78, 0x16, 0xbf,
+ 0x8f, 0x01, 0xcf, 0xea,
+ 0x41, 0x41, 0x40, 0xde,
+ 0x5d, 0xae, 0x22, 0x23,
+ 0xb0, 0x03, 0x61, 0xa3,
+ 0x96, 0x17, 0x7a, 0x9c,
+ 0xb4, 0x10, 0xff, 0x61,
+ 0xf2, 0x00, 0x15, 0xad };
+
+ std::string output1 = base::SHA256HashString(input1);
+ ASSERT_EQ(base::SHA256_LENGTH, output1.size());
+ for (size_t i = 0; i < base::SHA256_LENGTH; i++)
+ EXPECT_EQ(expected1[i], static_cast<uint8>(output1[i]));
+}
+
TEST(Sha256Test, Test2) {
// Example B.2 from FIPS 180-2: multi-block message.
std::string input2 =