Skip to content

Commit

Permalink
implement Display for SecretGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyob94 committed Sep 14, 2024
1 parent a3b7ed7 commit 5a8b039
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use core::{
any,
fmt::{self, Debug},
};
use std::ops::{Deref, DerefMut};
use std::{
fmt::Display,
ops::{Deref, DerefMut},
};
use std::{mem::size_of_val, str::FromStr};

#[cfg(unix)]
Expand All @@ -24,7 +27,7 @@ use libc::{mlock, munlock, sysconf, _SC_PAGESIZE};
use libc::{madvise, MADV_DODUMP, MADV_DONTDUMP};

pub use zeroize;
use zeroize::{Zeroize, ZeroizeOnDrop};
pub use zeroize::{Zeroize, ZeroizeOnDrop};

/// Wrapper for the inner secret. Can be exposed by [`ExposeSecret`]
pub struct SecretBox<S: Zeroize> {
Expand Down Expand Up @@ -225,6 +228,12 @@ where
data: &'a S,
}

impl<S: Display + Zeroize> Display for SecretGuard<'_, S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.data)
}
}

impl<S> Deref for SecretGuard<'_, S>
where
S: Zeroize,
Expand Down

0 comments on commit 5a8b039

Please sign in to comment.