Skip to main content

NixHash

Struct NixHash 

Source
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

Source

pub fn new(algorithm: HashAlgorithm, digest: Vec<u8>) -> Self

Create a new hash from algorithm and raw digest bytes.

Source

pub fn to_nix_string(&self) -> String

Encode as <algo>:<base16> (Nix’s default display format).

Source

pub fn to_sri(&self) -> String

Encode as SRI format: <algo>-<base64>.

Source

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.

Source

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:

  1. lowercase hex<digest_len * 2> characters (e.g. 64 chars for sha256).
  2. nix-base32(digest_len * 8 + 4) / 5 characters using the alphabet 0123456789abcdfghijklmnpqrsvwxyz (52 chars for sha256, 32 for sha1).
  3. 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::InvalidEncoding if the string can’t be decoded as any of the three formats, or if the decoded length doesn’t match the algorithm’s digest_len().

Trait Implementations§

Source§

impl Clone for NixHash

Source§

fn clone(&self) -> NixHash

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NixHash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NixHash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats as the Nix string representation (algo:hex).

Source§

impl Eq for NixHash

Source§

impl PartialEq for NixHash

Source§

fn eq(&self, other: &NixHash) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NixHash

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.