Skip to main content

GSecret

Struct GSecret 

Source
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

Source

pub fn try_default<S>(secret: S) -> Result<Self, GStringError<Infallible>>
where S: AsRef<str>,

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>

Source

pub fn try_new<S>(secret: S) -> Result<Self, GStringError<V::Err>>
where S: AsRef<str>,

Construct GSecret with defined generic params.

Source

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.

Source

pub fn zeroize(&mut self)

Manually zeroize the secret.

It’s useful if you want to zeroize before the secret is out-of-scope/dopped.

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>

Source§

fn clone(&self) -> GSecret<V, MIN, MAX, ASCII_ONLY>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Debug for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Drop for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> FromStr for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

type Err = GStringError<<V as Validator>::Err>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Hash for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<V: PartialEq + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> PartialEq for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

fn eq(&self, other: &GSecret<V, MIN, MAX, ASCII_ONLY>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> TryFrom<&str> for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

type Error = GStringError<<V as Validator>::Err>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
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>

Source§

type Error = GStringError<<GSECRETV as Validator>::Err>

The type returned in the event of a conversion error.
Source§

fn try_from( value: GString<GSTRINGV, MIN, MAX, ASCII_ONLY>, ) -> Result<Self, Self::Error>

Performs the conversion.
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.
Source§

type Error = GStringError<<V as Validator>::Err>

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Zeroize for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: Validator,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<V: Eq + Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Eq for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

impl<V: Validator, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> StructuralPartialEq for GSecret<V, MIN, MAX, ASCII_ONLY>

Source§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> ZeroizeOnDrop for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: Validator,

Auto Trait Implementations§

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Freeze for GSecret<V, MIN, MAX, ASCII_ONLY>

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> RefUnwindSafe for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: RefUnwindSafe,

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Send for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: Send,

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Sync for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: Sync,

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> Unpin for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: Unpin,

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> UnsafeUnpin for GSecret<V, MIN, MAX, ASCII_ONLY>

§

impl<V, const MIN: usize, const MAX: usize, const ASCII_ONLY: bool> UnwindSafe for GSecret<V, MIN, MAX, ASCII_ONLY>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,