pub struct VecMerkleTree<T> { /* private fields */ }
Expand description

An implementation of a Merkle tree, a tree for storing hashes. This implementation is a binary tree which stores its nodes in a vector to ensure data locality.

This type is used to provide integrity protection to a sequence of fixed sized units of data called sectors. The size of the sectors are determined when the tree is created and cannot be changed later. The hashes contained in the leaf nodes of this tree are hashes of sectors. Each sector corresponds to an offset into the protected data, and in order to verify that a sector has not been modified, you must supply the offset of the sector.

Implementations§

source§

impl<T> VecMerkleTree<T>

source

pub fn empty(sector_sz: usize) -> VecMerkleTree<T>

Creates a new tree with no nodes in it and the given sector size.

Trait Implementations§

source§

impl<T> Default for VecMerkleTree<T>

source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for VecMerkleTree<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: MerkleNode> MerkleTree for VecMerkleTree<T>

source§

fn verify(&self, offset: usize, data: &[u8]) -> Result<()>

Verifies that the given data stored from the given offset into the protected data, has not been modified.

source§

fn assert_root_contains(&mut self, hash_data: Option<&[u8]>) -> Result<()>

Checks that the root node contains the given hash data. If it does then Ok(()) is returned. If it doesn’t, then Err(Error::HashCmpFailure) is returned.
source§

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

Hashes the given data, adds a new node to the tree with its hash and updates the hashes of all parent nodes.
source§

fn root_hash(&self) -> Result<&[u8]>

Returns the hash data stored in the root node of the tree. An error is returned if and only if the tree is empty.
source§

impl<T> Sectored for VecMerkleTree<T>

source§

fn sector_sz(&self) -> usize

Returns the size of the sector for this stream.
source§

fn sector_sz64(&self) -> u64

Returns the sector size as a u64.
source§

fn assert_sector_sz(&self, actual: usize) -> Result<()>

Returns Err(Error::IncorrectSize) if the given size is not equal to the sector size.
source§

fn assert_at_least_sector_sz(&self, actual: usize) -> Result<()>

Returns Err(Error::IncorrectSize) if the given size is less than the sector size.
source§

fn offset_at(&self, index: u64) -> u64

Returns the offset (in bytes) from the beginning of this stream that the given 0-based sector index corresponds to.
source§

impl<T> Serialize for VecMerkleTree<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for VecMerkleTree<T>where T: RefUnwindSafe,

§

impl<T> Send for VecMerkleTree<T>where T: Send,

§

impl<T> Sync for VecMerkleTree<T>where T: Sync,

§

impl<T> Unpin for VecMerkleTree<T>where T: Unpin,

§

impl<T> UnwindSafe for VecMerkleTree<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Free for T

§

unsafe default fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,