summaryrefslogtreecommitdiff
path: root/src/buildtool/crypto/hash_function.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-11-27 16:17:08 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-11-30 14:50:41 +0100
commitcd66c1f47fbfc53d60d37d883c9c709c93e54a36 (patch)
tree40e217771c4b6e90386153395cc7a76989fb979a /src/buildtool/crypto/hash_function.hpp
parent28cf2a52413df40263c2a073287debaf8ccadd1a (diff)
downloadjustbuild-cd66c1f47fbfc53d60d37d883c9c709c93e54a36.tar.gz
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.
Diffstat (limited to 'src/buildtool/crypto/hash_function.hpp')
-rw-r--r--src/buildtool/crypto/hash_function.hpp8
1 files changed, 8 insertions, 0 deletions
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 <cstdint>
+#include <filesystem>
#include <functional>
#include <optional>
#include <string>
+#include <utility>
#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<std::pair<Hasher::HashDigest, std::uintmax_t>>;
+
/// \brief Compute a tree hash.
[[nodiscard]] static auto ComputeTreeHash(std::string const& data) noexcept
-> Hasher::HashDigest {