mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(masking): use empty enums as masking:Strategy<T> types (#2874)
This commit is contained in:
@ -72,7 +72,7 @@ impl<'de> Deserialize<'de> for CardNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CardNumberStrategy;
|
pub enum CardNumberStrategy {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for CardNumberStrategy
|
impl<T> Strategy<T> for CardNumberStrategy
|
||||||
where
|
where
|
||||||
|
|||||||
@ -27,7 +27,7 @@ pub type SecretSerdeValue = Secret<serde_json::Value>;
|
|||||||
|
|
||||||
/// Strategy for masking a PhoneNumber
|
/// Strategy for masking a PhoneNumber
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PhoneNumberStrategy;
|
pub enum PhoneNumberStrategy {}
|
||||||
|
|
||||||
/// Phone Number
|
/// Phone Number
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
@ -144,7 +144,7 @@ where
|
|||||||
|
|
||||||
/// Strategy for Encryption
|
/// Strategy for Encryption
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EncryptionStratergy;
|
pub enum EncryptionStratergy {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for EncryptionStratergy
|
impl<T> Strategy<T> for EncryptionStratergy
|
||||||
where
|
where
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
|
|
||||||
/// Client secret
|
/// Client secret
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ClientSecret;
|
pub enum ClientSecret {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for ClientSecret
|
impl<T> Strategy<T> for ClientSecret
|
||||||
where
|
where
|
||||||
@ -189,7 +189,7 @@ where
|
|||||||
|
|
||||||
/// Strategy for masking Email
|
/// Strategy for masking Email
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EmailStrategy;
|
pub enum EmailStrategy {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for EmailStrategy
|
impl<T> Strategy<T> for EmailStrategy
|
||||||
where
|
where
|
||||||
@ -305,7 +305,7 @@ impl FromStr for Email {
|
|||||||
|
|
||||||
/// IP address
|
/// IP address
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IpAddress;
|
pub enum IpAddress {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for IpAddress
|
impl<T> Strategy<T> for IpAddress
|
||||||
where
|
where
|
||||||
@ -332,7 +332,7 @@ where
|
|||||||
/// Strategy for masking UPI VPA's
|
/// Strategy for masking UPI VPA's
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UpiVpaMaskingStrategy;
|
pub enum UpiVpaMaskingStrategy {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for UpiVpaMaskingStrategy
|
impl<T> Strategy<T> for UpiVpaMaskingStrategy
|
||||||
where
|
where
|
||||||
|
|||||||
@ -12,8 +12,8 @@ use crate::{strategy::Strategy, PeekInterface};
|
|||||||
/// To get access to value use method `expose()` of trait [`crate::ExposeInterface`].
|
/// To get access to value use method `expose()` of trait [`crate::ExposeInterface`].
|
||||||
///
|
///
|
||||||
/// ## Masking
|
/// ## Masking
|
||||||
/// Use the [`crate::strategy::Strategy`] trait to implement a masking strategy on a unit struct
|
/// Use the [`crate::strategy::Strategy`] trait to implement a masking strategy on a zero-variant
|
||||||
/// and pass the unit struct as a second generic parameter to [`Secret`] while defining it.
|
/// enum and pass this enum as a second generic parameter to [`Secret`] while defining it.
|
||||||
/// [`Secret`] will take care of applying the masking strategy on the inner secret when being
|
/// [`Secret`] will take care of applying the masking strategy on the inner secret when being
|
||||||
/// displayed.
|
/// displayed.
|
||||||
///
|
///
|
||||||
@ -24,7 +24,7 @@ use crate::{strategy::Strategy, PeekInterface};
|
|||||||
/// use masking::Secret;
|
/// use masking::Secret;
|
||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
///
|
///
|
||||||
/// struct MyStrategy;
|
/// enum MyStrategy {}
|
||||||
///
|
///
|
||||||
/// impl<T> Strategy<T> for MyStrategy
|
/// impl<T> Strategy<T> for MyStrategy
|
||||||
/// where
|
/// where
|
||||||
|
|||||||
@ -7,7 +7,7 @@ pub trait Strategy<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Debug with type
|
/// Debug with type
|
||||||
pub struct WithType;
|
pub enum WithType {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for WithType {
|
impl<T> Strategy<T> for WithType {
|
||||||
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
@ -18,7 +18,7 @@ impl<T> Strategy<T> for WithType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Debug without type
|
/// Debug without type
|
||||||
pub struct WithoutType;
|
pub enum WithoutType {}
|
||||||
|
|
||||||
impl<T> Strategy<T> for WithoutType {
|
impl<T> Strategy<T> for WithoutType {
|
||||||
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|||||||
Reference in New Issue
Block a user