From 877c26c844713e77e82a43a6c577db287f7bb077 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 23 Nov 2016 00:46:09 +0000 Subject: Add convenient functions to compute hashes of byte vectors. In many sitautions, you just want to compute a hash for one chunk of data. This patch adds convenient functions for that purpose. Differential Revision: https://reviews.llvm.org/D26988 llvm-svn: 287726 --- llvm/unittests/Support/MD5Test.cpp | 10 ++++++++++ llvm/unittests/Support/raw_sha1_ostream_test.cpp | 7 +++++++ 2 files changed, 17 insertions(+) (limited to 'llvm/unittests/Support') diff --git a/llvm/unittests/Support/MD5Test.cpp b/llvm/unittests/Support/MD5Test.cpp index c4fa5cd92c1..4d790254503 100644 --- a/llvm/unittests/Support/MD5Test.cpp +++ b/llvm/unittests/Support/MD5Test.cpp @@ -57,4 +57,14 @@ TEST(MD5Test, MD5) { "81948d1f1554f58cd1a56ebb01f808cb"); TestMD5Sum("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"); } + +TEST(MD5HashTest, MD5) { + ArrayRef Input((const uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26); + std::array Vec = MD5::hash(Input); + MD5::MD5Result MD5Res; + SmallString<32> Res; + memcpy(MD5Res, Vec.data(), Vec.size()); + MD5::stringifyResult(MD5Res, Res); + EXPECT_EQ(Res, "c3fcd3d76192e4007dfb496cca67e13b"); +} } diff --git a/llvm/unittests/Support/raw_sha1_ostream_test.cpp b/llvm/unittests/Support/raw_sha1_ostream_test.cpp index db2a3e9ab64..1bb4e2eb1d5 100644 --- a/llvm/unittests/Support/raw_sha1_ostream_test.cpp +++ b/llvm/unittests/Support/raw_sha1_ostream_test.cpp @@ -37,6 +37,13 @@ TEST(raw_sha1_ostreamTest, Basic) { ASSERT_EQ("2EF7BDE608CE5404E97D5F042F95F89F1C232871", Hash); } +TEST(sha1_hash_test, Basic) { + ArrayRef Input((const uint8_t *)"Hello World!", 12); + std::array Vec = SHA1::hash(Input); + std::string Hash = toHex({(const char *)Vec.data(), 20}); + ASSERT_EQ("2EF7BDE608CE5404E97D5F042F95F89F1C232871", Hash); +} + // Check that getting the intermediate hash in the middle of the stream does // not invalidate the final result. TEST(raw_sha1_ostreamTest, Intermediate) { -- cgit v1.2.3