Crate opaque_debug
source ·Expand description
Macro for opaque Debug
trait implementation.
In many cases it’s convenient to have Debug
implementation for all crate types,
e.g. to allow deriving of Debug
in user-defined structs. But at the same time, using
the default derive macro can be a security hazard since it cause leaking of sensitive
information, for example, through uncareful logging.
This crate introduces the implement!
macro which creates an opaque Debug
implementation, which does not expose any internal type data.
§Examples
pub struct CryptoStuff {
key: [u8; 16],
}
opaque_debug::implement!(CryptoStuff);
let val = CryptoStuff { key: [42; 16] };
assert_eq!(format!("{:?}", val), "CryptoStuff { ... }")
The macro also support generic paramters:
pub struct GenricCryptoStuff<K> {
key: K,
}
opaque_debug::implement!(GenricCryptoStuff<K>);
let val = GenricCryptoStuff { key: [42u8; 16] };
assert_eq!(format!("{:?}", val), "GenricCryptoStuff<[u8; 16]> { ... }")
Macros§
- Macro for implementing an opaque
Debug
implementation.