pub struct Digest(/* private fields */);
Expand description
The output of the hash function.
Implementations§
Source§impl Digest
impl Digest
Sourcepub const SENTINEL_NONE: Digest
pub const SENTINEL_NONE: Digest
Sentinel hash to be used for hashing options in the case of None
.
Sourcepub const SENTINEL_RFOLD: Digest
pub const SENTINEL_RFOLD: Digest
Sentinel hash to be used by hash_slice_rfold
. Terminates the fold.
Sourcepub const SENTINEL_MERKLE_TREE: Digest
pub const SENTINEL_MERKLE_TREE: Digest
Sentinel hash to be used by hash_merkle_tree
in the case of an empty list.
Sourcepub fn hash<T: AsRef<[u8]>>(data: T) -> Digest
pub fn hash<T: AsRef<[u8]>>(data: T) -> Digest
Creates a 32-byte BLAKE2b hash digest from a given a piece of data.
Sourcepub fn hash_pair<T: AsRef<[u8]>, U: AsRef<[u8]>>(data1: T, data2: U) -> Digest
pub fn hash_pair<T: AsRef<[u8]>, U: AsRef<[u8]>>(data1: T, data2: U) -> Digest
Hashes a pair of byte slices.
Sourcepub fn hash_merkle_tree<I>(leaves: I) -> Digest
pub fn hash_merkle_tree<I>(leaves: I) -> Digest
Hashes an impl IntoIterator
of Digest
s into a single Digest
by
constructing a Merkle tree. Reduces pairs of elements in the collection by repeatedly
calling Digest::hash_pair.
The pattern of hashing is as follows. It is akin to graph reduction:
1 2 4 5 8 9
│ │ │ │ │ │
└─3 └─6 └─10
│ │ │
└───7 │
│ │
└───11
Finally hashes the number of elements with the resulting hash. In the example above the
final output would be hash_pair(6_u64.to_le_bytes(), l)
.
Returns Digest::SENTINEL_MERKLE_TREE
when the input is empty.
Sourcepub fn hash_btree_map<K, V>(btree_map: &BTreeMap<K, V>) -> Result<Digest, Error>
pub fn hash_btree_map<K, V>(btree_map: &BTreeMap<K, V>) -> Result<Digest, Error>
Hashes a BTreeMap
.
Sourcepub fn hash_slice_rfold(slice: &[Digest]) -> Digest
pub fn hash_slice_rfold(slice: &[Digest]) -> Digest
Hashes a &[Digest]
using a right fold.
This pattern of hashing is as follows:
hash_pair(a, &hash_pair(b, &hash_pair(c, &SENTINEL_RFOLD)))
Unlike Merkle trees, this is suited to hashing heterogeneous lists we may wish to extend in the future (ie, hashes of data structures that may undergo revision).
Returns Digest::SENTINEL_RFOLD
when given an empty slice as input.
Sourcepub fn hash_slice_with_proof(slice: &[Digest], proof: Digest) -> Digest
pub fn hash_slice_with_proof(slice: &[Digest], proof: Digest) -> Digest
Hashes a &[Digest]
using a right fold. Uses proof
as a Merkle proof for the
missing tail of the slice.
Sourcepub fn from_hex<T: AsRef<[u8]>>(hex_input: T) -> Result<Self, Error>
pub fn from_hex<T: AsRef<[u8]>>(hex_input: T) -> Result<Self, Error>
Returns a Digest
parsed from a hex-encoded Digest
.
Sourcepub fn hash_into_chunks_if_necessary(bytes: &[u8]) -> Digest
pub fn hash_into_chunks_if_necessary(bytes: &[u8]) -> Digest
Hash data into chunks if necessary.
Sourcepub fn hash_vec_merkle_tree(vec: Vec<Digest>) -> Digest
👎Deprecated since 1.5.0: use hash_merkle_tree
instead
pub fn hash_vec_merkle_tree(vec: Vec<Digest>) -> Digest
hash_merkle_tree
insteadProvides the same functionality as Digest::hash_merkle_tree
.
Trait Implementations§
Source§impl DataSize for Digest
impl DataSize for Digest
Source§const IS_DYNAMIC: bool = false
const IS_DYNAMIC: bool = false
true
, the type has a heap size that can vary at runtime, depending on the actual value.Source§const STATIC_HEAP_SIZE: usize = 0usize
const STATIC_HEAP_SIZE: usize = 0usize
IS_DYNAMIC
is false, this is
the total amount of heap memory occupied by the value. Otherwise this is a lower bound.Source§fn estimate_heap_size(&self) -> usize
fn estimate_heap_size(&self) -> usize
Source§impl<'de> Deserialize<'de> for Digest
impl<'de> Deserialize<'de> for Digest
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl JsonSchema for Digest
impl JsonSchema for Digest
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moreSource§impl Ord for Digest
impl Ord for Digest
Source§impl PartialOrd for Digest
impl PartialOrd for Digest
Source§impl ToBytes for Digest
impl ToBytes for Digest
Source§fn serialized_length(&self) -> usize
fn serialized_length(&self) -> usize
Vec<u8>
which would be returned from a successful call to
to_bytes()
or into_bytes()
. The data is not actually serialized, so this call is
relatively cheap.impl Copy for Digest
impl Eq for Digest
impl StructuralPartialEq for Digest
Auto Trait Implementations§
impl Freeze for Digest
impl RefUnwindSafe for Digest
impl Send for Digest
impl Sync for Digest
impl Unpin for Digest
impl UnwindSafe for Digest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)