diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-16 14:58:55 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-22 17:02:34 +0200 |
commit | ed8e56fa64bec6cb055b3d69022690a8a13d92ff (patch) | |
tree | c86132072b5bfc14df1ea3b70a5a2432b9579e4a /src/buildtool/crypto/hash_function.hpp | |
parent | 8f3a09e42d25f533e9d9a007125a7661cef3b653 (diff) | |
download | justbuild-ed8e56fa64bec6cb055b3d69022690a8a13d92ff.tar.gz |
Convert HashFunction to a regular class
Diffstat (limited to 'src/buildtool/crypto/hash_function.hpp')
-rw-r--r-- | src/buildtool/crypto/hash_function.hpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp index 6932a077..8d932016 100644 --- a/src/buildtool/crypto/hash_function.hpp +++ b/src/buildtool/crypto/hash_function.hpp @@ -33,22 +33,18 @@ class HashFunction { Compatible ///< SHA256 for all hashes. }; - static constexpr auto kDefaultType = JustHash::Native; - - explicit HashFunction(JustHash type) noexcept : type_{type} {} + explicit HashFunction(JustHash type) noexcept : type_{type} { + static_assert( + sizeof(HashFunction) <= sizeof(void*), + "HashFunction is passed and stored by value. If the " + "class is extended so that its size exceeds the size of a pointer, " + "the way how HashFunction is passed and stored must be changed."); + } [[nodiscard]] auto GetHashType() const noexcept -> JustHash { return type_; } - [[nodiscard]] static auto Instance() noexcept -> HashFunction& { - static HashFunction instance{kDefaultType}; - return instance; - } - - /// \brief Set globally used hash type. - void SetHashType(JustHash type) noexcept { type_ = type; } - /// \brief Compute a plain hash. [[nodiscard]] auto ComputeHash(std::string const& data) const noexcept -> Hasher::HashDigest { @@ -92,7 +88,7 @@ class HashFunction { } private: - JustHash type_ = kDefaultType; + JustHash const type_; [[nodiscard]] auto ComputeTaggedHash( std::string const& data, |