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§

source

const KIND: HashKind

The kind of hash algorithm that this HashData uses.

Required Methods§

source

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.

source

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

source

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

Returns Ok(()) if self contains the given hash data, and Err(Error::HashCmpFailure) otherwise.

source

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.

source

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.

source

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

Attempts to borrow the data in this node as a slice.

Provided Methods§

source

fn digest<'a, I: Iterator<Item = &'a [u8]>>( dest: &mut [u8], parts: I ) -> Result<()>

Computes the hash of the data produced by the given iterator and writes it to the given slice.

Implementors§

source§

impl MerkleNode for Sha2_256Node

source§

const KIND: HashKind = HashKind::Sha2_256