1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use Zeroize;
/// Overwrites a byte buffer with zeros in a way that cannot be optimized away.
///
/// Uses the [`Zeroize`] trait from the `zeroize` crate to guarantee that the
/// memory is cleared even in release builds. This is essential for securely
/// erasing sensitive material such as secret keys from memory.
///
/// # Parameters
///
/// * `data` – A mutable byte slice whose contents will be zeroized.
///
/// # Examples
///
/// ```rust
/// use age_setup::security::wipe_memory;
///
/// let mut secret = vec![1, 2, 3, 4];
/// wipe_memory(&mut secret);
/// assert_eq!(secret, vec![0, 0, 0, 0]);
/// ```
///
/// Empty buffers are handled gracefully:
///
/// ```rust
/// use age_setup::security::wipe_memory;
///
/// let mut empty: Vec<u8> = vec![];
/// wipe_memory(&mut empty);
/// assert_eq!(empty, vec![]);
/// ```
///
/// # See Also
///
/// * [`SecretKey`](crate::SecretKey) – Uses `Zeroizing` for automatic cleanup.
/// * [`zeroize`](https://docs.rs/zeroize) – The underlying crate.