Struct casper_hashing::Digest
source · 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) -> Digestwhere
I: IntoIterator<Item = Digest>,
I::IntoIter: ExactSizeIterator,
pub fn hash_merkle_tree<I>(leaves: I) -> Digestwhere I: IntoIterator<Item = Digest>, I::IntoIter: ExactSizeIterator,
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>where
K: ToBytes,
V: ToBytes,
pub fn hash_btree_map<K, V>(btree_map: &BTreeMap<K, V>) -> Result<Digest, Error>where K: ToBytes, V: ToBytes,
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 PartialEq for Digest
impl PartialEq for Digest
source§impl PartialOrd for Digest
impl PartialOrd for Digest
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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 StructuralEq for Digest
impl StructuralPartialEq for Digest
Auto Trait Implementations§
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§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 Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere T: AsRef<[u8]>,
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
)