Skip to main content

Hasher

Struct Hasher 

Source
pub struct Hasher<const BODY_SIZE: usize = DEFAULT_BODY_SIZE> { /* private fields */ }
Expand description

BMT hasher with configurable body size.

Implementations§

Source§

impl<const BODY_SIZE: usize> Hasher<BODY_SIZE>

Source

pub const fn new() -> Self

Create a new BMT hasher.

Source

pub const fn set_span(&mut self, span: u64)

Set the span of data to be hashed

Source

pub const fn span(&self) -> u64

Get the current span

Source

pub fn prefix_with(&mut self, prefix: &[u8])

Add a prefix to the hash calculation

Source

pub fn prefix(&self) -> &[u8]

Get the current prefix

Source

pub const fn position(&self) -> usize

Get the current cursor position

Source

pub const fn len(&self) -> usize

Get the amount of data currently in the buffer

Source

pub const fn is_empty(&self) -> bool

Check if the buffer is empty

Source

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

Update the hasher with more data (non-destructive)

Source

pub fn hash(&self, out: &mut [u8])

Compute the BMT hash and write to output buffer.

Source

pub fn sum(&self) -> B256

Compute the BMT hash and return the result (non-destructive)

Source

pub fn data(&self) -> Bytes

Get the current data as Bytes (immutable reference)

Source

pub fn get_level_segments(&self, data: &[u8]) -> Vec<B256>

Get segments for the current level of data

Trait Implementations§

Source§

impl<const BODY_SIZE: usize> Clone for Hasher<BODY_SIZE>

Source§

fn clone(&self) -> Hasher<BODY_SIZE>

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<const BODY_SIZE: usize> Debug for Hasher<BODY_SIZE>

Source§

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

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

impl<const BODY_SIZE: usize> Default for Hasher<BODY_SIZE>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const BODY_SIZE: usize> FixedOutput for Hasher<BODY_SIZE>

Source§

fn finalize_into(self, out: &mut Array<u8, Self::OutputSize>)

Consume value and write result into provided array.
Source§

fn finalize_fixed(self) -> Array<u8, Self::OutputSize>

Retrieve result and consume the hasher instance.
Source§

impl<const BODY_SIZE: usize> FixedOutputReset for Hasher<BODY_SIZE>

Source§

fn finalize_into_reset(&mut self, out: &mut Array<u8, Self::OutputSize>)

Write result into provided array and reset the hasher state.
Source§

fn finalize_fixed_reset(&mut self) -> Array<u8, Self::OutputSize>

Retrieve result and reset the hasher state.
Source§

impl<const BODY_SIZE: usize> HashMarker for Hasher<BODY_SIZE>

Source§

impl<const BODY_SIZE: usize> OutputSizeUser for Hasher<BODY_SIZE>

Source§

type OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

Size of the output in bytes.
Source§

fn output_size() -> usize

Return output size in bytes.
Source§

impl Prover for Hasher

Source§

fn generate_proof(&self, data: &[u8], segment_index: usize) -> Result<Proof>

Generate a proof for a specific segment
Source§

fn verify_proof(proof: &Proof, root_hash: &[u8]) -> Result<bool>

Verify a proof against a root hash
Source§

impl<const BODY_SIZE: usize> Reset for Hasher<BODY_SIZE>

Source§

fn reset(&mut self)

Reset state to its initial value.
Source§

impl<const BODY_SIZE: usize> Update for Hasher<BODY_SIZE>

Source§

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

Update state using the provided data.
Source§

fn chain(self, data: impl AsRef<[u8]>) -> Self
where Self: Sized,

Digest input data in a chained manner.
Source§

impl<const BODY_SIZE: usize> Write for Hasher<BODY_SIZE>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<const BODY_SIZE: usize> Freeze for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> RefUnwindSafe for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Send for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Sync for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Unpin for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnsafeUnpin for Hasher<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnwindSafe for Hasher<BODY_SIZE>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<D> Digest for D

Source§

fn new() -> D

Create new hasher instance.
Source§

fn new_with_prefix(data: impl AsRef<[u8]>) -> D
where D: Sized + Default,

Create new hasher instance which has processed the provided data.
Source§

fn update(&mut self, data: impl AsRef<[u8]>)

Process data, updating the internal state.
Source§

fn chain_update(self, data: impl AsRef<[u8]>) -> D

Process input data in a chained manner.
Source§

fn finalize(self) -> Array<u8, <D as OutputSizeUser>::OutputSize>

Retrieve result and consume hasher instance.
Source§

fn finalize_into(self, out: &mut Array<u8, <D as OutputSizeUser>::OutputSize>)

Write result into provided array and consume the hasher instance.
Source§

fn finalize_reset(&mut self) -> Array<u8, <D as OutputSizeUser>::OutputSize>

Retrieve result and reset hasher instance.
Source§

fn finalize_into_reset( &mut self, out: &mut Array<u8, <D as OutputSizeUser>::OutputSize>, )

Write result into provided array and reset the hasher instance.
Source§

fn reset(&mut self)
where D: Reset,

Reset hasher instance to its initial state.
Source§

fn output_size() -> usize

Get output size of the hasher
Source§

fn digest( data: impl AsRef<[u8]>, ) -> Array<u8, <D as OutputSizeUser>::OutputSize>

Compute hash of data.
Source§

impl<D> DynDigest for D
where D: Update + FixedOutputReset + Reset + Clone + 'static,

Source§

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

Digest input data. Read more
Source§

fn finalize_into(self, buf: &mut [u8]) -> Result<(), InvalidBufferSize>

Write result into provided array and consume the hasher instance. Read more
Source§

fn finalize_into_reset( &mut self, buf: &mut [u8], ) -> Result<(), InvalidBufferSize>

Write result into provided array and reset the hasher instance. Read more
Source§

fn reset(&mut self)

Reset hasher instance to its initial state.
Source§

fn output_size(&self) -> usize

Get output size of the hasher
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<W> Writer for W
where W: Write,

Source§

fn write(&mut self, slice: &[u8]) -> Result<(), Error>

Write the given DER-encoded bytes as output.
Source§

fn write_byte(&mut self, byte: u8) -> Result<(), Error>

Write a single byte.