12MakeError(BadHash,
Error);
14enum struct HashAlgorithm :
char { MD5 = 42, SHA1, SHA256, SHA512, BLAKE3 };
22 case HashAlgorithm::BLAKE3:
24 case HashAlgorithm::MD5:
26 case HashAlgorithm::SHA1:
28 case HashAlgorithm::SHA256:
30 case HashAlgorithm::SHA512:
37extern const StringSet hashAlgorithms;
55extern const StringSet hashFormats;
62 constexpr static size_t maxHashSize = 64;
64 uint8_t hash[maxHashSize] = {};
80 static Hash parseAny(std::string_view s, std::optional<HashAlgorithm> optAlgo);
85 static std::pair<Hash, HashFormat>
134 [[nodiscard]] std::string gitRev()
const
139 [[nodiscard]] std::string gitShortRev()
const
155Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashAlgorithm> ha);
168Hash hashFile(HashAlgorithm ha,
const std::filesystem::path & path);
176 uint64_t numBytesDigested;
183Hash compressHash(
const Hash & hash,
unsigned int newSize);
188HashFormat parseHashFormat(std::string_view hashFormatName);
193std::optional<HashFormat> parseHashFormatOpt(std::string_view hashFormatName);
198std::string_view printHashFormat(
HashFormat hashFormat);
209std::optional<HashAlgorithm>
215std::string_view printHashAlgo(HashAlgorithm ha);
220 void anchor()
override;
232 void anchor()
override;
235 HashSink(HashAlgorithm ha);
236 HashSink(
const HashSink & h);
238 void writeUnbuffered(std::string_view data)
override;
244struct json_avoids_null<
Hash> : std::true_type
250struct std::hash<nix::Hash>
252 std::size_t operator()(
const nix::Hash & hash)
const noexcept
254 assert(hash.hashSize >
sizeof(
size_t));
255 return *
reinterpret_cast<const std::size_t *
>(&hash.hash);
261inline std::size_t hash_value(
const Hash & hash)
263 return std::hash<Hash>{}(hash);
Utilities for working with the file system and file paths.
constexpr size_t regularHashSize(HashAlgorithm type)
Definition hash.hh:19
HashFormat
Enumeration representing the hash formats.
Definition hash.hh:42
@ Base16
Lowercase hexadecimal encoding.
Definition hash.hh:49
@ Base64
Base 64 encoding.
Definition hash.hh:45
@ Nix32
Nix-specific base-32 encoding.
Definition hash.hh:47
@ SRI
"<hash algo>:<Base 64 hash>", format of the SRI integrity attribute.
Definition hash.hh:52
Definition configuration.hh:558
static Hash parseAnyPrefixed(std::string_view s)
Definition hash.cc:230
Hash(HashAlgorithm algo, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition hash.cc:35
static Hash random(HashAlgorithm algo)
Definition hash.cc:276
static Hash parseNonSRIUnprefixed(std::string_view s, HashAlgorithm algo)
Definition hash.cc:265
static Hash parseExplicitFormatUnprefixed(std::string_view s, HashAlgorithm algo, HashFormat explicitFormat, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition hash.cc:270
static std::pair< Hash, HashFormat > parseAnyReturningFormat(std::string_view s, std::optional< HashAlgorithm > optAlgo)
Definition hash.cc:251
std::strong_ordering operator<=>(const Hash &h2) const noexcept
Definition hash.cc:56
std::string to_string(HashFormat hashFormat, bool includeAlgo) const
Definition hash.cc:69
bool operator==(const Hash &h2) const noexcept
Definition hash.cc:46
static Hash parseAny(std::string_view s, std::optional< HashAlgorithm > optAlgo)
Definition hash.cc:245
Definition serialise.hh:18