Trait btlib::crypto::merkle_stream::MerkleNode
source · pub trait MerkleNode: Default + Serialize + for<'de> Deserialize<'de> {
const KIND: HashKind;
// Required methods
fn new<'a, I: Iterator<Item = &'a [u8]>>(parts: I) -> Result<Self>;
fn combine<'a, I: Iterator<Item = &'a [u8]>>(
&mut self,
prefix: I,
left: Option<&'a Self>,
right: Option<&'a Self>
) -> Result<()>;
fn assert_contains(&self, hash_data: Option<&[u8]>) -> Result<()>;
fn assert_contains_hash_of<'a, I: Iterator<Item = &'a [u8]>>(
&self,
parts: I
) -> Result<()>;
fn assert_parent_of<'a, I: Iterator<Item = &'a [u8]>>(
&self,
prefix: I,
left: Option<&'a Self>,
right: Option<&'a Self>
) -> Result<()>;
fn try_as_slice(&self) -> Result<&[u8]>;
// Provided method
fn digest<'a, I: Iterator<Item = &'a [u8]>>(
dest: &mut [u8],
parts: I
) -> Result<()> { ... }
}
Expand description
Trait for types which can be used as nodes in a MerkleTree
.
Required Associated Constants§
Required Methods§
sourcefn new<'a, I: Iterator<Item = &'a [u8]>>(parts: I) -> Result<Self>
fn new<'a, I: Iterator<Item = &'a [u8]>>(parts: I) -> Result<Self>
Creates a new HashData
instance by hashing the data produced by the given iterator and
storing it in self.
sourcefn combine<'a, I: Iterator<Item = &'a [u8]>>(
&mut self,
prefix: I,
left: Option<&'a Self>,
right: Option<&'a Self>
) -> Result<()>
fn combine<'a, I: Iterator<Item = &'a [u8]>>( &mut self, prefix: I, left: Option<&'a Self>, right: Option<&'a Self> ) -> Result<()>
Combines the hash data from the given children and prefix and stores it in self. It is
an error for no children to be provided (though one or the other may be None
).
sourcefn assert_contains(&self, hash_data: Option<&[u8]>) -> Result<()>
fn assert_contains(&self, hash_data: Option<&[u8]>) -> Result<()>
Returns Ok(())
if self contains the given hash data, and Err(Error::HashCmpFailure)
otherwise.
sourcefn assert_contains_hash_of<'a, I: Iterator<Item = &'a [u8]>>(
&self,
parts: I
) -> Result<()>
fn assert_contains_hash_of<'a, I: Iterator<Item = &'a [u8]>>( &self, parts: I ) -> Result<()>
Returns Ok(())
if self contains the hash of the given data. Otherwise,
Err(Error::HashCmpFailure)
is returned.
sourcefn assert_parent_of<'a, I: Iterator<Item = &'a [u8]>>(
&self,
prefix: I,
left: Option<&'a Self>,
right: Option<&'a Self>
) -> Result<()>
fn assert_parent_of<'a, I: Iterator<Item = &'a [u8]>>( &self, prefix: I, left: Option<&'a Self>, right: Option<&'a Self> ) -> Result<()>
Returns Ok(())
if the result of combining left and right is contained in self.
sourcefn try_as_slice(&self) -> Result<&[u8]>
fn try_as_slice(&self) -> Result<&[u8]>
Attempts to borrow the data in this node as a slice.