From cd66c1f47fbfc53d60d37d883c9c709c93e54a36 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 27 Nov 2023 16:17:08 +0100 Subject: hash_function: support hashing of files Extend our internal hash-function abstraction to support hashing of files. In this way, we can provide a way to compute the hash of a potentially large file without having to fully read it to memory first, while still keeping the details of the used hash function abstracted away. --- src/buildtool/crypto/hash_function.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/buildtool/crypto/hash_function.hpp') diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp index 44341777..fa141ed2 100644 --- a/src/buildtool/crypto/hash_function.hpp +++ b/src/buildtool/crypto/hash_function.hpp @@ -16,9 +16,11 @@ #define INCLUDED_SRC_BUILDTOOL_CRYPTO_HASH_FUNCTION_HPP #include +#include #include #include #include +#include #include "src/buildtool/crypto/hasher.hpp" @@ -53,6 +55,12 @@ class HashFunction { return ComputeTaggedHash(data, kBlobTagCreator); } + /// \brief Compute the blob hash of a file or std::nullopt on IO error. + [[nodiscard]] static auto ComputeHashFile( + const std::filesystem::path& file_path, + bool as_tree) noexcept + -> std::optional>; + /// \brief Compute a tree hash. [[nodiscard]] static auto ComputeTreeHash(std::string const& data) noexcept -> Hasher::HashDigest { -- cgit v1.2.3