Struct fog_crypto::hash::Hash
source · pub struct Hash { /* private fields */ }
Expand description
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§
source§impl Hash
impl Hash
sourcepub fn new(data: impl AsRef<[u8]>) -> Self
pub fn new(data: impl AsRef<[u8]>) -> Self
Create a new hash from raw data, using the recommended algorithm.
sourcepub fn with_version(
data: impl AsRef<[u8]>,
version: u8
) -> Result<Self, CryptoError>
pub fn with_version( data: impl AsRef<[u8]>, version: u8 ) -> Result<Self, CryptoError>
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.
sourcepub fn from_base58(s: &str) -> Result<Self, CryptoError>
pub fn from_base58(s: &str) -> Result<Self, CryptoError>
Attempt to parse a Base58-encoded hash type. Fails if the string isn’t valid Base58 or the hash itself isn’t valid.
Trait Implementations§
source§impl ConstantTimeEq for Hash
impl ConstantTimeEq for Hash
source§impl<'de> Deserialize<'de> for Hash
impl<'de> Deserialize<'de> for Hash
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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 Ord for Hash
impl Ord for Hash
source§impl PartialEq<Hash> for Hash
impl PartialEq<Hash> for Hash
source§impl PartialOrd<Hash> for Hash
impl PartialOrd<Hash> for Hash
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Hash
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§
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
Mutably borrows from an owned value. Read more