pub struct Hash {
pub alg: Algorithm,
pub mem_cost_kib: u32,
pub iterations: u32,
pub threads: u32,
pub salt: Vec<u8>,
pub hash: Vec<u8>,
}Expand description
A container for an Argon2 hash, the corresponding salt, and the parameters used for hashing
Fields§
§alg: AlgorithmThe algorithm used for hashing (Argon2d, Argon2i, or Argon2id)
mem_cost_kib: u32The memory cost in kibibytes
iterations: u32The number of iterations used for hashing
threads: u32The number of threads used for hashing
salt: Vec<u8>The salt used to generate the hash
hash: Vec<u8>The hash in bytes
Implementations§
Source§impl Hash
impl Hash
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a reference to a byte slice of the computed hash/key.
Sourcepub fn salt_bytes(&self) -> &[u8] ⓘ
pub fn salt_bytes(&self) -> &[u8] ⓘ
Returns a reference to a byte slice of the salt used to generate the hash.
Sourcepub fn memory_cost_kib(&self) -> u32
pub fn memory_cost_kib(&self) -> u32
Returns the memory cost used to generate the hash.
Sourcepub fn iterations(&self) -> u32
pub fn iterations(&self) -> u32
Returns the number of iterations used to generate the hash.
Sourcepub fn verify(&self, password: &[u8]) -> bool
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.
Sourcepub fn verify_with_secret(&self, password: &[u8], secret: Secret<'_>) -> bool
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 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
Source§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