4 ms·
Not my crate, but I'll plug secrecy[1] as a better alternative to calling `zeroize()` manually on each variable containing secret material. That provides `Secre
by woodruffw 5y ago
Not my crate, but I'll plug secrecy[1] as a better alternative to calling `zeroize()` manually on each variable containing secret material. That provides `Secret<S: Zeroize>`, which provides reliable zero-on-drop semantics.
[1]: https://docs.rs/secrecy/latest/secrecy/ https://docs.rs/secrecy/latest/secrecy/
- stouset 5y agoAlternatively, 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