//! //! Abstract data types. //! use crate::Secret; /// Interface to expose a reference to an inner secret pub trait PeekInterface { /// Only method providing access to the secret value. fn peek(&self) -> &S; } /// Interface that consumes a option secret and returns the value. pub trait ExposeOptionInterface { /// Expose option. fn expose_option(self) -> S; } /// Interface that consumes a secret and returns the inner value. pub trait ExposeInterface { /// Consume the secret and return the inner value fn expose(self) -> S; } impl ExposeOptionInterface> for Option> where S: Clone, I: crate::Strategy, { fn expose_option(self) -> Option { self.map(ExposeInterface::expose) } } impl ExposeInterface for Secret where I: crate::Strategy, { fn expose(self) -> S { self.inner_secret } } /// Interface that consumes a secret and converts it to a secret with a different masking strategy. pub trait SwitchStrategy { /// The type returned by `switch_strategy()`. type Output; /// Consumes the secret and converts it to a secret with a different masking strategy. fn switch_strategy(self) -> Self::Output; } impl SwitchStrategy for Secret where FromStrategy: crate::Strategy, ToStrategy: crate::Strategy, { type Output = Secret; fn switch_strategy(self) -> Self::Output { Secret::new(self.inner_secret) } }