Struct rubedo::crypto::Sha256Hash

source ·
pub struct Sha256Hash { /* private fields */ }
Expand description

A SHA256 hash.

A formalised representation of a SHA256 hash, with support for common conversions, including serialisation and deserialisation using Serde.

The hash is stored internally as [u8; 32], which is the correct and most efficient format, as emitted by Sha256::digest().

The conversion to and from a String defaults to using hex strings rather than base64-encoded strings, because this is more common, due to it being a fixed-length string that is easy to read, verify, and transmit without any compatibility issues. However, base64 conversion functions are also provided for convenience in case that format is preferred.

Implementations§

source§

impl Sha256Hash

source

pub fn new<T: Into<Self>>(data: T) -> Self

Creates a new SHA256 hash instance.

§Parameters
  • data - The SHA256 hash as any type for which there is a From implementation.
§See also

Trait Implementations§

source§

impl AsMut<[u8; 32]> for Sha256Hash

source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u8; 32]> for Sha256Hash

source§

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

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

impl ByteSized<32> for Sha256Hash

source§

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

Returns a byte slice of the container’s contents. Read more
source§

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

Returns a copy of the container data as a fixed-length array of bytes. Read more
source§

fn from_bytes(bytes: [u8; 32]) -> Self

Constructs a ByteSized type from an array of bytes. Read more
source§

fn to_base64(&self) -> String

Returns the container data converted to a base64-encoded String. Read more
source§

fn from_base64(encoded: &str) -> Result<Self, DecodeError>

Converts a base64-encoded String to a ByteSized type. Read more
source§

fn to_hex(&self) -> String

Returns the container data converted to a hex-encoded String. Read more
source§

fn from_hex(encoded: &str) -> Result<Self, FromHexError>

Converts a hex-encoded String to a ByteSized. Read more
source§

fn to_vec(&self) -> Vec<u8>

Returns a copy of the container data converted to a vector of bytes. Read more
source§

impl ByteSizedMut<32> for Sha256Hash

source§

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

Returns a mutable reference to the container’s contents. Read more
source§

fn into_bytes(self) -> [u8; 32]

Returns the container as a fixed-length array of bytes. Read more
source§

fn into_vec(self) -> Vec<u8>

Returns the container as a vector of bytes. Read more
source§

impl Clone for Sha256Hash

source§

fn clone(&self) -> Sha256Hash

Returns a copy 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 Sha256Hash

source§

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

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

impl Default for Sha256Hash

source§

fn default() -> Sha256Hash

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

impl<'de> Deserialize<'de> for Sha256Hash

source§

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

Deserialises the SHA256 hash from a String.

This method deserialises the SHA256 hash from hexadecimal string representation.

§See also
  • [$t::deserialize()]
  • [$t::from_base64()]
source§

impl Display for Sha256Hash

source§

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

Formats the SHA256 hash for display.

This method serialises the SHA256 hash into hexadecimal string representation.

§See also
  • [$t::serialize()]
  • [$t::to_base64()]
source§

impl ForceFrom<&[u8]> for Sha256Hash

source§

fn force_from(b: &[u8]) -> Self

Converts a &[u8] to a [$t].

Note that if the incoming [u8] is too long to fit, it will be truncated without error or warning. If there is not enough data, it will be padded with zeroes. If this situation needs checking, use try_from() instead.

source§

impl<const N: usize> ForceFrom<&[u8; N]> for Sha256Hash

source§

fn force_from(b: &[u8; N]) -> Self

Converts a &[u8; N] to a [$t].

Note that if the incoming [u8; N] is too long to fit, it will be truncated without error or warning. If there is not enough data, it will be padded with zeroes. If this situation needs checking, use try_from() instead.

source§

impl ForceFrom<&Vec<u8>> for Sha256Hash

source§

fn force_from(v: &Vec<u8>) -> Self

Converts a &Vec[u8] to a [$t].

Note that if the incoming Vec<u8> is too long to fit, it will be truncated without error or warning. If there is not enough data, it will be padded with zeroes. If this situation needs checking, use try_from() instead.

source§

impl ForceFrom<Vec<u8>> for Sha256Hash

source§

fn force_from(v: Vec<u8>) -> Self

Converts a Vec<u8> to a [$t].

Note that if the incoming Vec<u8> is too long to fit, it will be truncated without error or warning. If there is not enough data, it will be padded with zeroes. If this situation needs checking, use try_from() instead.

source§

impl From<&[u8; 32]> for Sha256Hash

source§

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

Converts a &[u8; $s] to a [$t].

source§

impl From<&GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>> for Sha256Hash

source§

fn from(a: &GenericArray<u8, U32>) -> Self

Converts a GenericArray<u8, $o> to a [$t].

source§

impl From<[u8; 32]> for Sha256Hash

source§

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

Converts a [u8; $s] to a [$t].

source§

impl From<GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>> for Sha256Hash

source§

fn from(a: GenericArray<u8, U32>) -> Self

Converts a GenericArray<u8, $o> to a [$t].

source§

impl FromStr for Sha256Hash

§

type Err = ByteSizedError

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 Sha256Hash

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 Hashed for Sha256Hash

§

type Algorithm = CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, OidSha256>>

The hashing algorithm to use produce the hash.
§

type OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

The output size of the hashing algorithm.
source§

fn from_digest(output: GenericArray<u8, Self::OutputSize>) -> Self

Converts the output of the hashing algorithm to the Hashed type. Read more
source§

impl PartialEq<&[u8; 32]> for Sha256Hash

source§

fn eq(&self, other: &&[u8; 32]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<[u8; 32]> for Sha256Hash

source§

fn eq(&self, other: &[u8; 32]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Sha256Hash

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Sha256Hash

source§

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

Serialises the SHA256 hash to a String.

This method serialises the SHA256 hash into hexadecimal string representation.

§See also
  • [$t::deserialize()]
  • [$t::<Display>fmt()]
  • [$t::to_base64()]
source§

impl TryFrom<&[u8]> for Sha256Hash

source§

fn try_from(b: &[u8]) -> Result<Self, Self::Error>

Converts a &[u8] to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<&String> for Sha256Hash

source§

fn try_from(s: &String) -> Result<Self, Self::Error>

Converts a &String to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<&Vec<u8>> for Sha256Hash

source§

fn try_from(v: &Vec<u8>) -> Result<Self, Self::Error>

Converts a &Vec[u8] to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<&str> for Sha256Hash

source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Converts a &str to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<Box<str>> for Sha256Hash

source§

fn try_from(s: Box<str>) -> Result<Self, Self::Error>

Converts a boxed string slice to a [$t].

§

type Error = ByteSizedError

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

impl<'a> TryFrom<Cow<'a, str>> for Sha256Hash

source§

fn try_from(s: Cow<'a, str>) -> Result<Self, Self::Error>

Converts a clone-on-write string to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<String> for Sha256Hash

source§

fn try_from(s: String) -> Result<Self, Self::Error>

Converts a String to a [$t].

§

type Error = ByteSizedError

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

impl TryFrom<Vec<u8>> for Sha256Hash

source§

fn try_from(v: Vec<u8>) -> Result<Self, Self::Error>

Converts a Vec<u8> to a [$t].

§

type Error = ByteSizedError

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

impl Copy for Sha256Hash

source§

impl Eq for Sha256Hash

source§

impl StructuralPartialEq for Sha256Hash

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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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

§

type Output = T

Should always be Self
source§

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

§

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§

default 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>,

§

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>,

§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,