summaryrefslogtreecommitdiffstats
path: root/Source/cmCryptoHash.cxx
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2016-08-10 08:35:19 (GMT)
committerBrad King <brad.king@kitware.com>2016-08-10 17:09:55 (GMT)
commit74f0d4abcd8de84283858fe144772e688669e46a (patch)
treefedbfac78b8cf4af4e6c7eeb0500637ebfd4d32a /Source/cmCryptoHash.cxx
parent94c29976d0020b48a5c565234b71f8f6abaf08be (diff)
downloadCMake-74f0d4abcd8de84283858fe144772e688669e46a.zip
CMake-74f0d4abcd8de84283858fe144772e688669e46a.tar.gz
CMake-74f0d4abcd8de84283858fe144772e688669e46a.tar.bz2
cmCryptoHash: New byte hash to string function
Diffstat (limited to 'Source/cmCryptoHash.cxx')
-rw-r--r--Source/cmCryptoHash.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 8d60c1f..59b9abd 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -34,6 +34,37 @@ CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
}
}
+bool cmCryptoHash::IntFromHexDigit(char input, char& output)
+{
+ if (input >= '0' && input <= '9') {
+ output = char(input - '0');
+ return true;
+ } else if (input >= 'a' && input <= 'f') {
+ output = char(input - 'a' + 0xA);
+ return true;
+ } else if (input >= 'A' && input <= 'F') {
+ output = char(input - 'A' + 0xA);
+ return true;
+ }
+ return false;
+}
+
+std::string cmCryptoHash::ByteHashToString(
+ const std::vector<unsigned char>& hash)
+{
+ // Map from 4-bit index to hexadecimal representation.
+ static char const hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+ std::string res;
+ for (std::vector<unsigned char>::const_iterator vit = hash.begin();
+ vit != hash.end(); ++vit) {
+ res.push_back(hex[(*vit) >> 4]);
+ res.push_back(hex[(*vit) & 0xF]);
+ }
+ return res;
+}
+
std::string cmCryptoHash::HashString(const std::string& input)
{
this->Initialize();