Trait ExposeSecret

Source
pub trait ExposeSecret<'max, T, MEC: Unsigned, EC: Unsigned>: Sized {
    type Exposed<'brand>
       where 'max: 'brand;
    type Next: ExposeSecret<'max, T, MEC, Sum<EC, U1>>
       where EC: Add<U1> + Unsigned + IsLessOrEqual<MEC, Output = True>,
             Sum<EC, U1>: Unsigned + IsLessOrEqual<MEC, Output = True> + Add<U1>;

    // Required method
    fn expose_secret<ReturnType, ClosureType>(
        self,
        scope: ClosureType,
    ) -> (Self::Next, ReturnType)
       where for<'brand> ClosureType: FnOnce(Self::Exposed<'brand>) -> ReturnType,
             EC: Add<U1> + IsLessOrEqual<MEC, Output = True>,
             Sum<EC, U1>: Unsigned + Add<U1> + IsLessOrEqual<MEC, Output = True>;
}
Expand description

A trait for safely exposing secrets with a limited exposure count.

The ExposeSecret trait provides a mechanism to progressively expose a secret value in a controlled manner, with an invariant lifetime and compile-time guarantees. It allows for limiting the exposure of a secret to a maximum count (MEC). The exposure count (EC) is tracked at compile time to ensure that it does not exceed the specified maximum count.

§Type Parameters

  • 'max: A lifetime parameter indicating the lifetime of the value of the type that implements this trait.
  • T: The type of the secret being exposed.
  • MEC: A type-level unsigned integer (with typenum::Unsigned trait bound) representing the maximum exposure count.
  • EC: A type-level unsigned integer (with typenum::Unsigned trait bound) representing the current exposure count.

Required Associated Types§

Source

type Exposed<'brand> where 'max: 'brand

A wrapper type representing the exposed secret. It is associated with a lifetime 'brand, indicating the lifetime of the wrapper type, which is strictly a subtype of 'max,

Source

type Next: ExposeSecret<'max, T, MEC, Sum<EC, U1>> where EC: Add<U1> + Unsigned + IsLessOrEqual<MEC, Output = True>, Sum<EC, U1>: Unsigned + IsLessOrEqual<MEC, Output = True> + Add<U1>

The Secret<T, _, _> with an incremented count (i.e. EC) after exposing the secret. It is a new value of a type which implements the same trait, namely, ExposeSecret with an incremented exposure count, i.e. the new EC = previous EC + 1.

Required Methods§

Source

fn expose_secret<ReturnType, ClosureType>( self, scope: ClosureType, ) -> (Self::Next, ReturnType)
where for<'brand> ClosureType: FnOnce(Self::Exposed<'brand>) -> ReturnType, EC: Add<U1> + IsLessOrEqual<MEC, Output = True>, Sum<EC, U1>: Unsigned + Add<U1> + IsLessOrEqual<MEC, Output = True>,

Exposes the secret and returns the Secret<T, _, _> with an incremented count (i.e. EC), along with the result of a provided closure. It is impossible to return Self::Exposed associated type out from the closure scope.

§Parameters
  • self.
  • scope: A closure (of the type given by the type parameter ClosureType) that takes the exposed secret, of type Exposed<'brand> and returns a result, of type ReturnType.

Returns (Self::Next, ReturnType)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'max, T: Zeroize, MEC: Unsigned, EC: Add<U1> + Unsigned + IsLessOrEqual<MEC, Output = True>> ExposeSecret<'max, &'max T, MEC, EC> for Secret<T, MEC, EC>

Source§

type Exposed<'brand> = ExposedSecret<'brand, &'brand T> where 'max: 'brand

Source§

type Next = Secret<T, MEC, <EC as Add<UInt<UTerm, B1>>>::Output> where EC: Add<U1> + Unsigned + IsLessOrEqual<MEC, Output = True>, Sum<EC, U1>: Unsigned + IsLessOrEqual<MEC, Output = True> + Add<U1>