SecureString

Type Alias SecureString 

Source
pub type SecureString = SecretString;
Expand description

A secure string that automatically zeros its memory on drop.

This is a type alias for secrecy::SecretString, which provides:

  • Automatic memory zeroing on drop
  • Prevention of accidental logging via Debug/Display
  • Industry-standard security practices

§Security

The contained data is automatically zeroed when the value is dropped, using the zeroize crate which provides compiler-fence-backed guarantees that the zeroing operation won’t be optimized away.

§Usage

Access the underlying string using .expose_secret():

use api_keys_simplified::SecureString;
use api_keys_simplified::ExposeSecret;

let secret = SecureString::from("my_secret".to_string());
let value: &str = secret.expose_secret();

§Design: Why No Deref<Target=str>?

This type intentionally does NOT implement Deref to maintain security:

  • Explicit access: Requires .expose_secret() call, making code auditable
  • Prevents silent leakage: No implicit coercion to &str in logs/errors
  • Grep-able security: Easy to audit with git grep "\.expose_secret\(\)"
  • **Industry standard**: Uses the battle-tested secrecy` crate

Aliased Type§

pub struct SecureString { /* private fields */ }

Trait Implementations§

Source§

impl SecureStringExt for SecureString

Source§

fn len(&self) -> usize

Returns the length of the string in bytes.
Source§

fn is_empty(&self) -> bool

Returns true if the string is empty.
Source§

fn eq(&self, other: &Self) -> bool

Constant time eq