secure_zeroizing

Macro secure_zeroizing 

Source
macro_rules! secure_zeroizing {
    ($ty:ty, $expr:expr $(,)?) => { ... };
    (heap $ty:ty, $expr:expr $(,)?) => { ... };
}
Expand description

Creates a zeroizing secret that automatically wipes itself on drop.

Requires the zeroize feature.

§Examples

use secure_gate::secure_zeroizing;

#[cfg(feature = "zeroize")]
{
    use zeroize::Zeroizing;
    use secrecy::ExposeSecret;

    // Fixed-size zeroizing secret (uses zeroize::Zeroizing directly)
    let key: Zeroizing<[u8; 32]> = secure_zeroizing!([u8; 32], [42u8; 32]);
    assert_eq!(key[..], [42u8; 32]);

    // Heap-allocated zeroizing secret
    let pw = secure_zeroizing!(heap String, "hunter2".to_string().into_boxed_str());
    assert_eq!(pw.expose_secret(), "hunter2");
}