pub struct GSecret<V: Validator = NoValidation, const MIN: usize = DEFAULT_MIN, const MAX: usize = DEFAULT_MAX, const ASCII_ONLY: bool = DEFAULT_ASCII_ONLY> { /* private fields */ }Expand description
GSecret is a type for containing secret.
Unlike GString, it’s not Copy for security reason.
No Display implementation and debugging is redacted.
It Implements zeroize and can be triggered manually or automatically on drop.
You can reveal the secret inside a closure to do something with it.
If you reveal and clone or take ownership of the revealed string, it goes beyond responsibility of GSecret to zeroize it.
Implementations§
Source§impl GSecret
impl GSecret
Sourcepub fn try_default<S>(secret: S) -> Result<Self, GStringError<Infallible>>
pub fn try_default<S>(secret: S) -> Result<Self, GStringError<Infallible>>
Construct GSecret with default generic params.
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> GSecret<V, MIN, MAX, ASCII_ONLY>
Sourcepub fn try_new<S>(secret: S) -> Result<Self, GStringError<V::Err>>
pub fn try_new<S>(secret: S) -> Result<Self, GStringError<V::Err>>
Construct GSecret with defined generic params.
Sourcepub fn reveal<R>(&self, func: impl FnOnce(&str) -> R) -> R
pub fn reveal<R>(&self, func: impl FnOnce(&str) -> R) -> R
Reveals the secret.
It’s useful if you want to do something with the secret, e.g. authentication, authorization, etc.
§WARNING
Revealing the secret will expose reference to string of the secret itself. As long as you don’t bring it outside of closure scope, it’s fine. If you bring it outside, it goes beyond responsibility of GSecret to zeroize it.
Trait Implementations§
Source§impl<V: Clone + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Clone for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Clone + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Clone for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Debug for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Debug for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<'de, V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Deserialize<'de> for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<'de, V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Deserialize<'de> for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Drop for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Drop for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> FromStr for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> FromStr for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Hash for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Hash for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<V: PartialEq + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> PartialEq for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: PartialEq + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> PartialEq for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<&str> for GSecret<V, MIN, MAX, ASCII_ONLY>
impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<&str> for GSecret<V, MIN, MAX, ASCII_ONLY>
Source§impl<GSTRINGV: Validator, GSECRETV: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<GString<GSTRINGV, MIN, MAX, ASCII_ONLY>> for GSecret<GSECRETV, MIN, MAX, ASCII_ONLY>
impl<GSTRINGV: Validator, GSECRETV: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<GString<GSTRINGV, MIN, MAX, ASCII_ONLY>> for GSecret<GSECRETV, MIN, MAX, ASCII_ONLY>
Source§impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<String> for GSecret<V, MIN, MAX, ASCII_ONLY>where
V: Validator,
Available on crate feature alloc only.
impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<String> for GSecret<V, MIN, MAX, ASCII_ONLY>where
V: Validator,
alloc only.