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§
Sourcefn insert_all<It, Data>(&mut self, items: It)
fn insert_all<It, Data>(&mut self, items: It)
Insert multiple items into this hash function.
Sourcefn union(&mut self, other: &Self)
fn union(&mut self, other: &Self)
Add all the elements of another hash function into this hash function.
Sourcefn remove_all<It, Data>(&mut self, items: It)
fn remove_all<It, Data>(&mut self, items: It)
Remove multiple items from 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.