pub struct SecurePassword(/* private fields */);Expand description
A wrapper for sensitive password data that clears itself on drop.
SecurePassword provides a secure container for password strings that
automatically clears the password from memory when the wrapper is dropped.
This prevents passwords from lingering in memory where they could be
extracted by memory inspection attacks.
§Security Properties
- Zeroization: Password bytes are overwritten with zeros on drop
- Debug Safety: Debug output shows
[REDACTED]instead of the password - Clone Safety: Cloning creates a new secure copy (both are zeroized independently)
§Thread Safety
SecurePassword is Send and can be moved between threads. It is also
Clone, creating independent copies that are each zeroized on drop.
§Example
use vanguards_rs::SecurePassword;
// Create a secure password
let password = SecurePassword::new("my_secret_password".to_string());
// Access the password when needed
assert_eq!(password.as_str(), "my_secret_password");
// Debug output is safe
let debug = format!("{:?}", password);
assert!(debug.contains("REDACTED"));
assert!(!debug.contains("my_secret"));
// Password is automatically cleared when dropped
drop(password);§See Also
Vanguards::from_config- Uses SecurePassword internallyzeroize- The underlying zeroization library
Implementations§
Source§impl SecurePassword
impl SecurePassword
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns a reference to the password string.
§Security Note
The returned reference is valid only while the SecurePassword exists.
Avoid storing this reference or converting it to an owned String,
as that would defeat the purpose of secure password handling.
§Example
use vanguards_rs::SecurePassword;
let password = SecurePassword::new("secret123".to_string());
assert_eq!(password.as_str(), "secret123");Trait Implementations§
Source§impl Clone for SecurePassword
impl Clone for SecurePassword
Source§fn clone(&self) -> SecurePassword
fn clone(&self) -> SecurePassword
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SecurePassword
impl Debug for SecurePassword
Auto Trait Implementations§
impl Freeze for SecurePassword
impl RefUnwindSafe for SecurePassword
impl Send for SecurePassword
impl Sync for SecurePassword
impl Unpin for SecurePassword
impl UnwindSafe for SecurePassword
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more