diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
commit | 22f4d33bcebf81de0287c59b6d14faa68fad212b (patch) | |
tree | 3939c1be732ed03c32fcef6a94f16f3fb331341f /src | |
parent | 3a845bdff676a73f3fb6cbe2c515079b23164ec5 (diff) | |
download | justbuild-22f4d33bcebf81de0287c59b6d14faa68fad212b.tar.gz |
HashGenerator: Add global function for obtaining digest
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/crypto/hash_generator.hpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/buildtool/crypto/hash_generator.hpp b/src/buildtool/crypto/hash_generator.hpp index 79d744fc..dc720912 100644 --- a/src/buildtool/crypto/hash_generator.hpp +++ b/src/buildtool/crypto/hash_generator.hpp @@ -42,10 +42,14 @@ class HashGenerator { public: /// \brief Get pointer to raw bytes of digest. /// Length can be obtained using \ref Length. - [[nodiscard]] auto Bytes() const -> std::string const& { + [[nodiscard]] auto Bytes() const& -> std::string const& { return bytes_; } + [[nodiscard]] auto Bytes() && -> std::string { + return std::move(bytes_); + } + /// \brief Get hexadecimal string of digest. /// Length is twice the length of raw bytes (\ref Length). [[nodiscard]] auto HexString() const -> std::string { @@ -133,10 +137,15 @@ class HashGenerator { } }; +[[nodiscard]] static inline auto ComputeHashDigest( + std::string const& data) noexcept -> HashGenerator::HashDigest { + return HashGenerator::Instance().Run(data); +} + /// \brief Hash function used for the entire buildtool -[[maybe_unused]] [[nodiscard]] static inline auto ComputeHash( - std::string const& data) noexcept -> std::string { - return HashGenerator::Instance().Run(data).HexString(); +[[nodiscard]] static inline auto ComputeHash(std::string const& data) noexcept + -> std::string { + return ComputeHashDigest(data).HexString(); } #endif // INCLUDED_SRC_BUILDTOOL_CRYPTO_HASH_GENERATOR_HPP |