Skip to main content

Hash

Struct Hash 

Source
pub struct Hash { /* private fields */ }
Expand description

A cryptographic hash value with its associated algorithm.

This type represents the result of applying a cryptographic hash function to some data. It stores both the resulting hash value and the algorithm used to create it.

Implementations§

Source§

impl Hash

Source

pub const fn new(algorithm: HashAlgorithm, bytes: ByteVec) -> Self

Creates a new hash value with the specified algorithm and bytes.

§Arguments
  • algorithm - The hash algorithm used to create this hash
  • bytes - The raw hash value bytes
Source

pub const fn get_bytes(&self) -> &ByteVec

Returns a reference to the raw hash value bytes.

Source

pub const fn get_algorithm(&self) -> HashAlgorithm

Returns the algorithm used to create this hash.

Source

pub fn verify(&self, bytes: Arc<ByteVec>) -> bool

Verifies that this hash matches the hash of the provided bytes.

§Arguments
  • bytes - The bytes to verify against this hash
§Returns

true if the hash of the provided bytes matches this hash, false otherwise

Source

pub fn try_to_byte_vec(&self) -> Result<Arc<ByteVec>, SerialiseError>

Converts this hash to a ByteVec suitable for encoding.

§Errors

Returns SerialiseError if the hash cannot be converted to bytes.

Source

pub fn try_hash( byte_vec: Arc<ByteVec>, algorithm: HashAlgorithm, ) -> Result<Arc<Self>, SerialiseError>

Computes a hash of the provided bytes using the given algorithm.

§Errors

Returns SerialiseError if hashing fails.

Trait Implementations§

Source§

impl Debug for Hash

Source§

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

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

impl Decodable for Hash

Source§

fn try_decode(encoded_string: EncodedString) -> Result<Self, SerialiseError>
where Self: Sized,

Attempts to decode an encoded string into this type. Read more
Source§

impl Ord for Hash

Source§

fn cmp(&self, other: &Hash) -> 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 Hash

Source§

fn eq(&self, other: &Hash) -> 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 Hash

Source§

fn partial_cmp(&self, other: &Hash) -> 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 TryFrom<Arc<ByteVec>> for Hash

Source§

type Error = SerialiseError

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

fn try_from(value: Arc<ByteVec>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryIntoByteVec for Hash

Source§

fn try_into_byte_vec(value: Arc<Self>) -> Result<Arc<ByteVec>, SerialiseError>

Converts Self to a ByteVec. Read more
Source§

impl Eq for Hash

Source§

impl StructuralPartialEq for Hash

Auto Trait Implementations§

§

impl Freeze for Hash

§

impl RefUnwindSafe for Hash

§

impl Send for Hash

§

impl Sync for Hash

§

impl Unpin for Hash

§

impl UnsafeUnpin for Hash

§

impl UnwindSafe for Hash

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.