Skip to main content

ExposedSecretString

Struct ExposedSecretString 

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

Owned secret UTF-8 text extracted from SecretBuffer.

This wrapper keeps redacted formatting, best-effort spare-capacity clearing at construction time, and best-effort full wipe on drop after a SecretBuffer is consumed for string interop. Use Self::into_exposed_unprotected_string_caller_must_zeroize only when a raw String is unavoidable and the caller will handle cleanup.

Implementations§

Source§

impl ExposedSecretString

Source

pub fn from_string(text: String) -> Self

Wraps an owned UTF-8 string as exposed secret text.

Source

pub fn len(&self) -> usize

Returns the length of the secret text in bytes.

Source

pub fn is_empty(&self) -> bool

Returns whether the secret text is empty.

Source

pub fn expose_secret(&self) -> &str

Reveals the secret text.

This method is intentionally named to make secret access explicit at the call site.

Source

pub fn expose_secret_bytes(&self) -> &[u8]

Reveals the secret text as bytes.

This method is intentionally named to make secret access explicit at the call site.

Source

pub fn into_exposed_unprotected_string_caller_must_zeroize(self) -> String

Consumes the wrapper and returns a raw String.

This is an unprotected escape hatch. The returned string is no longer redacted by formatting and will not be cleared by this crate on drop. Callers must clear it with their own approved zeroization policy.

Trait Implementations§

Source§

impl AsRef<str> for ExposedSecretString

Available on crate feature alloc only.
Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for ExposedSecretString

Available on crate feature alloc only.
Source§

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

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

impl Display for ExposedSecretString

Available on crate feature alloc only.
Source§

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

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

impl Drop for ExposedSecretString

Available on crate feature alloc only.
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

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