Hash

Struct Hash 

Source
pub struct Hash<'a> { /* private fields */ }
Expand description

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

Implementations§

Source§

impl<'a> Hash<'a>

Source

pub fn from_parts( hash: &'a [u8], salt: &'a [u8], alg: Algorithm, mem_cost_kib: u32, iterations: u32, threads: u32, ) -> Self

Constructs a Hash from a slice of the hash and salt and the parameters used for hashing.

Source

pub fn from_parts_owned( hash: Vec<u8>, salt: Vec<u8>, alg: Algorithm, mem_cost_kib: u32, iterations: u32, threads: u32, ) -> Self

Constructs a Hash from a Vec<u8> of the hash and salt and the parameters used for hashing, taking ownership of the hash and salt Vecs.

Source

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

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

Source

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

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

Source

pub fn algorithm(&self) -> Algorithm

Returns the algorithm used to generate the hash.

Source

pub fn memory_cost_kib(&self) -> u32

Returns the memory cost used to generate the hash.

Source

pub fn iterations(&self) -> u32

Returns the number of iterations used to generate the hash.

Source

pub fn threads(&self) -> u32

Returns the number of threads 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<'a> Clone for Hash<'a>

Source§

fn clone(&self) -> Hash<'a>

Returns a duplicate 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<'a> Debug for Hash<'a>

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

Source§

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<'a> Freeze for Hash<'a>

§

impl<'a> RefUnwindSafe for Hash<'a>

§

impl<'a> Send for Hash<'a>

§

impl<'a> Sync for Hash<'a>

§

impl<'a> Unpin for Hash<'a>

§

impl<'a> UnwindSafe for Hash<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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 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.
Source§

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

Source§

fn vzip(self) -> V