FsVerityHasher

Struct FsVerityHasher 

Source
pub struct FsVerityHasher<H: FsVerityHashValue, const LG_BLKSZ: u8 = 12> {
    layers: Vec<FsVerityLayer<H, LG_BLKSZ>>,
    value: Option<H>,
    n_bytes: u64,
}
Expand description

Incremental fs-verity digest computation.

This hasher allows computing fs-verity digests incrementally by feeding data in chunks. The data must be provided in block-aligned chunks (4KB by default) except for the final chunk which may be smaller.

§Example

use composefs::fsverity::{FsVerityHasher, Sha256HashValue};

let mut hasher = FsVerityHasher::<Sha256HashValue>::new();
hasher.write_all(b"hello world");
let digest = hasher.digest();

Fields§

§layers: Vec<FsVerityLayer<H, LG_BLKSZ>>§value: Option<H>§n_bytes: u64

Implementations§

Source§

impl<H: FsVerityHashValue, const LG_BLKSZ: u8> FsVerityHasher<H, LG_BLKSZ>

Source

pub const BLOCK_SIZE: usize

The block size in bytes used for fs-verity Merkle tree computation.

Source

pub fn hash(buffer: &[u8]) -> H

Hash a complete buffer and return the fs-verity digest.

Source

pub fn new() -> Self

Create a new incremental fs-verity hasher.

Source

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

Add a block of data to the hasher.

For correct results, data should be provided in block-sized chunks (4KB) except for the final chunk which may be smaller.

Source

fn root_hash(&mut self) -> H

Source

pub fn digest(&mut self) -> H

Finalize and return the fs-verity digest.

This consumes any remaining partial data and computes the final digest.

Trait Implementations§

Source§

impl<H: Debug + FsVerityHashValue, const LG_BLKSZ: u8> Debug for FsVerityHasher<H, LG_BLKSZ>

Source§

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

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

impl<H: FsVerityHashValue, const LG_BLKSZ: u8> Default for FsVerityHasher<H, LG_BLKSZ>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<H, const LG_BLKSZ: u8> Freeze for FsVerityHasher<H, LG_BLKSZ>
where H: Freeze,

§

impl<H, const LG_BLKSZ: u8> RefUnwindSafe for FsVerityHasher<H, LG_BLKSZ>

§

impl<H, const LG_BLKSZ: u8> Send for FsVerityHasher<H, LG_BLKSZ>
where <H as FsVerityHashValue>::Digest: Send,

§

impl<H, const LG_BLKSZ: u8> Sync for FsVerityHasher<H, LG_BLKSZ>
where <H as FsVerityHashValue>::Digest: Sync,

§

impl<H, const LG_BLKSZ: u8> Unpin for FsVerityHasher<H, LG_BLKSZ>

§

impl<H, const LG_BLKSZ: u8> UnwindSafe for FsVerityHasher<H, LG_BLKSZ>

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

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

§

fn vzip(self) -> V