pub struct Digest(pub [BFieldElement; 5]);
Expand description
The result of hashing a sequence of elements, for example using Tip5. Sometimes called a “hash”.
Tuple Fields§
§0: [BFieldElement; 5]
Implementations§
Source§impl Digest
impl Digest
pub const fn values(self) -> [BFieldElement; 5]
pub const fn new(digest: [BFieldElement; 5]) -> Digest
Source§impl Digest
impl Digest
Sourcepub fn hash(self) -> Digest
pub fn hash(self) -> Digest
Hash this digest using Tip5, producing a new digest.
A digest can be used as a source of entropy. It can be beneficial or even necessary to not reveal the entropy itself, but use it as the seed for some deterministic computation. In such cases, hashing the digest using this method is probably the right thing to do. If the digest in question is used for its entropy only, there might not be a known meaningful pre-image for that digest.
This method invokes Tip5::hash_pair
with the right operand being the
zero digest, agreeing with the standard way to hash a digest in the virtual
machine.
Sourcepub fn try_from_hex(
data: impl AsRef<[u8]>,
) -> Result<Digest, TryFromHexDigestError>
pub fn try_from_hex( data: impl AsRef<[u8]>, ) -> Result<Digest, TryFromHexDigestError>
Decode hex string to Digest
. Must not include leading “0x”.
Trait Implementations§
Source§impl<'arbitrary> Arbitrary<'arbitrary> for Digest
impl<'arbitrary> Arbitrary<'arbitrary> for Digest
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Digest, Error>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Digest, Error>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Digest, Error>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Digest, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§impl BFieldCodec for Digest
impl BFieldCodec for Digest
type Error = DigestBFieldDecodingError
fn decode( sequence: &[BFieldElement], ) -> Result<Box<Digest>, <Digest as BFieldCodec>::Error>
fn encode(&self) -> Vec<BFieldElement>
Source§fn static_length() -> Option<usize>
fn static_length() -> Option<usize>
Source§impl<'de> Deserialize<'de> for Digest
impl<'de> Deserialize<'de> for Digest
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Digest, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Digest, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<XFieldElement> for Digest
impl From<XFieldElement> for Digest
Source§fn from(xfe: XFieldElement) -> Digest
fn from(xfe: XFieldElement) -> Digest
Interpret the XFieldElement
as a Digest
. No hashing is performed. This
interpretation can be useful for the
AlgebraicHasher
trait and,
by extension, allows building
MerkleTree
s directly from XFieldElement
s.
Source§impl GetSize for Digest
impl GetSize for Digest
Source§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§impl Ord for Digest
impl Ord for Digest
Source§impl PartialOrd for Digest
impl PartialOrd for Digest
Source§impl Serialize for Digest
impl Serialize for Digest
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl TryFrom<&[BFieldElement]> for Digest
impl TryFrom<&[BFieldElement]> for Digest
Source§type Error = TryFromDigestError
type Error = TryFromDigestError
Source§fn try_from(
value: &[BFieldElement],
) -> Result<Digest, <Digest as TryFrom<&[BFieldElement]>>::Error>
fn try_from( value: &[BFieldElement], ) -> Result<Digest, <Digest as TryFrom<&[BFieldElement]>>::Error>
Source§impl TryFrom<Digest> for XFieldElement
impl TryFrom<Digest> for XFieldElement
Source§type Error = TryFromXFieldElementError
type Error = TryFromXFieldElementError
Source§fn try_from(
digest: Digest,
) -> Result<XFieldElement, <XFieldElement as TryFrom<Digest>>::Error>
fn try_from( digest: Digest, ) -> Result<XFieldElement, <XFieldElement as TryFrom<Digest>>::Error>
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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<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 more