tc_zeroize 0.1.0

Explicit memory erasure with volatile writes and opt-in scope guards.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Erasure of an optional value before it is removed.

use crate::Zeroize;
use core::sync::atomic::{Ordering, compiler_fence};

impl<T: Zeroize> Zeroize for Option<T> {
    fn zeroize(&mut self) {
        if let Some(value) = self.as_mut() {
            value.zeroize();
        }
        // Assignment drops the cleared payload; a volatile replacement would
        // skip its destructor. Only the payload's erasure needs volatile stores.
        *self = None;
        compiler_fence(Ordering::SeqCst);
    }
}