reliakit-secret
Secret-safe wrappers for Rust values that should not leak through formatting or diagnostics.
reliakit-secret provides Secret<T>, a small wrapper that redacts its inner
value in Debug and Display output. Access to the wrapped value is explicit
through ExposeSecret.
The crate has no dependencies and forbids unsafe code.
What This Crate Does
This crate helps prevent accidental secret leaks in logs, error messages, debug output, and diagnostic reports.
Instead of passing a raw password, token, or API key through a public API, wrap it
as a Secret<T>:
use ;
What This Crate Does Not Do
This crate does not provide memory zeroization, encryption, process isolation, or protection against memory inspection. It is a formatting and diagnostics safety primitive.
Installation
[]
= "0.1"
For no_std without allocation:
[]
= { = "0.1", = false }
For no_std with string-backed secrets:
[]
= { = "0.1", = false, = ["alloc"] }
Examples
Generic secret
use ;
let token = new;
assert_eq!;
assert_eq!;
assert_eq!;
String-backed secret
use ;
let password = from_string;
assert_eq!;
assert_eq!;
assert_eq!;
Consuming a secret
use Secret;
let secret = new;
let token = secret.into_inner;
assert_eq!;
Redacting a field inside a struct
The common case: a secret living in a config or request struct. Because
Secret<T> redacts itself, deriving Debug on the parent stays safe — the
secret field shows [REDACTED] and the rest prints normally, so you can log the
whole struct.
use SecretString;
let cfg = DbConfig ;
let rendered = format!;
assert!;
assert!;
assert!;
Constant-time comparison
Checking a presented value against a stored secret with == on the exposed
bytes can leak the secret through timing. ct_eq compares in time that does not
depend on how many leading bytes match (best-effort, dependency-free; it depends
only on the input length, not the contents).
use SecretString;
let stored = from_string;
assert!;
assert!;
Available Types
| Type | Description |
|---|---|
Secret<T> |
Generic wrapper that redacts Debug and Display |
SecretString |
String-backed secret, available with std or alloc |
ExposeSecret<T> |
Trait for explicit shared access |
ExposeSecretMut<T> |
Trait for explicit mutable access |
Secret<T> where the value is byte-viewable (String, Vec<u8>, &[u8],
[u8; N], ...) also has ct_eq for constant-time comparison.
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
yes | Enables the standard library |
alloc |
no | Enables SecretString without std |
no_std
The crate supports no_std.
Generic Secret<T> works without allocation. SecretString requires alloc or
std.
Safety
This crate is #![forbid(unsafe_code)].
Minimum Supported Rust Version
Rust 1.85 and newer. No nightly features are used.
Status
Active. The crate is intentionally small and focused on formatting-safe secret wrappers.
License
Licensed under the MIT License.