Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Hash Struct Reference

Classes

union  Ctx

Public Member Functions

 Hash (HashAlgorithm algo, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
bool operator== (const Hash &h2) const noexcept
std::strong_ordering operator<=> (const Hash &h2) const noexcept
std::string to_string (HashFormat hashFormat, bool includeAlgo) const
std::string gitRev () const
std::string gitShortRev () const

Static Public Member Functions

static Hash parseAny (std::string_view s, std::optional< HashAlgorithm > optAlgo)
static std::pair< Hash, HashFormat > parseAnyReturningFormat (std::string_view s, std::optional< HashAlgorithm > optAlgo)
static Hash parseAnyPrefixed (std::string_view s)
static Hash parseNonSRIUnprefixed (std::string_view s, HashAlgorithm algo)
static Hash parseExplicitFormatUnprefixed (std::string_view s, HashAlgorithm algo, HashFormat explicitFormat, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
static Hash parseSRI (std::string_view original, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
static Hash random (HashAlgorithm algo)

Public Attributes

size_t hashSize = 0
uint8_t hash [maxHashSize] = {}
HashAlgorithm algo

Static Public Attributes

static constexpr size_t maxHashSize = 64
static Hash dummy

Constructor & Destructor Documentation

◆ Hash()

nix::Hash::Hash ( HashAlgorithm algo,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings )
explicit

Create a zero-filled hash object.

Member Function Documentation

◆ operator<=>()

std::strong_ordering nix::Hash::operator<=> ( const Hash & h2) const
noexcept

Compare how two hashes are ordered.

◆ operator==()

bool nix::Hash::operator== ( const Hash & h2) const
noexcept

Check whether two hashes are equal.

◆ parseAny()

Hash nix::Hash::parseAny ( std::string_view s,
std::optional< HashAlgorithm > optAlgo )
static

Parse the hash from a string representation in the format "[<type>:]<base16|base32|base64>" or "<type>-<base64>" (a Subresource Integrity hash expression). If the 'type' argument is not present, then the hash algorithm must be specified in the string.

◆ parseAnyPrefixed()

Hash nix::Hash::parseAnyPrefixed ( std::string_view s)
static

Parse a hash from a string representation like the above, except the type prefix is mandatory is there is no separate argument.

◆ parseAnyReturningFormat()

std::pair< Hash, HashFormat > nix::Hash::parseAnyReturningFormat ( std::string_view s,
std::optional< HashAlgorithm > optAlgo )
static

Like parseAny, but also returns the format the hash was parsed from.

◆ parseExplicitFormatUnprefixed()

Hash nix::Hash::parseExplicitFormatUnprefixed ( std::string_view s,
HashAlgorithm algo,
HashFormat explicitFormat,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings )
static

Like parseNonSRIUnprefixed, but the hash format has been explicitly given.

Parameters
explicitFormatcannot be SRI, but must be one of the "bases".

◆ parseNonSRIUnprefixed()

Hash nix::Hash::parseNonSRIUnprefixed ( std::string_view s,
HashAlgorithm algo )
static

Parse a plain hash that musst not have any prefix indicating the type. The type is passed in to disambiguate.

◆ random()

Hash nix::Hash::random ( HashAlgorithm algo)
static
Returns
a random hash with hash algorithm algo

◆ to_string()

std::string nix::Hash::to_string ( HashFormat hashFormat,
bool includeAlgo ) const
nodiscard

Return a string representation of the hash, in base-16, base-32 or base-64. By default, this is prefixed by the hash algo (e.g. "sha256:").


The documentation for this struct was generated from the following files:
  • libutil/include/nix/util/hash.hh
  • libutil/hash.cc