Struct password_hash::PasswordHash
source · [−]pub struct PasswordHash<'a> {
pub algorithm: Ident<'a>,
pub version: Option<Decimal>,
pub params: ParamsString,
pub salt: Option<Salt<'a>>,
pub hash: Option<Output>,
}
Expand description
Password hash.
This type corresponds to the parsed representation of a PHC string as described in the PHC string format specification.
PHC strings have the following format:
$<id>[$v=<version>][$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
where:
<id>
is the symbolic name for the function<version>
is the algorithm version<param>
is a parameter name<value>
is a parameter value<salt>
is an encoding of the salt<hash>
is an encoding of the hash output
The string is then the concatenation, in that order, of:
- a
$
sign; - the function symbolic name;
- optionally, a
$
sign followed by the algorithm version with av=version
format; - optionally, a
$
sign followed by one or several parameters, each with aname=value
format; the parameters are separated by commas; - optionally, a
$
sign followed by the (encoded) salt value; - optionally, a
$
sign followed by the (encoded) hash output (the hash output may be present only if the salt is present).
Fields
algorithm: Ident<'a>
Password hashing algorithm identifier.
This corresponds to the <id>
field in a PHC string, a.k.a. the
symbolic name for the function.
version: Option<Decimal>
Optional version field.
This corresponds to the <version>
field in a PHC string.
params: ParamsString
Algorithm-specific parameters.
This corresponds to the set of $<param>=<value>(,<param>=<value>)*
name/value pairs in a PHC string.
salt: Option<Salt<'a>>
Salt
string for personalizing a password hash output.
This corresponds to the <salt>
value in a PHC string.
hash: Option<Output>
Password hashing function Output
, a.k.a. hash/digest.
This corresponds to the <hash>
output in a PHC string.
Implementations
sourceimpl<'a> PasswordHash<'a>
impl<'a> PasswordHash<'a>
sourcepub fn new(s: &'a str) -> Result<Self>
pub fn new(s: &'a str) -> Result<Self>
Parse a password hash from a string in the PHC string format.
sourcepub fn parse(s: &'a str, encoding: Encoding) -> Result<Self>
pub fn parse(s: &'a str, encoding: Encoding) -> Result<Self>
Parse a password hash from the given Encoding
.
sourcepub fn generate(
phf: impl PasswordHasher,
password: impl AsRef<[u8]>,
salt: &'a str
) -> Result<Self>
pub fn generate(
phf: impl PasswordHasher,
password: impl AsRef<[u8]>,
salt: &'a str
) -> Result<Self>
Generate a password hash using the supplied algorithm.
sourcepub fn verify_password(
&self,
phfs: &[&dyn PasswordVerifier],
password: impl AsRef<[u8]>
) -> Result<()>
pub fn verify_password(
&self,
phfs: &[&dyn PasswordVerifier],
password: impl AsRef<[u8]>
) -> Result<()>
Verify this password hash using the specified set of supported
PasswordHasher
trait objects.
sourcepub fn encoding(&self) -> Encoding
pub fn encoding(&self) -> Encoding
Get the Encoding
that this PasswordHash
is serialized with.
sourcepub fn serialize(&self) -> PasswordHashString
Available on crate feature alloc
only.
pub fn serialize(&self) -> PasswordHashString
alloc
only.Serialize this PasswordHash
as a PasswordHashString
.
Trait Implementations
sourceimpl<'a> Clone for PasswordHash<'a>
impl<'a> Clone for PasswordHash<'a>
sourcefn clone(&self) -> PasswordHash<'a>
fn clone(&self) -> PasswordHash<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for PasswordHash<'a>
impl<'a> Debug for PasswordHash<'a>
sourceimpl<'a> Display for PasswordHash<'a>
impl<'a> Display for PasswordHash<'a>
sourceimpl From<&PasswordHash<'_>> for PasswordHashString
impl From<&PasswordHash<'_>> for PasswordHashString
sourcefn from(hash: &PasswordHash<'_>) -> PasswordHashString
fn from(hash: &PasswordHash<'_>) -> PasswordHashString
Converts to this type from the input type.
sourceimpl From<PasswordHash<'_>> for PasswordHashString
impl From<PasswordHash<'_>> for PasswordHashString
sourcefn from(hash: PasswordHash<'_>) -> PasswordHashString
fn from(hash: PasswordHash<'_>) -> PasswordHashString
Converts to this type from the input type.
sourceimpl<'a> PartialEq<PasswordHash<'a>> for PasswordHash<'a>
impl<'a> PartialEq<PasswordHash<'a>> for PasswordHash<'a>
sourcefn eq(&self, other: &PasswordHash<'a>) -> bool
fn eq(&self, other: &PasswordHash<'a>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PasswordHash<'a>) -> bool
fn ne(&self, other: &PasswordHash<'a>) -> bool
This method tests for !=
.
sourceimpl<'a> TryFrom<&'a str> for PasswordHash<'a>
impl<'a> TryFrom<&'a str> for PasswordHash<'a>
impl<'a> Eq for PasswordHash<'a>
impl<'a> StructuralEq for PasswordHash<'a>
impl<'a> StructuralPartialEq for PasswordHash<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for PasswordHash<'a>
impl<'a> Send for PasswordHash<'a>
impl<'a> Sync for PasswordHash<'a>
impl<'a> Unpin for PasswordHash<'a>
impl<'a> UnwindSafe for PasswordHash<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more