diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-15 18:51:47 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-20 15:23:02 +0200 |
commit | 855affd9b681d98f248009ddb2c1abe987029f72 (patch) | |
tree | 6d4dbfc2c99020772313f381d2f793950d2b03f4 /src/buildtool/crypto/hash_function.hpp | |
parent | 391d982f2fbd98a2973f14e0b5969f66c2abd756 (diff) | |
download | justbuild-855affd9b681d98f248009ddb2c1abe987029f72.tar.gz |
Crypto: Refactor hash computation
... by renaming HashGenerator to (incremental) Hasher and
dropping support for Git/MD5 hashes. The Hasher does not
expose the actual hash implementation.
Diffstat (limited to 'src/buildtool/crypto/hash_function.hpp')
-rw-r--r-- | src/buildtool/crypto/hash_function.hpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp index 4030c7a7..734a096d 100644 --- a/src/buildtool/crypto/hash_function.hpp +++ b/src/buildtool/crypto/hash_function.hpp @@ -6,7 +6,7 @@ #include <optional> #include <string> -#include "src/buildtool/crypto/hash_generator.hpp" +#include "src/buildtool/crypto/hasher.hpp" /// \brief Hash function used for the entire buildtool. class HashFunction { @@ -23,13 +23,13 @@ class HashFunction { /// \brief Compute a plain hash. [[nodiscard]] static auto ComputeHash(std::string const& data) noexcept - -> HashGenerator::HashDigest { + -> Hasher::HashDigest { return ComputeTaggedHash(data); } /// \brief Compute a blob hash. [[nodiscard]] static auto ComputeBlobHash(std::string const& data) noexcept - -> HashGenerator::HashDigest { + -> Hasher::HashDigest { static auto const kBlobTagCreator = [](std::string const& data) -> std::string { return {"blob " + std::to_string(data.size()) + '\0'}; @@ -39,7 +39,7 @@ class HashFunction { /// \brief Compute a tree hash. [[nodiscard]] static auto ComputeTreeHash(std::string const& data) noexcept - -> HashGenerator::HashDigest { + -> Hasher::HashDigest { static auto const kTreeTagCreator = [](std::string const& data) -> std::string { return {"tree " + std::to_string(data.size()) + '\0'}; @@ -48,14 +48,12 @@ class HashFunction { } /// \brief Obtain incremental hasher for computing plain hashes. - [[nodiscard]] static auto Hasher() noexcept -> HashGenerator::Hasher { + [[nodiscard]] static auto Hasher() noexcept -> ::Hasher { switch (HashType()) { case JustHash::Native: - return HashGenerator{HashGenerator::HashType::SHA1} - .IncrementalHasher(); + return ::Hasher{Hasher::HashType::SHA1}; case JustHash::Compatible: - return HashGenerator{HashGenerator::HashType::SHA256} - .IncrementalHasher(); + return ::Hasher{Hasher::HashType::SHA256}; } } @@ -74,13 +72,13 @@ class HashFunction { [[nodiscard]] static auto ComputeTaggedHash( std::string const& data, std::function<std::string(std::string const&)> const& tag_creator = - {}) noexcept -> HashGenerator::HashDigest { + {}) noexcept -> Hasher::HashDigest { auto hasher = Hasher(); if (tag_creator and HashType() == JustHash::Native) { hasher.Update(tag_creator(data)); } hasher.Update(data); - return *std::move(hasher).Finalize(); + return std::move(hasher).Finalize(); } }; |