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
impl Hash
sourcepub fn as_bytes<'a>(&'a self) -> &'a [u8] ⓘ
pub fn as_bytes<'a>(&'a self) -> &'a [u8] ⓘ
Returns a reference to a byte slice of the computed hash/key.
sourcepub fn salt<'a>(&'a self) -> &'a [u8] ⓘ
pub fn salt<'a>(&'a self) -> &'a [u8] ⓘ
Returns a reference to a byte slice of the salt used to generate the hash.
sourcepub fn verify(&self, password: &str) -> bool
pub fn verify(&self, password: &str) -> 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.
sourcepub fn verify_with_secret(&self, password: &str, secret: Secret<'_>) -> bool
pub fn verify_with_secret(&self, password: &str, 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 FromStr for Hash
impl FromStr for Hash
source§fn from_str(s: &str) -> Result<Self, Self::Err>
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
type Err = Argon2Error
source§impl ToString for Hash
impl ToString for Hash
source§fn to_string(&self) -> String
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