From ec349328e034f66e67a4ec27b9155b74b06ba27c Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 27 Jul 2020 16:54:19 -0700 Subject: chore(3p/nix/hash): add decoding tests Change-Id: Ifbeaf1822fa920f929482510ee79a5b24d7976ae Reviewed-on: https://cl.tvl.fyi/c/depot/+/1485 Tested-by: BuildkiteCI Reviewed-by: tazjin --- third_party/nix/src/tests/hash_test.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'third_party') diff --git a/third_party/nix/src/tests/hash_test.cc b/third_party/nix/src/tests/hash_test.cc index c56fa937574b..2ed4dca3bd44 100644 --- a/third_party/nix/src/tests/hash_test.cc +++ b/third_party/nix/src/tests/hash_test.cc @@ -21,4 +21,23 @@ TEST(HASH_TEST, SHA256) { "sha256:LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564="); } +TEST(HashTest, SHA256Decode) { + auto hash = hashString(HashType::htSHA256, "foo"); + + std::unique_ptr base16 = std::make_unique( + "sha256:" + "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", + HashType::htSHA256); + std::unique_ptr base32 = std::make_unique( + "sha256:1bp7cri8hplaz6hbz0v4f0nl44rl84q1sg25kgwqzipzd1mv89ic", + HashType::htSHA256); + std::unique_ptr base64 = std::make_unique( + "sha256:LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=", + HashType::htSHA256); + + ASSERT_EQ(hash, *base16); + ASSERT_EQ(hash, *base32); + ASSERT_EQ(hash, *base64); +} + } // namespace nix -- cgit 1.4.1