pub type CloneableString = Dynamic<CloneableStringInner>;Aliased Type§
pub struct CloneableString(/* private fields */);Implementations§
Source§impl CloneableString
impl CloneableString
pub const fn expose_inner(&self) -> &String
pub fn expose_inner_mut(&mut self) -> &mut String
Sourcepub fn init_with<F>(constructor: F) -> Self
pub fn init_with<F>(constructor: F) -> Self
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());Trait Implementations§
Source§impl From<&str> for CloneableString
Available on crate feature zeroize only.
impl From<&str> for CloneableString
Available on crate feature
zeroize only.