MultisetHash

Trait MultisetHash 

Source
pub trait MultisetHash<const DIGEST_LENGTH: usize>: Eq {
    // Required methods
    fn insert<Data: AsRef<[u8]>>(&mut self, item: Data);
    fn insert_all<It, Data>(&mut self, items: It)
       where It: IntoIterator<Item = Data>,
             Data: AsRef<[u8]>;
    fn union(&mut self, other: &Self);
    fn remove<Data: AsRef<[u8]>>(&mut self, item: Data);
    fn remove_all<It, Data>(&mut self, items: It)
       where It: IntoIterator<Item = Data>,
             Data: AsRef<[u8]>;
    fn digest(&self) -> Digest<DIGEST_LENGTH>;
}
Expand description

A Multiset Hash is a homomorphic hash function, which hashes arbitrary multisets of objects such that the hash of the union of two multisets is easy to compute from the hashes of the two multisets.

The hash may be computed incrementally, adding items one at a time, and the order does not affect the result. The hash of two multisets can be compared by using the Eq trait impl’d for the given hash function, and the hash function should be collision resistant. Items may also be removed again.

See “Incremental Multiset Hash Functions and Their Application to Memory Integrity Checking” by D. Clarke et al. for a discussion of this type of hash functions.

§Example

use vrf_wasm::{EllipticCurveMultisetHash, MultisetHash};

let mut hash1 = EllipticCurveMultisetHash::default();
hash1.insert(b"Hello");
hash1.insert(b"World");

let mut hash2 = EllipticCurveMultisetHash::default();
hash2.insert(b"World");
hash2.insert(b"Hello");

assert_eq!(hash1, hash2);
assert_eq!(hash1.digest(), hash2.digest());

Required Methods§

Source

fn insert<Data: AsRef<[u8]>>(&mut self, item: Data)

Insert an item into this hash function.

Source

fn insert_all<It, Data>(&mut self, items: It)
where It: IntoIterator<Item = Data>, Data: AsRef<[u8]>,

Insert multiple items into this hash function.

Source

fn union(&mut self, other: &Self)

Add all the elements of another hash function into this hash function.

Source

fn remove<Data: AsRef<[u8]>>(&mut self, item: Data)

Remove an element from this hash function.

Source

fn remove_all<It, Data>(&mut self, items: It)
where It: IntoIterator<Item = Data>, Data: AsRef<[u8]>,

Remove multiple items from this hash function.

Source

fn digest(&self) -> Digest<DIGEST_LENGTH>

Generate a digest of the current state of this hash function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§