secret-string
A lightweight Rust library that provides a wrapper around strings to prevent accidental exposure of sensitive data in logs, debug output, or error messages.
Overview
SecretString wraps sensitive string data and replaces it with asterisks when printed or formatted for debugging. This helps prevent accidental leakage of passwords, API keys, tokens, and other sensitive information.
Features
- Hides sensitive data when using
Displaytrait (prints as asterisks) - Hides sensitive data when using
Debugtrait (prints asSecretString(**)) - Provides explicit
.value()method to access the actual secret when needed - Zero-copy wrapper - works with any type that implements
AsRef<str> - No external dependencies
Installation
Add the package:
cargo add secret-string
Usage
Basic Example
use SecretString;
Preventing Accidental Exposure
use SecretString;
With String Slices
use SecretString;
Contributing
This library is part of the crabcakes project. Contributions are welcome.