Skip to main content

Digest

Struct Digest 

Source
pub struct Digest(/* private fields */);
Expand description

A 32-byte Blake2b256 hash output.

§BCS

A Digest’s BCS serialized form is defined by the following:

digest = %x20 32OCTET

Due to historical reasons, even though a Digest has a fixed-length of 32, Sui’s binary representation of a Digest is prefixed with its length meaning its serialized binary form (in bcs) is 33 bytes long vs a more compact 32 bytes.

Implementations§

Source§

impl Digest

Source

pub const LENGTH: usize = 32

A constant representing the length of a digest in bytes.

Source

pub const ZERO: Self

A constant representing a zero digest.

Source

pub const fn new(digest: [u8; 32]) -> Self

Generates a new digest from the provided 32 byte array containing u8 values.

Source

pub fn generate<R>(rng: R) -> Self
where R: RngCore + CryptoRng,

Available on crate feature rand only.

Generates a new digest from the provided random number generator.

Source

pub const fn inner(&self) -> &[u8; 32]

Returns a slice to the inner array representation of this digest.

Source

pub const fn into_inner(self) -> [u8; 32]

Returns the inner array representation of this digest.

Source

pub const fn as_bytes(&self) -> &[u8]

Returns a slice of bytes representing the digest.

Source

pub fn from_base58<T: AsRef<[u8]>>(base58: T) -> Result<Self, DigestParseError>

Decodes a digest from a Base58 encoded string.

Source

pub const fn from_static(base58: &'static str) -> Self

Decodes a digest from a Base58 encoded &’static str.

Similar to from_base58 except any errors are unwrapped, turning them into panics.

Source

pub fn to_base58(&self) -> String

Returns a Base58 encoded string representation of this digest.

Source

pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, DigestParseError>

Generates a digest from bytes.

Trait Implementations§

Source§

impl Arbitrary for Digest

Source§

type Parameters = ()

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Digest>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
Source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl AsRef<[u8]> for Digest

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<[u8; 32]> for Digest

Source§

fn as_ref(&self) -> &[u8; 32]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Digest

Source§

fn clone(&self) -> Digest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Digest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Digest

Source§

fn default() -> Digest

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Digest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Digest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Digest> for String

Source§

fn from(value: &Digest) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 32]> for Digest

Source§

fn from(digest: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl From<Digest> for [u8; 32]

Source§

fn from(digest: Digest) -> Self

Converts to this type from the input type.
Source§

impl From<Digest> for String

Source§

fn from(value: Digest) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Digest

Source§

type Err = DigestParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Digest

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for Digest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Digest

Source§

fn cmp(&self, other: &Digest) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Digest

Source§

fn eq(&self, other: &Digest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Digest

Source§

fn partial_cmp(&self, other: &Digest) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Digest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Digest

Source§

impl Eq for Digest

Source§

impl StructuralPartialEq for Digest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'de, T> FromBcs for T
where T: Deserialize<'de>,

Source§

fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>
where Self: Deserialize<'de>,

Available on crate feature serde only.
Source§

fn from_bcs_base64(base64: &str) -> Result<Self, Error>
where Self: DeserializeOwned,

Available on crate feature serde only.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToBcs for T
where T: Serialize,

Source§

fn to_bcs(&self) -> Result<Vec<u8>, Error>

Available on crate feature serde only.
Source§

fn to_bcs_base64(&self) -> Result<String, Error>

Available on crate feature serde only.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,