//////////////////////////////////////////////////////////////////////////////// // Copyright 2016 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// #include "common/sha_util.h" #include "testing/gunit.h" #include "absl/strings/escaping.h" namespace widevine { TEST(ShaUtilTest, Sha1Empty) { const uint8_t kExpected[] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09, }; EXPECT_EQ(std::string(kExpected, kExpected + sizeof(kExpected)), Sha1_Hash("")); } TEST(ShaUtilTest, Sha256Empty) { const uint8_t kExpected[] = { 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55, }; EXPECT_EQ(std::string(kExpected, kExpected + sizeof(kExpected)), Sha256_Hash("")); } TEST(ShaUtilTest, Sha1) { const uint8_t kExpected[] = { 0x6b, 0x63, 0xa5, 0xe3, 0x6b, 0xfe, 0x54, 0x19, 0x4e, 0xfe, 0x9f, 0xe0, 0x29, 0x7e, 0xd8, 0x11, 0x0f, 0x10, 0x0d, 0x1d, }; EXPECT_EQ(std::string(kExpected, kExpected + sizeof(kExpected)), Sha1_Hash("random data")); } TEST(ShaUtilTest, Sha256) { const uint8_t kExpected[] = { 0x62, 0x4b, 0x56, 0xb3, 0x38, 0x1b, 0xbc, 0xe0, 0x4f, 0x58, 0x88, 0x83, 0xb4, 0x2f, 0x4e, 0x27, 0xfe, 0xc0, 0x95, 0x56, 0xf8, 0x61, 0xcf, 0x94, 0x49, 0xe6, 0x5f, 0x26, 0xea, 0x70, 0xad, 0x88, }; EXPECT_EQ(std::string(kExpected, kExpected + sizeof(kExpected)), Sha256_Hash("random data")); } TEST(ShaUtilTest, GenerateSha1Uuid) { std::string name_space = absl::HexStringToBytes("4d20ad7dd95bc4b250fae56fb143e774"); std::string name = "some seed value"; EXPECT_EQ("730621a55c675c4086be38e72aefa03e", absl::BytesToHexString(GenerateSha1Uuid(name_space, name))); } } // namespace widevine