Struct fog_crypto::hash::Hash[][src]

pub struct Hash { /* fields omitted */ }

Crytographically secure hash of data.

Offers constant time equality check (non-constant time ordinal checks). A version byte is used to indicate what hash algorithm should be used. Uses base58 encoding when displayed, unless overridden with hex formatting or debug formatting.

Supported Versions

  • 1: Blake2B hash with 32 bytes of digest

Example

// Create a new hash from raw bytes
let hash = Hash::new(b"I am the entire data sequence");
println!("Hash(Base58): {}", hash);

Implementations

impl Hash[src]

pub fn new(data: impl AsRef<[u8]>) -> Self[src]

Create a new hash from raw data, using the recommended algorithm.

pub fn with_version(
    data: impl AsRef<[u8]>,
    version: u8
) -> Result<Self, CryptoError>
[src]

Create a hash with a specific algorithm version. You should avoid this except when working through a upgrade process, where you may briefly need to support more than one version. Fails if the version isn’t supported.

pub fn version(&self) -> u8[src]

Algorithm version associated with this hash.

pub fn digest(&self) -> &[u8][src]

The raw digest from the hash, without the version byte.

pub fn from_base58(s: &str) -> Result<Self, CryptoError>[src]

Attempt to parse a Base58-encoded hash type. Fails if the string isn’t valid Base58 or the hash itself isn’t valid.

pub fn to_base58(&self) -> String[src]

Encode the hash as a Base58 string.

Trait Implementations

impl AsRef<[u8]> for Hash[src]

impl Clone for Hash[src]

impl ConstantTimeEq for Hash[src]

impl Debug for Hash[src]

impl<'de> Deserialize<'de> for Hash[src]

impl Display for Hash[src]

impl Eq for Hash[src]

impl Hash for Hash[src]

impl LowerHex for Hash[src]

impl Ord for Hash[src]

impl PartialEq<Hash> for Hash[src]

impl PartialOrd<Hash> for Hash[src]

impl Serialize for Hash[src]

impl TryFrom<&'_ [u8]> for Hash[src]

type Error = CryptoError

The type returned in the event of a conversion error.

impl UpperHex for Hash[src]

Auto Trait Implementations

impl RefUnwindSafe for Hash

impl Send for Hash

impl Sync for Hash

impl Unpin for Hash

impl UnwindSafe for Hash

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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