| // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "src/lib/crypto_util/hash.h" |
| |
| #include <string> |
| |
| #include <gtest/gtest.h> |
| |
| namespace cobalt::crypto::hash { |
| |
| TEST(HashTest, TestHash) { |
| std::string data = |
| "The algorithms were first published in 2001 in the draft FIPS PUB " |
| "180-2, at which time public review and comments were accepted. In " |
| "August 2002, FIPS PUB 180-2 became the new Secure Hash Standard, " |
| "replacing FIPS PUB 180-1, which was released in April 1995. The updated " |
| "standard included the original SHA-1 algorithm, with updated technical " |
| "notation consistent with that describing the inner workings of the " |
| "SHA-2 family.[9]"; |
| |
| // Hash the data into digest. |
| byte digest[DIGEST_SIZE]; |
| EXPECT_TRUE(Hash(reinterpret_cast<byte*>(&data[0]), data.size(), digest)); |
| |
| // Generate a human-readable string representing the bytes of digest. |
| std::ostringstream stream; |
| stream << std::hex << std::setfill('0'); |
| for (unsigned char ch : digest) { |
| stream << std::setw(2) << static_cast<int>(ch); |
| } |
| |
| // Compare this to an expected result. |
| EXPECT_EQ(std::string("fc11f3cbffea99f65944e50e72e5bfc09674eed67bcebcd76ec0f9dc90faef05"), |
| stream.str()); |
| } |
| |
| } // namespace cobalt::crypto::hash |