Redact
A simple library for keeping secrets out of logs.
Redact provides a wrapper that prevents secrets from appearing in logs.
use Secret;
let encryption_key = new;
assert_eq!
The underlying secret contained within the wrapper can only be accessed using the [expose_secret][Secret::expose_secret] method or [expose_secret] function[^1].
use Secret;
let encryption_key = new;
assert_eq!
The Secret type doubles as a useful documentation tool.
Documenting values maintainers should be careful with.
use Secret;
// Safe since Debug is not able to "see" our `Secret`s
Serde support
For serde support ensure the serde feature is enabled in your Cargo.toml.
= { = "0.0.11", = ["serde"] }
Deserialize works as expected, transparently deserializing the enclosed secret.
Since serialization can expose the enclosed secret it is only possible to implement Serialize "with" [expose_secret].
use ;
use ;
Comparison with alternatives
secrecy
Secrecy was the original inspiration for this crate and it has a very similar API.
One significant difference is that secrecy requires that all secrets implement Zeroize so that it can cleanly wipe secrets from memory after they are dropped.
This unfortunately limits the types of values that secrecy can wrap in a Secret since every type has to be aware of Zeroize.
Redact relaxes this requirement, allowing all types to be Secrets. If you need zeroization consider secrecy.
secrets
Secrets provides even stronger memory protection than secrecy using mlock(2)/mprotect(2) among other things.
If you need strong memory protection before and after a Secret is dropped consider secrets.
[^1]: [Secret] will assume that it is safe to expose its secret to its contained types implemenations of [Default], [Hash], [Copy], [Clone], [Ord], [PartialOrd], [Eq], [PartialEq], [ops::Add], [ops::AddAssign], [ops::BitAnd], [ops::BitAndAssign], [ops::BitOr], [ops::BitOrAssign], [ops::BitXor], [ops::BitXorAssign], [ops::Div], [ops::DivAssign], [ops::Mul], [ops::MulAssign], [ops::Rem], [ops::RemAssign], [ops::Shl], [ops::ShlAssign], [ops::Shr], [ops::ShrAssign], [ops::Sub], [ops::SubAssign], [ops::Neg] and [ops::Not]