summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/artifact_digest_factory.cpp14
-rw-r--r--src/buildtool/common/artifact_digest_factory.hpp13
2 files changed, 27 insertions, 0 deletions
diff --git a/src/buildtool/common/artifact_digest_factory.cpp b/src/buildtool/common/artifact_digest_factory.cpp
index 05bfd031..0f95f444 100644
--- a/src/buildtool/common/artifact_digest_factory.cpp
+++ b/src/buildtool/common/artifact_digest_factory.cpp
@@ -19,6 +19,20 @@
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
+auto ArtifactDigestFactory::Create(HashFunction::Type hash_type,
+ std::string hash,
+ std::size_t size,
+ bool is_tree) noexcept
+ -> expected<ArtifactDigest, std::string> {
+ const bool kTreesAllowed = hash_type == HashFunction::Type::GitSHA1;
+ auto hash_info =
+ HashInfo::Create(hash_type, std::move(hash), kTreesAllowed and is_tree);
+ if (not hash_info) {
+ return unexpected{std::move(hash_info).error()};
+ }
+ return ArtifactDigest{*hash_info, size};
+}
+
auto ArtifactDigestFactory::FromBazel(HashFunction::Type hash_type,
bazel_re::Digest const& digest) noexcept
-> expected<ArtifactDigest, std::string> {
diff --git a/src/buildtool/common/artifact_digest_factory.hpp b/src/buildtool/common/artifact_digest_factory.hpp
index 09c0b478..8e28ae83 100644
--- a/src/buildtool/common/artifact_digest_factory.hpp
+++ b/src/buildtool/common/artifact_digest_factory.hpp
@@ -34,6 +34,19 @@ namespace bazel_re = build::bazel::remote::execution::v2;
class ArtifactDigestFactory final {
public:
+ /// \brief Create ArtifactDigest from plain hash.
+ /// \param hash_type Type of the hash function that was used for creation
+ /// of the hash
+ /// \param hash Hexadecimal plain hash
+ /// \param size Size of the content
+ /// \return A valid ArtifactDigest on success or an error message if
+ /// validation fails.
+ [[nodiscard]] static auto Create(HashFunction::Type hash_type,
+ std::string hash,
+ std::size_t size,
+ bool is_tree) noexcept
+ -> expected<ArtifactDigest, std::string>;
+
/// \brief Create ArtifactDigest from bazel_re::Digest
/// \param hash_type Type of the hash function that was used for creation of
/// the hash