From 5fa5bde5d63c9a5303461d038a4ab55b1bb76b51 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Tue, 30 Apr 2024 18:36:24 +0200 Subject: cmCryptoHash: Add function which gets the hash type name --- Source/cmCryptoHash.cxx | 33 +++++++++++++++++++++++++++++++++ Source/cmCryptoHash.h | 4 ++++ 2 files changed, 37 insertions(+) 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 + #include #include @@ -80,6 +82,37 @@ std::unique_ptr cmCryptoHash::New(cm::string_view algo) return std::unique_ptr(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); -- cgit v0.12