summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorDeniz Bahadir <deniz@code.bahadir.email>2024-04-30 16:36:24 (GMT)
committerDeniz Bahadir <deniz@code.bahadir.email>2024-04-30 16:36:24 (GMT)
commit5fa5bde5d63c9a5303461d038a4ab55b1bb76b51 (patch)
tree5055c53406624437551ff069246dbef7b056654c /Source
parent0ccc9f519dc00891fadb9e9189a652013b7c30e2 (diff)
downloadCMake-5fa5bde5d63c9a5303461d038a4ab55b1bb76b51.zip
CMake-5fa5bde5d63c9a5303461d038a4ab55b1bb76b51.tar.gz
CMake-5fa5bde5d63c9a5303461d038a4ab55b1bb76b51.tar.bz2
cmCryptoHash: Add function which gets the hash type name
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCryptoHash.cxx33
-rw-r--r--Source/cmCryptoHash.h4
2 files changed, 37 insertions, 0 deletions
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index ff9ab0f..55e3a5b 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCryptoHash.h"
+#include <cassert>
+
#include <cm/memory>
#include <cm3p/kwiml/int.h>
@@ -80,6 +82,37 @@ std::unique_ptr<cmCryptoHash> cmCryptoHash::New(cm::string_view algo)
return std::unique_ptr<cmCryptoHash>(nullptr);
}
+std::string cmCryptoHash::GetHashAlgoName() const
+{
+#ifndef CMAKE_USE_SYSTEM_LIBRHASH
+ static_assert(RHASH_HASH_COUNT == 10, "Update switch statement!");
+#endif
+ switch (this->Id) {
+ case RHASH_MD5:
+ return "MD5";
+ case RHASH_SHA1:
+ return "SHA1";
+ case RHASH_SHA224:
+ return "SHA224";
+ case RHASH_SHA256:
+ return "SHA256";
+ case RHASH_SHA384:
+ return "SHA384";
+ case RHASH_SHA512:
+ return "SHA512";
+ case RHASH_SHA3_224:
+ return "SHA3_224";
+ case RHASH_SHA3_256:
+ return "SHA3_256";
+ case RHASH_SHA3_384:
+ return "SHA3_384";
+ case RHASH_SHA3_512:
+ return "SHA3_512";
+ }
+ assert(false);
+ return "UNKNOWN";
+}
+
bool cmCryptoHash::IntFromHexDigit(char input, char& output)
{
if (input >= '0' && input <= '9') {
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index a2d45e7..bb026a2 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -74,6 +74,10 @@ public:
/// An empty string otherwise.
std::string HashFile(const std::string& file);
+ /// @brief Returns the name of the hash type.
+ /// @return The name of the hash type associated with this hash generator.
+ std::string GetHashAlgoName() const;
+
void Initialize();
void Append(void const*, size_t);
void Append(cm::string_view input);