pub struct PasswordHash<'a> {
    pub algorithm: Ident<'a>,
    pub version: Option<u32>,
    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<u32>

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§

§

impl<'a> PasswordHash<'a>

pub fn new(s: &'a str) -> Result<PasswordHash<'a>, Error>

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

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

Parse a password hash from the given Encoding.

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

Generate a password hash using the supplied algorithm.

pub fn verify_password( &self, phfs: &[&dyn PasswordVerifier], password: impl AsRef<[u8]> ) -> Result<(), Error>

Verify this password hash using the specified set of supported PasswordHasher trait objects.

pub fn encoding(&self) -> Encoding

Get the Encoding that this PasswordHash is serialized with.

pub fn serialize(&self) -> PasswordHashString

Serialize this PasswordHash as a PasswordHashString.

Trait Implementations§

§

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

§

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
§

impl<'a> Debug for PasswordHash<'a>

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Converts to this type from the input type.
§

impl From<PasswordHash<'_>> for PasswordHashString

§

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

Converts to this type from the input type.
§

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

§

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

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

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

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

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

§

type Error = Error

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

fn try_from(hash: &'a PasswordHash<'a>) -> Result<Params, Error>

Performs the conversion.
§

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

§

type Error = Error

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

fn try_from(s: &'a str) -> Result<PasswordHash<'a>, Error>

Performs the conversion.
§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more