summaryrefslogtreecommitdiff
path: root/src/buildtool/crypto/hash_impl_md5.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-06-15 18:51:47 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2022-06-20 15:23:02 +0200
commit855affd9b681d98f248009ddb2c1abe987029f72 (patch)
tree6d4dbfc2c99020772313f381d2f793950d2b03f4 /src/buildtool/crypto/hash_impl_md5.cpp
parent391d982f2fbd98a2973f14e0b5969f66c2abd756 (diff)
downloadjustbuild-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_impl_md5.cpp')
-rw-r--r--src/buildtool/crypto/hash_impl_md5.cpp50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/buildtool/crypto/hash_impl_md5.cpp b/src/buildtool/crypto/hash_impl_md5.cpp
deleted file mode 100644
index 106dc984..00000000
--- a/src/buildtool/crypto/hash_impl_md5.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <array>
-#include <cstdint>
-
-#include "openssl/md5.h"
-#include "src/buildtool/crypto/hash_impl.hpp"
-
-/// \brief Hash implementation for MD5
-class HashImplMd5 final : public IHashImpl {
- public:
- HashImplMd5() { initialized_ = MD5_Init(&ctx_) == 1; }
-
- auto Update(std::string const& data) noexcept -> bool final {
- return initialized_ and
- MD5_Update(&ctx_, data.data(), data.size()) == 1;
- }
-
- auto Finalize() && noexcept -> std::optional<std::string> final {
- if (initialized_) {
- auto out = std::array<std::uint8_t, MD5_DIGEST_LENGTH>{};
- if (MD5_Final(out.data(), &ctx_) == 1) {
- return std::string{out.begin(), out.end()};
- }
- }
- return std::nullopt;
- }
-
- auto Compute(std::string const& data) && noexcept -> std::string final {
- if (Update(data)) {
- auto digest = std::move(*this).Finalize();
- if (digest) {
- return *digest;
- }
- }
- FatalError();
- return {};
- }
-
- [[nodiscard]] auto DigestLength() const noexcept -> std::size_t final {
- return MD5_DIGEST_LENGTH;
- }
-
- private:
- MD5_CTX ctx_{};
- bool initialized_{};
-};
-
-/// \brief Factory for MD5 implementation
-auto CreateHashImplMd5() -> std::unique_ptr<IHashImpl> {
- return std::make_unique<HashImplMd5>();
-}