Struct argon2_kdf::Hash

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

A container for an Argon2 hash, the corresponding salt, and the parameters used for hashing

Implementations§

source§

impl Hash

source

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

Returns a reference to a byte slice of the computed hash/key.

source

pub fn salt(&self) -> &[u8]

Returns a reference to a byte slice of the salt used to generate the hash.

source

pub fn verify(&self, password: &[u8]) -> bool

Checks if the hash matches the provided password.

Because verification requires re-hashing the password, this is an expensive operation. For some appliations, it might make sense to move this operation to a separate thread using std::thread or something like the Rayon crate to avoid blocking main threads.

source

pub fn verify_with_secret(&self, password: &[u8], secret: Secret<'_>) -> bool

Checks if the hash matches the provided password using the provided secret.

Because verification requires re-hashing the password, this is an expensive operation. For some appliations, it might make sense to move this operation to a separate thread using std::thread or something like the Rayon crate to avoid blocking main threads.

Trait Implementations§

source§

impl Clone for Hash

source§

fn clone(&self) -> Hash

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 Hash

source§

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

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

impl FromStr for Hash

source§

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

Deserializes a hash string into parts (e.g. the hash, the salt, parameters) that can be used for purposes such as verification or encryption.

A hash string looks something like this:

$argon2id$v=19$m=62500,t=18,p=2$AQIDBAUGBwg$ypJ3pKxN4aWGkwMv0TOb08OIzwrfK1SZWy64vyTLKo8

§

type Err = Argon2Error

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

impl ToString for Hash

source§

fn to_string(&self) -> String

Generates a hash string. Aside from the hash, the hash string also includes the salt and paramters used to generate the hash, making it easy to store in a database or a cache. This string is formatted to a standard shared by most implementations of argon2, so other argon2 libraries should be able to use this hash string.

A hash string looks something like this:

$argon2id$v=19$m=62500,t=18,p=2$AQIDBAUGBwg$ypJ3pKxN4aWGkwMv0TOb08OIzwrfK1SZWy64vyTLKo8

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V