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
impl HashParts
Sourcepub fn get_salt_raw(&self) -> [u8; 16]
pub fn get_salt_raw(&self) -> [u8; 16]
The raw 16-byte salt.
Sourcepub fn get_hash(&self) -> [u8; 23]
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.
Sourcepub fn format_for_version(&self, version: Version) -> String
pub fn format_for_version(&self, version: Version) -> String
The 60-byte hash string with the given version marker.
Trait Implementations§
impl Eq for HashParts
Source§impl FromStr for HashParts
impl FromStr for HashParts
Source§fn from_str(s: &str) -> Result<Self, BcryptError>
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 outside4..=31(an out-of-range cost in a string is a parse error;CostNotAllowedis reserved for cost arguments to hash functions, matching thebcryptcrate);"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.