Struct btlib::crypto::merkle_stream::VecMerkleTree
source · 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>
impl<T> VecMerkleTree<T>
sourcepub fn empty(sector_sz: usize) -> VecMerkleTree<T>
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>
impl<T> Default for VecMerkleTree<T>
source§impl<'de, T> Deserialize<'de> for VecMerkleTree<T>where
T: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<T: MerkleNode> MerkleTree for VecMerkleTree<T>
impl<T: MerkleNode> MerkleTree for VecMerkleTree<T>
source§fn verify(&self, offset: usize, data: &[u8]) -> Result<()>
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<()>
fn assert_root_contains(&mut self, hash_data: Option<&[u8]>) -> Result<()>
Ok(())
is
returned. If it doesn’t, then Err(Error::HashCmpFailure)
is returned.source§impl<T> Sectored for VecMerkleTree<T>
impl<T> Sectored for VecMerkleTree<T>
source§fn sector_sz64(&self) -> u64
fn sector_sz64(&self) -> u64
u64
.source§fn assert_sector_sz(&self, actual: usize) -> Result<()>
fn assert_sector_sz(&self, actual: usize) -> Result<()>
Err(Error::IncorrectSize)
if the given size is not equal to the sector size.