Expand description
§secure-gate: Zero-cost secure wrappers for secrets
This crate provides safe, ergonomic wrappers for handling sensitive data in memory with zero runtime overhead. It supports both stack-allocated fixed-size secrets and heap-allocated dynamic secrets, with optional automatic zeroing on drop.
Key components:
Fixed<T>: Stack-allocated for fixed-size secrets (e.g., keys, nonces).Dynamic<T>: Heap-allocated for dynamic secrets (e.g., passwords, vectors).- Zeroizing variants:
FixedZeroizing<T>andDynamicZeroizing<T>for auto-wiping (withzeroizefeature). - Macros:
fixed_alias!,dynamic_alias!,secure!,secure_zeroizing!for ergonomic usage.
§Features
zeroize: Enables automatic memory wiping on drop viazeroizeandsecrecy.rand: Enables [SecureRandomExt::random()] for generating fixed-size secrets.serde: Optional serialization support (deserialization disabled forDynamic<T>for security).- Works in
no_std+allocenvironments.
§Quick Start
use secure_gate::{dynamic_alias, fixed_alias, Dynamic, Fixed};
fixed_alias!(Aes256Key, 32);
dynamic_alias!(Password, String);
let key: Aes256Key = [42u8; 32].into();
let pw: Password = "hunter2".into();
assert_eq!(key.expose_secret()[0], 42);
assert_eq!(pw.expose_secret(), "hunter2");See individual modules for detailed documentation.
Macros§
- dynamic_
alias - Defines a type alias for a dynamic (heap-allocated) secret.
- fixed_
alias - Defines a type alias for a fixed-size byte secret.
- secure
- Creates a secret wrapper around the given value.
- secure_
zeroizing - Creates a zeroizing secret that automatically wipes itself on drop.
Structs§
- Dynamic
- A zero-cost, heap-allocated wrapper for sensitive data.
- Dynamic
Zeroizing - Zeroizing wrapper for heap-allocated secrets.
- Fixed
- A zero-cost, stack-allocated wrapper for sensitive data.
Traits§
- Zeroize
- Trait for securely erasing values from memory.
- Zeroize
OnDrop - Marker trait signifying that this type will
Zeroize::zeroizeitself onDrop.
Type Aliases§
- Fixed
Zeroizing - Re-export of
zeroize::Zeroizing<T>for stack-allocated secrets. - Zeroizing
Derive Macros§
- Zeroize
- Derive the
Zeroizetrait. - Zeroize
OnDrop - Derive the
ZeroizeOnDroptrait.