diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
commit | 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch) | |
tree | 01868de723cb82c86842f33743fa7b14e24c1fa3 /src/buildtool/crypto/hash_impl.hpp | |
download | justbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz |
Initial self-hosting commit
This is the initial version of our tool that is able to
build itself. In can be bootstrapped by
./bin/bootstrap.py
Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com>
Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'src/buildtool/crypto/hash_impl.hpp')
-rw-r--r-- | src/buildtool/crypto/hash_impl.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/buildtool/crypto/hash_impl.hpp b/src/buildtool/crypto/hash_impl.hpp new file mode 100644 index 00000000..aa5a9559 --- /dev/null +++ b/src/buildtool/crypto/hash_impl.hpp @@ -0,0 +1,40 @@ +#ifndef INCLUDED_SRC_BUILDTOOL_CRYPTO_HASH_IMPL_HPP +#define INCLUDED_SRC_BUILDTOOL_CRYPTO_HASH_IMPL_HPP + +#include <optional> +#include <string> + +#include "src/buildtool/logging/logger.hpp" + +/// \brief Interface for hash implementations +class IHashImpl { + public: + IHashImpl() noexcept = default; + IHashImpl(IHashImpl const&) = default; + IHashImpl(IHashImpl&&) = default; + auto operator=(IHashImpl const&) -> IHashImpl& = default; + auto operator=(IHashImpl &&) -> IHashImpl& = default; + virtual ~IHashImpl() = default; + + /// \brief Feed data to the incremental hashing. + [[nodiscard]] virtual auto Update(std::string const& data) noexcept + -> bool = 0; + + /// \brief Finalize the hashing and return hash as string of raw bytes. + [[nodiscard]] virtual auto Finalize() && noexcept + -> std::optional<std::string> = 0; + + /// \brief Compute the hash of data and return it as string of raw bytes. + [[nodiscard]] virtual auto Compute(std::string const& data) && noexcept + -> std::string = 0; + + /// \brief Get length of the hash in raw bytes. + [[nodiscard]] virtual auto DigestLength() const noexcept -> std::size_t = 0; + + static auto FatalError() noexcept -> void { + Logger::Log(LogLevel::Error, "Failed to compute hash."); + std::terminate(); + } +}; + +#endif // INCLUDED_SRC_BUILDTOOL_CRYPTO_HASH_IMPL_HPP |