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 a v=version format;
  • optionally, a $ sign followed by one or several parameters, each with a name=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§

source§

impl<'a> PasswordHash<'a>

source

pub fn new(s: &'a str) -> Result<Self>

Parse a password hash from a string in the PHC string format.

source

pub fn parse(s: &'a str, encoding: Encoding) -> Result<Self>

Parse a password hash from the given Encoding.

source

pub fn generate( phf: impl PasswordHasher, password: impl AsRef<[u8]>, salt: impl Into<Salt<'a>>, ) -> Result<Self>

Generate a password hash using the supplied algorithm.

source

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.

source

pub fn encoding(&self) -> Encoding

Get the Encoding that this PasswordHash is serialized with.

source

pub fn serialize(&self) -> PasswordHashString

Available on crate feature alloc only.

Serialize this PasswordHash as a PasswordHashString.

Trait Implementations§

source§

impl<'a> Clone for PasswordHash<'a>

source§

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

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<'a> Debug for PasswordHash<'a>

source§

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

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

impl<'a> Display for PasswordHash<'a>

source§

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

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

impl From<&PasswordHash<'_>> for PasswordHashString

Available on crate feature alloc only.
source§

fn from(hash: &PasswordHash<'_>) -> PasswordHashString

Converts to this type from the input type.
source§

impl From<PasswordHash<'_>> for PasswordHashString

Available on crate feature alloc only.
source§

fn from(hash: PasswordHash<'_>) -> PasswordHashString

Converts to this type from the input type.
source§

impl<'a> PartialEq for PasswordHash<'a>

source§

fn eq(&self, other: &PasswordHash<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> TryFrom<&'a str> for PasswordHash<'a>

source§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(s: &'a str) -> Result<Self>

Performs the conversion.
source§

impl<'a> Eq for PasswordHash<'a>

source§

impl<'a> StructuralPartialEq for PasswordHash<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PasswordHash<'a>

§

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§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.