Trait merkle_light::hash::Algorithm [] [src]

pub trait Algorithm<T>: Hasher + Default where
    T: Clone + AsRef<[u8]>, 
{ fn hash(&mut self) -> T; fn reset(&mut self) { ... }
fn leaf(&mut self, leaf: T) -> T { ... }
fn node(&mut self, left: T, right: T) -> T { ... } }

A trait for hashing an arbitrary stream of bytes for calculating merkle tree nodes.

T is a hash item must be of known size at compile time, globally ordered, with default value as a neutral element of the hash space. Neutral element is interpreted as 0 or nil and required for evaluation of merkle tree.

[Algorithm] breaks the [Hasher] contract at finish(), but that is intended. This trait extends [Hasher] with hash -> T and reset state methods, plus implements default behavior of evaluation of MT interior nodes.

Required Methods

Returns the hash value for the data stream written so far.

Provided Methods

Reset Hasher state.

Returns hash value for MT leaf (prefix 0x00).

Returns hash value for MT interior node (prefix 0x01).

Implementors