summaryrefslogtreecommitdiff
path: root/src/buildtool/crypto/hasher.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/crypto/hasher.hpp')
-rw-r--r--src/buildtool/crypto/hasher.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/buildtool/crypto/hasher.hpp b/src/buildtool/crypto/hasher.hpp
index 4bbcc7b7..a926fab1 100644
--- a/src/buildtool/crypto/hasher.hpp
+++ b/src/buildtool/crypto/hasher.hpp
@@ -17,6 +17,7 @@
#include <cstddef>
#include <cstdint>
+#include <limits>
#include <memory>
#include <optional>
#include <string>
@@ -69,6 +70,10 @@ class Hasher {
/// \brief Interface for hash implementations
class IHashImpl {
public:
+ static constexpr size_t kCharsPerNumber =
+ std::numeric_limits<std::uint8_t>::max() /
+ std::numeric_limits<signed char>::max();
+
IHashImpl() noexcept = default;
IHashImpl(IHashImpl const&) = delete;
IHashImpl(IHashImpl&&) = default;
@@ -89,6 +94,9 @@ class Hasher {
[[nodiscard]] virtual auto Compute(std::string const& data) && noexcept
-> std::string = 0;
+ /// \brief Obtain length of the resulting hash string.
+ [[nodiscard]] virtual auto GetHashLength() const noexcept -> size_t = 0;
+
static auto FatalError() noexcept -> void {
Logger::Log(LogLevel::Error, "Failed to compute hash.");
std::terminate();
@@ -111,6 +119,11 @@ class Hasher {
return HashDigest{{}};
}
+ /// \brief Obtain length of the resulting hash string.
+ [[nodiscard]] auto GetHashLength() const noexcept -> size_t {
+ return impl_->GetHashLength();
+ }
+
private:
std::unique_ptr<IHashImpl> impl_;