summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SHA1.cpp
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/lib/Support/SHA1.cpp
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/lib/Support/SHA1.cpp')
-rw-r--r--llvm/lib/Support/SHA1.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Support/SHA1.cpp b/llvm/lib/Support/SHA1.cpp
index 88c76395ead..016f580ae6d 100644
--- a/llvm/lib/Support/SHA1.cpp
+++ b/llvm/lib/Support/SHA1.cpp
@@ -269,3 +269,13 @@ StringRef SHA1::result() {
// Return pointer to hash (20 characters)
return Hash;
}
+
+std::array<uint8_t, 20> SHA1::hash(ArrayRef<uint8_t> Data) {
+ SHA1 Hash;
+ Hash.update(Data);
+ StringRef S = Hash.final().data();
+
+ std::array<uint8_t, 20> Arr;
+ memcpy(Arr.data(), S.data(), S.size());
+ return Arr;
+}
OpenPOWER on IntegriCloud