CloneableString

Type Alias CloneableString 

Source
pub type CloneableString = Dynamic<CloneableStringInner>;

Aliased Type§

pub struct CloneableString(/* private fields */);

Implementations§

Source§

impl CloneableString

Source

pub const fn expose_inner(&self) -> &String

Source

pub fn expose_inner_mut(&mut self) -> &mut String

Source

pub fn init_with<F>(constructor: F) -> Self
where F: FnOnce() -> String,

Construct a cloneable string secret by building it in a closure.

This minimizes the time the secret spends on the stack:

  • The closure builds a temporary String.
  • It is immediately cloned to the heap.
  • The temporary is zeroized before returning.

Use this when reading passwords or tokens from user input.

§Example
use secure_gate::CloneableString;
use std::io::{self, Write};

fn read_password() -> io::Result<String> {
    let mut input = String::new();
    io::stdout().flush()?;
    io::stdin().read_line(&mut input)?;
    Ok(input.trim_end().to_string())
}

let pw = CloneableString::init_with(|| read_password().unwrap());
Source

pub fn try_init_with<F, E>(constructor: F) -> Result<Self, E>
where F: FnOnce() -> Result<String, E>,

Fallible version of init_with.

Useful when construction can fail (e.g., I/O errors).

Trait Implementations§

Source§

impl From<&str> for CloneableString

Available on crate feature zeroize only.
Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CloneableString

Available on crate feature zeroize only.
Source§

fn from(value: String) -> Self

Converts to this type from the input type.