From 855affd9b681d98f248009ddb2c1abe987029f72 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 15 Jun 2022 18:51:47 +0200 Subject: 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. --- src/buildtool/crypto/hash_impl_git.cpp | 42 ---------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/buildtool/crypto/hash_impl_git.cpp (limited to 'src/buildtool/crypto/hash_impl_git.cpp') diff --git a/src/buildtool/crypto/hash_impl_git.cpp b/src/buildtool/crypto/hash_impl_git.cpp deleted file mode 100644 index 9cb2a761..00000000 --- a/src/buildtool/crypto/hash_impl_git.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include "openssl/sha.h" -#include "src/buildtool/crypto/hash_impl.hpp" - -/// \brief Hash implementation for Git blob ids. -/// Does not support incremental hashing. -class HashImplGit final : public IHashImpl { - public: - auto Update(std::string const& /*data*/) noexcept -> bool final { - return false; - } - - auto Finalize() && noexcept -> std::optional final { - return std::nullopt; - } - - auto Compute(std::string const& data) && noexcept -> std::string final { - SHA_CTX ctx; - std::string const header{"blob " + std::to_string(data.size()) + '\0'}; - if (SHA1_Init(&ctx) == 1 && - SHA1_Update(&ctx, header.data(), header.size()) == 1 && - SHA1_Update(&ctx, data.data(), data.size()) == 1) { - auto out = std::array{}; - if (SHA1_Final(out.data(), &ctx) == 1) { - return std::string{out.begin(), out.end()}; - } - } - FatalError(); - return {}; - } - - [[nodiscard]] auto DigestLength() const noexcept -> std::size_t final { - return SHA_DIGEST_LENGTH; - } -}; - -/// \brief Factory for Git implementation -auto CreateHashImplGit() -> std::unique_ptr { - return std::make_unique(); -} -- cgit v1.2.3