summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-11-23 00:46:09 +0000
committerRui Ueyama <ruiu@google.com>2016-11-23 00:46:09 +0000
commit877c26c844713e77e82a43a6c577db287f7bb077 (patch)
tree7f2c913692ab5f9b2f1a9956ab410e869f949aa4 /llvm/unittests/Support
parent2b2bfce5803d1b47325a65d26cf35a5dda47786d (diff)
downloadbcm5719-llvm-877c26c844713e77e82a43a6c577db287f7bb077.tar.gz
bcm5719-llvm-877c26c844713e77e82a43a6c577db287f7bb077.zip
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
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/MD5Test.cpp10
-rw-r--r--llvm/unittests/Support/raw_sha1_ostream_test.cpp7
2 files changed, 17 insertions, 0 deletions
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<uint8_t> Input((const uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26);
+ std::array<uint8_t, 16> 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<uint8_t> Input((const uint8_t *)"Hello World!", 12);
+ std::array<uint8_t, 20> 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) {
OpenPOWER on IntegriCloud