docs.rs failed to build secret-box-0.1.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
secret-box
Safe boxing mechanism for sensitive values in Rust.
Core features
- Explicit secret access via
ExposeSecrettrait - makes secret access auditable in code reviews - Automatic memory zeroization on drop using the
zeroizecrate - Debug redaction prevents accidental logging of secrets
- Optional serde support with opt-in serialization to prevent accidental secret exfiltration
Installation
[]
= "0.1"
# with serde support
# [dependencies]
# secret-box = { version = "0.1", features = ["serde"] }
Basic Usage
use ;
// Create a secret password
let password: = new;
// Access requires explicit expose_secret()
println!;
// Debug output is redacted
println!; // Prints: SecretBox<String>([REDACTED])
// Secret is automatically zeroized when dropped
API Overview
SecretBox<S>
The main wrapper type for secrets. Generic over any type that implements Zeroize.
// From pre-boxed value
let secret = new;
// Initialize in-place on heap (safest method)
let secret: = init_with_mut;
// From String or Vec<u8> directly
let secret: = "password".to_string.into;
let secret: = vec!.into;
ExposeSecret<S>
Trait for accessing the secret value. This is the only way to access the secret, making secret access explicit and auditable.
use ExposeSecret;
let secret = new;
let value: &String = secret.expose_secret;
Serde Support
With the serde feature enabled:
- Deserialization:
SecretBox<T>can be deserialized from any type that implementsDeserializeOwned - Serialization: Requires implementing the
SerializableSecretmarker trait to prevent accidental secret exfiltration
use ;
use ;
// Deserialize secrets from config
let json = r#"{"api_key":"secret123"}"#;
let config: Config = from_str.unwrap;
// Note: SecretBox<String> cannot be serialized without implementing SerializableSecret
// This prevents accidental secret leakage via serialization
License
Apache-2.0