Skip to main content

Hasher

Enum Hasher 

Source
pub enum Hasher {
    CidRaw {
        hasher: Sha256,
    },
    DagPb {
        buffer: Vec<u8>,
        leaves: Vec<DagNode>,
        raw_leaves: bool,
    },
}
Expand description

A streaming hasher that accumulates data and produces a Cid on finalization.

Variants§

§

CidRaw

CIDv1 with the raw codec: the whole input is one raw block.

Fields

§hasher: Sha256
§

DagPb

dag-pb DAG (CIDv0 wrapped leaves, or CIDv1 with raw leaves).

Fields

§buffer: Vec<u8>
§leaves: Vec<DagNode>
§raw_leaves: bool

Implementations§

Source§

impl Hasher

Source

pub fn for_ipfs() -> Self

Creates a hasher for IPFS CIDv0 dag-pb (wrapped leaves, balanced DAG).

Source

pub fn for_ipfs_v1_raw_leaves() -> Self

Creates a hasher for IPFS CIDv1 dag-pb with raw leaves.

Matches kubo’s ipfs add --cid-version=1 --raw-leaves defaults: chunks of 256 KiB are stored as raw blocks (codec 0x55) and the file root (if the file spans multiple chunks) is a dag-pb node linking those raw leaves. A single-chunk file collapses to a bare raw block whose CID is bafkrei….

Source

pub fn for_expected(expected: &Cid) -> Result<Self, UnsupportedCid>

Creates a hasher that reproduces the construction of the given CID: dag-pb with wrapped leaves for CIDv0, a single raw block for CIDv1 raw, dag-pb with raw leaves for CIDv1 dag-pb.

Source

pub fn update(&mut self, data: &[u8])

Feed data into the hasher.

Source

pub fn finalize(self) -> Cid

Finalize the hasher and return the computed Cid.

Trait Implementations§

Source§

impl Debug for Hasher

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.