Skip to main content

HashParts

Struct HashParts 

Source
pub struct HashParts { /* private fields */ }
Expand description

A parsed bcrypt hash: cost, raw salt, and the 23-byte hash payload.

Obtain one from a hash string with "...".parse(), or from hashing with hash_with_result / hash_with_salt. Formatting back is Display (always $2b$) or format_for_version / write_for_version for a chosen marker.

The version marker of a parsed string is not retained: versions are labels (see Version), so re-formatting a parsed $2a$ string yields $2b$ — the same behaviour as the bcrypt crate.

Implementations§

Source§

impl HashParts

Source

pub fn get_cost(&self) -> u32

The cost parameter: bcrypt’s log2(rounds), in 4..=31.

Source

pub fn get_salt(&self) -> String

The salt, encoded in bcrypt’s base64 dialect (22 chars).

Source

pub fn get_salt_raw(&self) -> [u8; 16]

The raw 16-byte salt.

Source

pub fn get_hash(&self) -> [u8; 23]

The raw 23-byte hash payload: the 24-byte bcrypt ciphertext with its last byte dropped, exactly as the string’s hash field encodes it.

This accessor is an extension over the bcrypt crate, which exposes the payload only as an encoded string.

Source

pub fn format_for_version(&self, version: Version) -> String

The 60-byte hash string with the given version marker.

Source

pub fn write_for_version<W: Write>(&self, version: Version, w: &mut W) -> Result

Write the 60-byte hash string with the given version marker to w.

Trait Implementations§

Source§

impl Clone for HashParts

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HashParts

Source§

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

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

impl Display for HashParts

Source§

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

The 60-byte hash string in the default $2b$ spelling.

Source§

impl Eq for HashParts

Source§

impl FromStr for HashParts

Source§

fn from_str(s: &str) -> Result<Self, BcryptError>

Strict parser. Rejects — with InvalidHash naming the failing part — anything that is not exactly 60 bytes of $2v$cc$<salt><hash> with v one of a/b/x/y, two decimal cost digits in 4..=31, and both fields valid bcrypt base64:

  • "length" — not exactly 60 bytes;
  • "prefix" — bad magic, unknown version marker, or missing $;
  • "cost" — non-decimal digits or a value outside 4..=31 (an out-of-range cost in a string is a parse error; CostNotAllowed is reserved for cost arguments to hash functions, matching the bcrypt crate);
  • "salt" / "hash" — a character outside the bcrypt alphabet.

Every check compares bytes, so a non-ASCII string fails the field it lands in; no separate ASCII pass is needed.

Source§

type Err = BcryptError

The associated error which can be returned from parsing.
Source§

impl Hash for HashParts

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HashParts

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HashParts

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.