mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-31 01:57:45 +08:00
chore: address Rust 1.83.0 clippy lints and enable more clippy lints (#6705)
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! Abstract data types.
|
||||
//!
|
||||
|
||||
use crate::Secret;
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//!
|
||||
//! `Box` types containing secrets
|
||||
//!
|
||||
//! There is not alias type by design.
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! Diesel-related.
|
||||
//!
|
||||
|
||||
use diesel::{
|
||||
backend::Backend,
|
||||
@ -13,7 +11,7 @@ use diesel::{
|
||||
|
||||
use crate::{Secret, Strategy, StrongSecret, ZeroizableSecret};
|
||||
|
||||
impl<'expr, S, I, T> AsExpression<T> for &'expr Secret<S, I>
|
||||
impl<S, I, T> AsExpression<T> for &Secret<S, I>
|
||||
where
|
||||
T: sql_types::SingleValue,
|
||||
I: Strategy<S>,
|
||||
@ -24,7 +22,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'expr2, 'expr, S, I, T> AsExpression<T> for &'expr2 &'expr Secret<S, I>
|
||||
impl<S, I, T> AsExpression<T> for &&Secret<S, I>
|
||||
where
|
||||
T: sql_types::SingleValue,
|
||||
I: Strategy<S>,
|
||||
@ -81,7 +79,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'expr, S, I, T> AsExpression<T> for &'expr StrongSecret<S, I>
|
||||
impl<S, I, T> AsExpression<T> for &StrongSecret<S, I>
|
||||
where
|
||||
T: sql_types::SingleValue,
|
||||
S: ZeroizableSecret,
|
||||
@ -93,7 +91,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'expr2, 'expr, S, I, T> AsExpression<T> for &'expr2 &'expr StrongSecret<S, I>
|
||||
impl<S, I, T> AsExpression<T> for &&StrongSecret<S, I>
|
||||
where
|
||||
T: sql_types::SingleValue,
|
||||
S: ZeroizableSecret,
|
||||
|
||||
@ -2,10 +2,8 @@
|
||||
#![cfg_attr(docsrs, doc(cfg_hide(doc)))]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
//!
|
||||
//! Personal Identifiable Information protection. Wrapper types and traits for secret management which help ensure they aren't accidentally copied, logged, or otherwise exposed (as much as possible), and also ensure secrets are securely wiped from memory when dropped.
|
||||
//! Secret-keeping library inspired by secrecy.
|
||||
//!
|
||||
|
||||
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR" ), "/", "README.md"))]
|
||||
|
||||
@ -49,7 +47,6 @@ pub use crate::serde::{
|
||||
/// This module should be included with asterisk.
|
||||
///
|
||||
/// `use masking::prelude::*;`
|
||||
///
|
||||
pub mod prelude {
|
||||
pub use super::{ExposeInterface, ExposeOptionInterface, PeekInterface};
|
||||
}
|
||||
|
||||
@ -1,13 +1,9 @@
|
||||
//!
|
||||
//! This module contains Masking objects and traits
|
||||
//!
|
||||
|
||||
use crate::{ExposeInterface, Secret};
|
||||
|
||||
///
|
||||
/// An Enum that allows us to optionally mask data, based on which enum variant that data is stored
|
||||
/// in.
|
||||
///
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub enum Maskable<T: Eq + PartialEq + Clone> {
|
||||
/// Variant which masks the data by wrapping in a Secret
|
||||
@ -35,9 +31,7 @@ impl<T: Eq + PartialEq + Clone + std::hash::Hash> std::hash::Hash for Maskable<T
|
||||
}
|
||||
|
||||
impl<T: Eq + PartialEq + Clone> Maskable<T> {
|
||||
///
|
||||
/// Get the inner data while consuming self
|
||||
///
|
||||
pub fn into_inner(self) -> T {
|
||||
match self {
|
||||
Self::Masked(inner_secret) => inner_secret.expose(),
|
||||
@ -45,49 +39,37 @@ impl<T: Eq + PartialEq + Clone> Maskable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Create a new Masked data
|
||||
///
|
||||
pub fn new_masked(item: Secret<T>) -> Self {
|
||||
Self::Masked(item)
|
||||
}
|
||||
|
||||
///
|
||||
/// Create a new non-masked data
|
||||
///
|
||||
pub fn new_normal(item: T) -> Self {
|
||||
Self::Normal(item)
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the data is masked.
|
||||
/// Returns `true` if the data is wrapped in the `Masked` variant,
|
||||
/// returns `false` otherwise.
|
||||
///
|
||||
pub fn is_masked(&self) -> bool {
|
||||
matches!(self, Self::Masked(_))
|
||||
}
|
||||
|
||||
///
|
||||
/// Checks whether the data is normal (not masked).
|
||||
/// Returns `true` if the data is wrapped in the `Normal` variant,
|
||||
/// returns `false` otherwise.
|
||||
///
|
||||
pub fn is_normal(&self) -> bool {
|
||||
matches!(self, Self::Normal(_))
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for providing a method on custom types for constructing `Maskable`
|
||||
|
||||
pub trait Mask {
|
||||
/// The type returned by the `into_masked()` method. Must implement `PartialEq`, `Eq` and `Clone`
|
||||
|
||||
type Output: Eq + Clone + PartialEq;
|
||||
|
||||
///
|
||||
/// Construct a `Maskable` instance that wraps `Self::Output` by consuming `self`
|
||||
///
|
||||
fn into_masked(self) -> Maskable<Self::Output>;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
//!
|
||||
//! Structure describing secret.
|
||||
//!
|
||||
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
use crate::{strategy::Strategy, PeekInterface, StrongSecret};
|
||||
|
||||
///
|
||||
/// Secret thing.
|
||||
///
|
||||
/// To get access to value use method `expose()` of trait [`crate::ExposeInterface`].
|
||||
@ -39,7 +36,6 @@ use crate::{strategy::Strategy, PeekInterface, StrongSecret};
|
||||
///
|
||||
/// assert_eq!("hello", &format!("{:?}", my_secret));
|
||||
/// ```
|
||||
///
|
||||
pub struct Secret<Secret, MaskingStrategy = crate::WithType>
|
||||
where
|
||||
MaskingStrategy: Strategy<Secret>,
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! Serde-related.
|
||||
//!
|
||||
|
||||
pub use erased_serde::Serialize as ErasedSerialize;
|
||||
pub use serde::{de, Deserialize, Serialize, Serializer};
|
||||
@ -17,7 +15,6 @@ use crate::{Secret, Strategy, StrongSecret, ZeroizableSecret};
|
||||
///
|
||||
/// This is done deliberately to prevent accidental exfiltration of secrets
|
||||
/// via `serde` serialization.
|
||||
///
|
||||
|
||||
#[cfg_attr(docsrs, cfg(feature = "serde"))]
|
||||
pub trait SerializableSecret: Serialize {}
|
||||
@ -87,7 +84,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Masked serialization.
|
||||
///
|
||||
/// the default behaviour for secrets is to serialize in exposed format since the common use cases
|
||||
@ -99,7 +95,6 @@ pub fn masked_serialize<T: Serialize>(value: &T) -> Result<Value, serde_json::Er
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// Masked serialization.
|
||||
///
|
||||
/// Trait object for supporting serialization to Value while accounting for masking
|
||||
@ -118,7 +113,7 @@ impl<T: Serialize + ErasedSerialize> ErasedMaskSerialize for T {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Serialize for dyn ErasedMaskSerialize + 'a {
|
||||
impl Serialize for dyn ErasedMaskSerialize + '_ {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@ -127,7 +122,7 @@ impl<'a> Serialize for dyn ErasedMaskSerialize + 'a {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Serialize for dyn ErasedMaskSerialize + 'a + Send {
|
||||
impl Serialize for dyn ErasedMaskSerialize + '_ + Send {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//!
|
||||
//! Secret strings
|
||||
//!
|
||||
//! There is not alias type by design.
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
//!
|
||||
//! Structure describing secret.
|
||||
//!
|
||||
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
@ -9,11 +7,9 @@ use zeroize::{self, Zeroize as ZeroizableSecret};
|
||||
|
||||
use crate::{strategy::Strategy, PeekInterface};
|
||||
|
||||
///
|
||||
/// Secret thing.
|
||||
///
|
||||
/// To get access to value use method `expose()` of trait [`crate::ExposeInterface`].
|
||||
///
|
||||
pub struct StrongSecret<Secret: ZeroizableSecret, MaskingStrategy = crate::WithType> {
|
||||
/// Inner secret value
|
||||
pub(crate) inner_secret: Secret,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//!
|
||||
//! Secret `Vec` types
|
||||
//!
|
||||
//! There is not alias type by design.
|
||||
|
||||
Reference in New Issue
Block a user