Expand description
§Shroud
Secure memory management with mlock, guard pages, and automatic zeroization.
shrouded provides types for storing secrets in protected memory that is:
- Locked to RAM (mlock/VirtualLock) to prevent swapping to disk
- Guard-paged to catch buffer overflows/underflows
- Excluded from core dumps (MADV_DONTDUMP on Linux)
- Automatically zeroized on drop using volatile writes
§Quick Start
use shrouded::{ShroudedString, Expose};
// Create a protected secret from a String (original is zeroized)
let password = String::from("hunter2");
let secret = ShroudedString::new(password).unwrap();
// Access the secret when needed
assert_eq!(secret.expose(), "hunter2");
// Secret is automatically zeroized when dropped§Types
ShroudedBytes: Dynamic-size protected byte bufferShroudedString: UTF-8 string with protected storageShroudedArray<N>: Fixed-size protected arrayShroud<T>: Generic protected box for anyZeroizetype
§Policy
Control how memory protection failures are handled with Policy:
BestEffort(default): Attempt protection, fall back gracefullyStrict: Require all protection to succeed, error on failureDisabled: Skip protection (still zeroizes on drop)
use shrouded::{ShroudBuilder, Policy};
let mut key = [0x42u8; 32];
let secret = ShroudBuilder::new()
.policy(Policy::Strict)
.build_bytes(&mut key)
.unwrap();§Features
mlock(default): Enable memory lockingguard-pages(default): Enable guard pagesserde: Enable deserialize support (never serialize!)
§Security Considerations
- Secrets are protected from being swapped to disk
- Guard pages help detect buffer overflows
- Debug output shows
[REDACTED]instead of secret data - No
Displayimpl - must explicitly call.expose() - No
Cloneimpl - must explicitly call.try_clone() - Serde only implements
Deserialize, neverSerialize
Structs§
- Expose
Guard - A guard that provides temporary access to protected memory.
- Expose
Guard Mut - A mutable guard that provides temporary write access to protected memory.
- Shroud
- A generic protected box for any type implementing
Zeroize. - Shroud
Builder - A builder for creating shrouded types with custom configuration.
- Shrouded
Array - A fixed-size protected byte array.
- Shrouded
Bytes - A dynamic-size protected byte buffer.
- Shrouded
String - A UTF-8 string stored in protected memory.
Enums§
- Policy
- Policy controlling how memory protection failures are handled.
- Shroud
Error - Errors that can occur during protected memory operations.
Traits§
- Expose
- Trait for types that can expose their protected contents as an immutable reference.
- Expose
Guarded - Trait for types that support guarded access with automatic re-locking.
- Expose
Guarded Mut - Trait for types that support mutable guarded access with automatic re-locking.
- Expose
Mut - Trait for types that can expose their protected contents as a mutable reference.
- Zeroize
- Trait for securely erasing values from memory.
Type Aliases§
- Result
- Result type alias for shrouded operations.
Derive Macros§
- Zeroize
- Derive the
Zeroizetrait.