pub struct ZeroizingMutGuard<'a, T>{ /* private fields */ }Expand description
RAII guard for mutable references that automatically zeroizes on drop.
ZeroizingMutGuard wraps a mutable reference &mut T and ensures that
the referenced value is zeroized when the guard is dropped. This is useful
for protecting sensitive data during temporary operations (e.g., encryption,
decryption, signing).
§Design
- Wraps
&'a mut T(borrows the value mutably) - Implements
DerefandDerefMutfor convenient access - Zeroizes
*inneron drop via#[fast_zeroize(drop)] - Contains
ZeroizeOnDropSentinelto verify zeroization happened
§Usage
use redoubt_zero_core::{ZeroizingMutGuard, ZeroizationProbe};
let mut sensitive: u64 = 12345;
{
// Guard borrows `sensitive` and zeroizes it on drop
let mut guard = ZeroizingMutGuard::from(&mut sensitive);
*guard = 67890;
println!("Value: {}", *guard);
} // guard drops here → sensitive is zeroized
assert!(sensitive.is_zeroized());§Composition with Temporary Data
ZeroizingMutGuard is useful for wrapping sensitive temporary data:
ⓘ
use redoubt_zero_core::ZeroizingMutGuard;
struct Context<'a> {
key: ZeroizingMutGuard<'a, [u8; 32]>,
nonce: ZeroizingMutGuard<'a, [u8; 16]>,
}
impl Drop for Context<'_> {
fn drop(&mut self) {
// key and nonce auto-zeroize when guards drop
}
}§Panics
The guard panics on drop if the wrapped value’s ZeroizeOnDropSentinel was not
marked as zeroized. This ensures zeroization invariants are enforced.
Implementations§
Source§impl<'a, T> ZeroizingMutGuard<'a, T>
impl<'a, T> ZeroizingMutGuard<'a, T>
Sourcepub fn from(inner: &'a mut T) -> Self
pub fn from(inner: &'a mut T) -> Self
Creates a new guard wrapping a mutable reference.
The guard takes ownership of the mutable reference and will zeroize the referenced value when dropped.
§Example
use redoubt_zero_core::ZeroizingMutGuard;
let mut value: u32 = 42;
let guard = ZeroizingMutGuard::from(&mut value);
assert_eq!(*guard, 42);Trait Implementations§
Source§impl<'a, T> AssertZeroizeOnDrop for ZeroizingMutGuard<'a, T>
impl<'a, T> AssertZeroizeOnDrop for ZeroizingMutGuard<'a, T>
Source§fn clone_sentinel(&self) -> ZeroizeOnDropSentinel
fn clone_sentinel(&self) -> ZeroizeOnDropSentinel
Clones the internal
ZeroizeOnDropSentinel for verification. Read moreSource§fn assert_zeroize_on_drop(self)
fn assert_zeroize_on_drop(self)
Asserts that zeroization happens when this value is dropped. Read more
Source§impl<'a, T> Debug for ZeroizingMutGuard<'a, T>
impl<'a, T> Debug for ZeroizingMutGuard<'a, T>
Source§impl<'a, T> Deref for ZeroizingMutGuard<'a, T>
impl<'a, T> Deref for ZeroizingMutGuard<'a, T>
Source§impl<'a, T> DerefMut for ZeroizingMutGuard<'a, T>
impl<'a, T> DerefMut for ZeroizingMutGuard<'a, T>
Source§impl<'a, T> Drop for ZeroizingMutGuard<'a, T>
impl<'a, T> Drop for ZeroizingMutGuard<'a, T>
Source§impl<'a, T> FastZeroizable for ZeroizingMutGuard<'a, T>
impl<'a, T> FastZeroizable for ZeroizingMutGuard<'a, T>
Source§fn fast_zeroize(&mut self)
fn fast_zeroize(&mut self)
Zeroizes the value in place. Read more
Source§impl<'a, T> ZeroizationProbe for ZeroizingMutGuard<'a, T>
impl<'a, T> ZeroizationProbe for ZeroizingMutGuard<'a, T>
Source§fn is_zeroized(&self) -> bool
fn is_zeroized(&self) -> bool
Returns
true if the value is zeroized (all bytes are 0). Read moreAuto Trait Implementations§
impl<'a, T> Freeze for ZeroizingMutGuard<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for ZeroizingMutGuard<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> Send for ZeroizingMutGuard<'a, T>
impl<'a, T> Sync for ZeroizingMutGuard<'a, T>
impl<'a, T> Unpin for ZeroizingMutGuard<'a, T>where
T: ?Sized,
impl<'a, T> !UnwindSafe for ZeroizingMutGuard<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more