Skip to main content

Passphrase

Struct Passphrase 

Source
#[non_exhaustive]
pub struct Passphrase(/* private fields */);
Expand description

A passphrase held in a buffer that is wiped when the value drops.

Every operation that takes a passphrase consumes a Passphrase: Encryptor::with_passphrase, PassphraseDecryptor::decrypt, PrivateKey::from_key_file, KeyPairGenerator::with_passphrase, and generate_key_pair.

The text is readable only inside the crate. There is no public accessor, Debug prints Passphrase(<redacted>), and the type implements neither Display nor Clone, so a passphrase cannot leak through formatting and each operation consumes a value built for it.

Wiping covers the buffer this value owns. A copy that existed before construction — a prompt library’s buffer, a String the caller still holds — is outside its reach, so build the Passphrase as early as practical and let the source value drop. The wipe also acts only inside this process: it cannot stop the operating system from paging the memory to swap or including it in a crash dump while the value is alive.

There is no way to derive a second value from one secret. A caller that needs the same passphrase for two operations reads it from its source again for each; holding the text in a String between them would leave a copy this type cannot wipe.

Implementations§

Source§

impl Passphrase

Source

pub fn new(text: impl Into<String>) -> Self

Takes ownership of the passphrase text.

Accepts a String or &str; passing an owned String moves it into the wiped buffer without an extra copy of the secret. The length bound of 1 to 4,096 bytes is checked by the operation that uses the passphrase, not here; construction is infallible.

Trait Implementations§

Source§

impl Debug for Passphrase

Source§

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

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.