mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
//!
|
|
//! Abstract data types.
|
|
//!
|
|
|
|
use crate::Secret;
|
|
|
|
/// Interface to expose a reference to an inner secret
|
|
pub trait PeekInterface<S> {
|
|
/// 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<S> {
|
|
/// Expose option.
|
|
fn expose_option(self) -> S;
|
|
}
|
|
|
|
/// Interface that consumes a secret and returns the inner value.
|
|
pub trait ExposeInterface<S> {
|
|
/// Consume the secret and return the inner value
|
|
fn expose(self) -> S;
|
|
}
|
|
|
|
impl<S, I> ExposeOptionInterface<Option<S>> for Option<Secret<S, I>>
|
|
where
|
|
S: Clone,
|
|
I: crate::Strategy<S>,
|
|
{
|
|
fn expose_option(self) -> Option<S> {
|
|
self.map(ExposeInterface::expose)
|
|
}
|
|
}
|
|
|
|
impl<S, I> ExposeInterface<S> for Secret<S, I>
|
|
where
|
|
I: crate::Strategy<S>,
|
|
{
|
|
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<FromStrategy, ToStrategy> {
|
|
/// 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<S, FromStrategy, ToStrategy> SwitchStrategy<FromStrategy, ToStrategy>
|
|
for Secret<S, FromStrategy>
|
|
where
|
|
FromStrategy: crate::Strategy<S>,
|
|
ToStrategy: crate::Strategy<S>,
|
|
{
|
|
type Output = Secret<S, ToStrategy>;
|
|
|
|
fn switch_strategy(self) -> Self::Output {
|
|
Secret::new(self.inner_secret)
|
|
}
|
|
}
|