pub struct Password(/* private fields */);Expand description
A password used to unlock a Keystore.
The password is stored in a Zeroizing<Vec<u8>>; the underlying memory is
wiped when the Password is dropped. Password is Clone so callers may
retain a copy for later use (e.g., re-locking with the same password);
both copies are zeroized on drop.
§Construction
Use any of the From impls:
use dig_keystore::Password;
let from_str: Password = Password::from("abc");
let from_string: Password = Password::from(String::from("abc"));
let from_slice: Password = Password::from(b"abc".as_slice());
let from_vec: Password = Password::from(b"abc".to_vec());
let from_new: Password = Password::new(b"abc");§UTF-8 vs arbitrary bytes
Password accepts arbitrary byte sequences. Argon2id hashes raw bytes, so
non-UTF-8 passwords work. The optional password-strength feature (which
wires zxcvbn) requires UTF-8 and falls back to
an empty-string score for non-UTF-8 bytes.
Implementations§
Source§impl Password
impl Password
Sourcepub fn new(bytes: impl AsRef<[u8]>) -> Self
pub fn new(bytes: impl AsRef<[u8]>) -> Self
Wrap any byte sequence as a Password.
Copies the input bytes into a freshly-allocated zeroizing buffer. The
caller’s original bytes are not wiped — callers managing particularly
sensitive memory should zeroize the source themselves after passing it
to Password::new.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Borrow the raw password bytes. The returned slice is valid only while
the Password is alive.
Used internally by kdf to feed Argon2id. External callers
generally should not need this — prefer handing the Password to a
Keystore method.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the password is zero bytes long.
Empty passwords are permitted by the library (Argon2id will hash them), but they are trivially brute-forced. Treat as an operator error.
Sourcepub fn strength(&self) -> Entropy
pub fn strength(&self) -> Entropy
Return a zxcvbn strength estimate for CLI
helpers.
Returns an entropy score 0–4 with feedback suggestions. This is a very rough estimate designed for UX prompts, not a cryptographic guarantee. Non-UTF-8 passwords are scored as the empty string (conservative).
Only available with the password-strength feature.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Password
impl RefUnwindSafe for Password
impl Send for Password
impl Sync for Password
impl Unpin for Password
impl UnsafeUnpin for Password
impl UnwindSafe for Password
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more