pub struct NixHash {
pub algorithm: HashAlgorithm,
pub digest: Vec<u8>,
}Expand description
A typed hash value.
Fields§
§algorithm: HashAlgorithm§digest: Vec<u8>Implementations§
Source§impl NixHash
impl NixHash
Sourcepub fn new(algorithm: HashAlgorithm, digest: Vec<u8>) -> Self
pub fn new(algorithm: HashAlgorithm, digest: Vec<u8>) -> Self
Create a new hash from algorithm and raw digest bytes.
Sourcepub fn to_nix_string(&self) -> String
pub fn to_nix_string(&self) -> String
Encode as <algo>:<base16> (Nix’s default display format).
Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Lower-case hex of the digest (no <algo>: prefix). Useful
for embedding into the fixed:out:<algo>:<hex>: content-
address fingerprints CppNix uses to compute fixed-output
store paths.
Sourcepub fn parse_any(algorithm: HashAlgorithm, raw: &str) -> Result<Self, HashError>
pub fn parse_any(algorithm: HashAlgorithm, raw: &str) -> Result<Self, HashError>
Decode a user-supplied hash string under algorithm,
accepting any of the three formats CppNix tolerates as
outputHash input:
- lowercase hex —
<digest_len * 2>characters (e.g. 64 chars for sha256). - nix-base32 —
(digest_len * 8 + 4) / 5characters using the alphabet0123456789abcdfghijklmnpqrsvwxyz(52 chars for sha256, 32 for sha1). - SRI —
<algo>-<standard-base64-of-digest>(e.g.sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=).
The parser chooses by length + alphabet without backtracking.
Returns HashError::InvalidEncoding for any malformed or
length-mismatched input.
This is the canonical hash-ingress primitive: every callsite
that takes a hash string from user code (derivation
outputHash, builtin fetchurl, flake-input narHash)
must normalize through here before computing store paths
— the fixed:out:<algo>:<hex>: fingerprint embedded in the
store-path digest is byte-equivalent to CppNix only when the
hash is canonicalized to lowercase hex first.
§Errors
HashError::InvalidEncodingif the string can’t be decoded as any of the three formats, or if the decoded length doesn’t match the algorithm’sdigest_len().