Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
hash.hh File Reference

Go to the source code of this file.

Classes

struct  nix::Hash
struct  nix::HashResult
struct  nix::AbstractHashSink
class  nix::HashSink
struct  std::hash< nix::Hash >

Enumerations

enum struct  HashAlgorithm : char {
  MD5 = 42 , SHA1 , SHA256 , SHA512 ,
  BLAKE3
}
enum struct  nix::HashFormat : int { Base64 , Nix32 , Base16 , SRI }
 Enumeration representing the hash formats. More...

Functions

 nix::MakeError (BadHash, Error)
constexpr size_t nix::regularHashSize (HashAlgorithm type)
Hash nix::newHashAllowEmpty (std::string_view hashStr, std::optional< HashAlgorithm > ha)
Hash nix::hashString (HashAlgorithm ha, std::string_view s, const ExperimentalFeatureSettings &xpSettings)
Hash nix::hashFile (HashAlgorithm ha, const std::filesystem::path &path)
Hash nix::compressHash (const Hash &hash, unsigned int newSize)
HashFormat nix::parseHashFormat (std::string_view hashFormatName)
std::optional< HashFormat > nix::parseHashFormatOpt (std::string_view hashFormatName)
std::string_view nix::printHashFormat (HashFormat HashFormat)
HashAlgorithm nix::parseHashAlgo (std::string_view s, const ExperimentalFeatureSettings &xpSettings)
std::optional< HashAlgorithm > nix::parseHashAlgoOpt (std::string_view s, const ExperimentalFeatureSettings &xpSettings)
std::string_view nix::printHashAlgo (HashAlgorithm ha)
std::size_t nix::hash_value (const Hash &hash)

Enumeration Type Documentation

◆ HashFormat

enum struct nix::HashFormat : int
strong

Enumeration representing the hash formats.

Enumerator
Base64 

Base 64 encoding.

See also
IETF RFC 4648, section 4.
Nix32 

Nix-specific base-32 encoding.

See also
BaseNix32
Base16 

Lowercase hexadecimal encoding.

See also
base16Chars
SRI 

"<hash algo>:<Base 64 hash>", format of the SRI integrity attribute.

See also
W3C recommendation Subresource Integrity.

Function Documentation

◆ compressHash()

Hash nix::compressHash ( const Hash & hash,
unsigned int newSize )

Compress a hash to the specified number of bytes by cyclically XORing bytes together.

◆ hashFile()

Hash nix::hashFile ( HashAlgorithm ha,
const std::filesystem::path & path )

Compute the hash of the given file, hashing its contents directly.

(Metadata, such as the executable permission bit, is ignored.)

◆ hashString()

Hash nix::hashString ( HashAlgorithm ha,
std::string_view s,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings )

Compute the hash of the given string.

◆ newHashAllowEmpty()

Hash nix::newHashAllowEmpty ( std::string_view hashStr,
std::optional< HashAlgorithm > ha )

Helper that defaults empty hashes to the 0 hash.

◆ parseHashAlgo()

HashAlgorithm nix::parseHashAlgo ( std::string_view s,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings )

Parse a string representing a hash algorithm.

◆ parseHashAlgoOpt()

std::optional< HashAlgorithm > nix::parseHashAlgoOpt ( std::string_view s,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings )

Will return nothing on parse error

◆ parseHashFormat()

HashFormat nix::parseHashFormat ( std::string_view hashFormatName)

Parse a string representing a hash format.

◆ parseHashFormatOpt()

std::optional< HashFormat > nix::parseHashFormatOpt ( std::string_view hashFormatName)

std::optional version of parseHashFormat that doesn't throw error.

◆ printHashAlgo()

std::string_view nix::printHashAlgo ( HashAlgorithm ha)

And the reverse.

◆ printHashFormat()

std::string_view nix::printHashFormat ( HashFormat hashFormat)

The reverse of parseHashFormat.

◆ regularHashSize()

size_t nix::regularHashSize ( HashAlgorithm type)
inlineconstexpr
Returns
the size of a hash for the given algorithm