4 ms·
Alternatively, you could use secrets[1] (full disclosure, I'm the author). The secrecy crate does very little to prevent you from accidentally creating copies o
by stouset 5y ago
Alternatively, you could use secrets[1] (full disclosure, I'm the author). The secrecy crate does very little to prevent you from accidentally creating copies of secret data. Additionally, my crate punts to libsodium's memory management[2] API so provides all the features it does: memory is prevented from being paged to disk, memory is protected by `mprotect` when not being accessed, memory is protected with guard pages before and after, and memory is preceded by a canary to protect against underflow. secrets' functionality and protections are essentially a superset of secrecy's.
Additionally, there's support for stack-allocated secrets which lack some of the extra protections that heap-allocated secrets have, but is often a much more appropriate approach for short-lived secrets.
A downside of this is that it relies on unsafe code in order to call into libsodium and convert back and forth between pointers. And of course it has a libsodium dependency.
1: https://docs.rs/secrets/latest/secrets/ https://docs.rs/secrets/latest/secrets/
2: https://doc.libsodium.org/memory_management https://doc.libsodium.org/memory_management