pub type SecrecySecret<T> = RTSecret<T, NumericalZeroSizedType>;Expand description
A convenience alias for RTSecret with a secret of type T that does not conduct any exposure count checking, i.e. the secret can be exposed infinitely many times.
It is meant to function almost identically to secrecy::Secret, except that the signature of .expose_secret(...) method is different.
Aliased Type§
pub struct SecrecySecret<T>(/* private fields */);Trait Implementations§
Source§impl<'secret, T: Zeroize> RTExposeSecret<'secret, &'secret T> for SecrecySecret<T>
impl<'secret, T: Zeroize> RTExposeSecret<'secret, &'secret T> for SecrecySecret<T>
Source§fn expose_secret<ReturnType, ClosureType>(
&self,
scope: ClosureType,
) -> ReturnType
fn expose_secret<ReturnType, ClosureType>( &self, scope: ClosureType, ) -> ReturnType
Exposes the secret without any runtime checking that the exposure count is not more than the maximally allowed exposure count represented by the type parameter MEC.
Note: It is impossible to return the ‘exposed secret’ as the return value of the closure.
Example:
use sosecrets_rs::{
prelude::{typenum::U2, SecrecySecret, RTSecret},
runtime::traits::RTExposeSecret,
};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
struct A {
inner: i32,
}
#[cfg(feature = "zeroize")]
impl Zeroize for A {
fn zeroize(&mut self) {
self.inner.zeroize()
}
}
let secret_one = SecrecySecret::<A>::new(A { inner: 69 });
let returned_value = secret_one.expose_secret(|exposed_secret| A { inner: (*exposed_secret).inner + 1});
assert_eq!(returned_value.inner, 70);Example (this does NOT compile):
use sosecrets_rs::{
prelude::{typenum::U2, SecrecySecret, RTSecret},
runtime::traits::RTExposeSecret,
};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
struct A {
inner: i32,
}
#[cfg(feature = "zeroize")]
impl Zeroize for A {
fn zeroize(&mut self) {
self.inner.zeroize()
}
}
let secret_one = SecrecySecret::<A>::new(A { inner: 69 });
let _ = secret_one.expose_secret(|exposed_secret| exposed_secret);
let _ = secret_one.expose_secret(|exposed_secret| *exposed_secret); // Only if T is not `Copy`§Parameters
self.scope: A closure that takes the exposed secret and returns a value of theReturnType.
§Returns
A value of type ReturnType which is the type of the returned value from the closure named scope.
Source§fn try_expose_secret<ReturnType, ClosureType>(
&self,
scope: ClosureType,
) -> Result<ReturnType, Infallible>
fn try_expose_secret<ReturnType, ClosureType>( &self, scope: ClosureType, ) -> Result<ReturnType, Infallible>
Exposes the secret without any runtime checking that the exposure count is not more than the maximally allowed exposure count represented by the type parameter MEC.
Note: It is impossible to return the ‘exposed secret’ as the return value of the closure.
Example:
use sosecrets_rs::{
prelude::{typenum::U2, SecrecySecret, RTSecret},
runtime::traits::RTExposeSecret,
};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
struct A {
inner: i32,
}
#[cfg(feature = "zeroize")]
impl Zeroize for A {
fn zeroize(&mut self) {
self.inner.zeroize()
}
}
let secret_one = SecrecySecret::<A>::new(A { inner: 69 });
let returned_value = secret_one.try_expose_secret(|exposed_secret| A { inner: (*exposed_secret).inner + 1});
assert!(returned_value.is_ok());Example (this does NOT compile):
use sosecrets_rs::{
prelude::typenum::U2,
runtime::{secret::RTSecret, traits::RTExposeSecret},
};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
struct A {
inner: i32,
}
#[cfg(feature = "zeroize")]
impl Zeroize for A {
fn zeroize(&mut self) {
self.inner.zeroize()
}
}
let secret_one = SecrecySecret::<A>::new(A { inner: 69 });
let _ = secret_one.try_expose_secret(|exposed_secret| exposed_secret);
let _ = secret_one.try_expose_secret(|exposed_secret| *exposed_secret); // Only if T is not `Copy`§Parameters
self.scope: A closure that takes the exposed secret and returns a value of theReturnType.
§Returns
An Ok variant containing the value of type ReturnType which is the type of the returned value from the closure named scope.
This function can never fail because no check is done.
Source§type Error = Infallible
type Error = Infallible
Error variant as part of the Result returned type in try_expose_secret.