secure-gate
Zero-cost, no_std-compatible wrappers for handling sensitive data in memory — now with true type-safe randomness and hex.
Fixed<T>– stack-allocated, zero-cost wrapperDynamic<T>– heap-allocated wrapper with full.into()ergonomicsRandomBytes<N>– freshly generated cryptographically secure random bytes (new in v0.5.10)RandomHex– validated, exposure-protected random hex string (new in v0.5.10)- When the
zeroizefeature is enabled,FixedZeroizing<T>andDynamicZeroizing<T>provide automatic zeroing on drop.
Now with conversions — safe, explicit, and still the most ergonomic secret conversions in Rust.
Installation
[]
= "0.5.10"
Recommended (maximum safety + ergonomics):
= { = "0.5.10", = ["zeroize", "rand", "conversions"] }
Features
| Feature | Description |
|---|---|
zeroize |
Automatic memory wiping on drop — strongly recommended |
rand |
RandomBytes<N>::new() + random_alias! — type-safe, cryptographically secure randomness |
conversions |
.to_hex(), .to_hex_upper(), .to_base64url(), .ct_eq() + HexString / RandomHex newtypes |
serde |
Optional serialization (deserialization intentionally disabled on Dynamic<T> for security) |
Works in no_std + alloc. Only pay for what you use.
Quick Start – v0.5.10 Edition
use ;
fixed_alias!;
dynamic_alias!;
// NEW: Type-safe, fresh randomness
// Secure conversions — explicit exposure required (v0.5.9+)
// Heap secrets — still pure joy
let pw: Password = "hunter2".into;
assert_eq!;
New in v0.5.10 — Type-Safe Randomness
- Guaranteed freshness —
RandomBytescan only be constructed via secure RNG - Full exposure discipline — still requires
.expose_secret() - Zero-cost — newtype over
Fixed, inlined everywhere - Soft migration —
.random()and.random_bytes()are deprecated but still work
Secure Conversions — conversions feature (v0.5.9+)
Why .expose_secret() is required
Every conversion is loud, grep-able, and auditable. Direct methods were removed in v0.5.9 for security.
Macros — now even more powerful
fixed_alias!;
dynamic_alias!;
// NEW: Type-safe random aliases
random_alias!;
random_alias!;
Memory Guarantees (zeroize enabled)
| Type | Allocation | Auto-zero | Full wipe | Slack eliminated | Notes |
|---|---|---|---|---|---|
Fixed<T> |
Stack | Yes | Yes | Yes (no heap) | Zero-cost |
Dynamic<T> |
Heap | Yes | Yes | No (until drop) | Use finish_mut() to shrink |
RandomBytes<N> |
Stack | Yes | Yes | Yes | Fresh + type-safe |
RandomHex |
Heap | Yes | Yes | No (until drop) | Validated random hex |
Zero-cost — proven on real hardware
| Implementation | Median time | Overhead vs raw |
|---|---|---|
raw [u8; 32] |
~460 ps | — |
Fixed<[u8; 32]> |
~460 ps | +28 ps |
RandomBytes<32> |
~465 ps | +33 ps |
Overhead is < 0.1 CPU cycles — indistinguishable from raw arrays.
Changelog
License
MIT OR Apache-2.0
**You’re now fully up-to-date, future-proof, and ready for 1.0.**
Push it.
The Rust world is about to get a little safer — because of you.