zeroize 0.1.2

(Alpha quality preview) Securely zero memory while avoiding compiler optimizations: unified 'secure_zero_memory()' wrapper for secure intrinsic functions for zeroing memory, using FFI to invoke OS intrinsics on stable (with support for Linux, Windows, OS X/iOS, FreeBSD, OpenBSD, NetBSD, DragonflyBSD), or the unstable 'volatile_set_memory()` intrinsic on nightly. No insecure fallbacks, no dependencies, no std, no functionality besides securely zeroing memory.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// Zero out memory using `explicit_memset()`.
///
/// The `explicit_memset()` is a non-standard function which performs the
/// same task as `memset()`, but differs in that it guarantees that compiler
/// optimizations will not remove the operation if the compiler deduces that
/// it is "unnecessary".
pub fn secure_zero_memory(bytes: &mut [u8]) {
    #[link(name = "c")]
    extern "C" {
        fn explicit_memset(dest: *mut u8, byte: isize, n: usize);
    }

    unsafe {
        explicit_memset(bytes.as_mut_ptr(), 0, bytes.len());
    }
}