refactor(masking): PII improvements (#77)

This commit is contained in:
kos-for-juspay
2022-12-13 08:50:21 +01:00
committed by GitHub
parent b3fefeb2aa
commit 124048ce75
16 changed files with 188 additions and 162 deletions

View File

@ -3,14 +3,14 @@ use core::fmt;
/// Debugging trait which is specialized for handling secret values
pub trait Strategy<T> {
/// Format information about the secret's type.
fn fmt(value: &T, fmt: &mut fmt::Formatter<'_>) -> std::fmt::Result;
fn fmt(value: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
}
/// Debug with type
pub struct WithType;
impl<T> Strategy<T> for WithType {
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("*** ")?;
fmt.write_str(std::any::type_name::<T>())?;
fmt.write_str(" ***")
@ -21,18 +21,7 @@ impl<T> Strategy<T> for WithType {
pub struct WithoutType;
impl<T> Strategy<T> for WithoutType {
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(_: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("*** ***")
}
}
pub struct NoMasking;
impl<T> Strategy<T> for NoMasking
where
T: fmt::Display,
{
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(val, f)
}
}