Function nix_compat::nixhash::from_str

source ยท
pub fn from_str(s: &str, algo_str: Option<&str>) -> NixHashResult<NixHash>
Expand description

Nix allows specifying hashes in various encodings, and magically just derives the encoding. This function parses strings to a NixHash.

Hashes can be:

  • Nix hash strings
  • SRI hashes
  • bare digests

Encoding for Nix hash strings or bare digests can be:

  • base16 (lowerhex),
  • nixbase32,
  • base64 (StdEncoding)
  • sri string

The encoding is derived from the length of the string and the hash type. The hash is communicated out-of-band, but might also be in-band (in the case of a nix hash string or SRI), in which it needs to be consistent with the one communicated out-of-band.