Skip to main content

Password

Struct Password 

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

A password whose backing memory is securely zeroed when dropped.

This newtype is the primary way to pass passwords into hash, hash_with_salt, and verify. By accepting Password by value, the API guarantees that the caller’s plaintext copy is destroyed (via crypto::secure_zero_bytes()) before the function returns, even on panic.

§Examples

use crypt_sha512::{hash, verify, Password};

let h = hash(Password::from("hunter2"), None);
assert_eq!(verify(Password::from("hunter2"), &h), Ok(true));

Password deliberately does not implement Clone, Debug, or core::fmt::Display to discourage accidental duplication or logging of plaintext secrets.

Implementations§

Source§

impl Password

Source

pub fn from_bytes(bytes: Vec<u8>) -> Self

Construct a Password from raw bytes. The provided Vec<u8> is moved into the Password and will be zeroed when the Password is dropped.

Trait Implementations§

Source§

impl Debug for Password

Source§

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

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

impl Drop for Password

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<&str> for Password

Source§

fn from(s: &str) -> Self

Copy the string slice into a new Password. The copy will be zeroed on drop, but the caller’s original &str is unaffected — prefer Password::from(String) when you own the buffer.

Source§

impl From<String> for Password

Source§

fn from(s: String) -> Self

Move a String’s buffer into a Password. The original String’s allocation becomes the Password’s allocation; no copy is made and the buffer will be zeroed on drop.

Source§

impl From<Vec<u8>> for Password

Source§

fn from(bytes: Vec<u8>) -> Self

Converts to this type from the input type.

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