mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
chore: address Rust 1.83.0 clippy lints and enable more clippy lints (#6705)
This commit is contained in:
@ -238,7 +238,6 @@ impl VerifySignature for HmacSha512 {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Blake3
|
||||
#[derive(Debug)]
|
||||
pub struct Blake3(String);
|
||||
@ -437,9 +436,7 @@ pub fn generate_cryptographically_secure_random_bytes<const N: usize>() -> [u8;
|
||||
bytes
|
||||
}
|
||||
|
||||
///
|
||||
/// A wrapper type to store the encrypted data for sensitive pii domain data types
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Encryptable<T: Clone> {
|
||||
inner: T,
|
||||
@ -447,9 +444,7 @@ pub struct Encryptable<T: Clone> {
|
||||
}
|
||||
|
||||
impl<T: Clone, S: masking::Strategy<T>> Encryptable<Secret<T, S>> {
|
||||
///
|
||||
/// constructor function to be used by the encryptor and decryptor to generate the data type
|
||||
///
|
||||
pub fn new(
|
||||
masked_data: Secret<T, S>,
|
||||
encrypted_data: Secret<Vec<u8>, EncryptionStrategy>,
|
||||
@ -462,33 +457,25 @@ impl<T: Clone, S: masking::Strategy<T>> Encryptable<Secret<T, S>> {
|
||||
}
|
||||
|
||||
impl<T: Clone> Encryptable<T> {
|
||||
///
|
||||
/// Get the inner data while consuming self
|
||||
///
|
||||
#[inline]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.inner
|
||||
}
|
||||
|
||||
///
|
||||
/// Get the reference to inner value
|
||||
///
|
||||
#[inline]
|
||||
pub fn get_inner(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
///
|
||||
/// Get the inner encrypted data while consuming self
|
||||
///
|
||||
#[inline]
|
||||
pub fn into_encrypted(self) -> Secret<Vec<u8>, EncryptionStrategy> {
|
||||
self.encrypted
|
||||
}
|
||||
|
||||
///
|
||||
/// Deserialize inner value and return new Encryptable object
|
||||
///
|
||||
pub fn deserialize_inner_value<U, F>(
|
||||
self,
|
||||
f: F,
|
||||
|
||||
@ -202,7 +202,6 @@ pub mod timestamp {
|
||||
}
|
||||
|
||||
/// <https://github.com/serde-rs/serde/issues/994#issuecomment-316895860>
|
||||
|
||||
pub mod json_string {
|
||||
use serde::de::{self, Deserialize, DeserializeOwned, Deserializer};
|
||||
use serde_json;
|
||||
|
||||
@ -7,7 +7,6 @@ use crate::types::MinorUnit;
|
||||
/// error_stack::Report<E> specific extendability
|
||||
///
|
||||
/// Effectively, equivalent to `Result<T, error_stack::Report<E>>`
|
||||
///
|
||||
pub type CustomResult<T, E> = error_stack::Result<T, E>;
|
||||
|
||||
/// Parsing Errors
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
//!
|
||||
//! This module holds traits for extending functionalities for existing datatypes
|
||||
//! & inbuilt datatypes.
|
||||
//!
|
||||
|
||||
use error_stack::ResultExt;
|
||||
use masking::{ExposeInterface, PeekInterface, Secret, Strategy};
|
||||
@ -14,10 +12,8 @@ use crate::{
|
||||
fp_utils::when,
|
||||
};
|
||||
|
||||
///
|
||||
/// Encode interface
|
||||
/// An interface for performing type conversions and serialization
|
||||
///
|
||||
pub trait Encode<'e>
|
||||
where
|
||||
Self: 'e + std::fmt::Debug,
|
||||
@ -27,62 +23,49 @@ where
|
||||
/// Converting `Self` into an intermediate representation `<P>`
|
||||
/// and then performing encoding operation using the `Serialize` trait from `serde`
|
||||
/// Specifically to convert into json, by using `serde_json`
|
||||
///
|
||||
fn convert_and_encode<P>(&'e self) -> CustomResult<String, errors::ParsingError>
|
||||
where
|
||||
P: TryFrom<&'e Self> + Serialize,
|
||||
Result<P, <P as TryFrom<&'e Self>>::Error>: ResultExt,
|
||||
<Result<P, <P as TryFrom<&'e Self>>::Error> as ResultExt>::Ok: Serialize;
|
||||
|
||||
///
|
||||
/// Converting `Self` into an intermediate representation `<P>`
|
||||
/// and then performing encoding operation using the `Serialize` trait from `serde`
|
||||
/// Specifically, to convert into urlencoded, by using `serde_urlencoded`
|
||||
///
|
||||
fn convert_and_url_encode<P>(&'e self) -> CustomResult<String, errors::ParsingError>
|
||||
where
|
||||
P: TryFrom<&'e Self> + Serialize,
|
||||
Result<P, <P as TryFrom<&'e Self>>::Error>: ResultExt,
|
||||
<Result<P, <P as TryFrom<&'e Self>>::Error> as ResultExt>::Ok: Serialize;
|
||||
|
||||
///
|
||||
/// Functionality, for specifically encoding `Self` into `String`
|
||||
/// after serialization by using `serde::Serialize`
|
||||
///
|
||||
fn url_encode(&'e self) -> CustomResult<String, errors::ParsingError>
|
||||
where
|
||||
Self: Serialize;
|
||||
|
||||
///
|
||||
/// Functionality, for specifically encoding `Self` into `String`
|
||||
/// after serialization by using `serde::Serialize`
|
||||
/// specifically, to convert into JSON `String`.
|
||||
///
|
||||
fn encode_to_string_of_json(&'e self) -> CustomResult<String, errors::ParsingError>
|
||||
where
|
||||
Self: Serialize;
|
||||
|
||||
///
|
||||
/// Functionality, for specifically encoding `Self` into `String`
|
||||
/// after serialization by using `serde::Serialize`
|
||||
/// specifically, to convert into XML `String`.
|
||||
///
|
||||
fn encode_to_string_of_xml(&'e self) -> CustomResult<String, errors::ParsingError>
|
||||
where
|
||||
Self: Serialize;
|
||||
|
||||
///
|
||||
/// Functionality, for specifically encoding `Self` into `serde_json::Value`
|
||||
/// after serialization by using `serde::Serialize`
|
||||
///
|
||||
fn encode_to_value(&'e self) -> CustomResult<serde_json::Value, errors::ParsingError>
|
||||
where
|
||||
Self: Serialize;
|
||||
|
||||
///
|
||||
/// Functionality, for specifically encoding `Self` into `Vec<u8>`
|
||||
/// after serialization by using `serde::Serialize`
|
||||
///
|
||||
fn encode_to_vec(&'e self) -> CustomResult<Vec<u8>, errors::ParsingError>
|
||||
where
|
||||
Self: Serialize;
|
||||
@ -165,13 +148,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Extending functionalities of `bytes::Bytes`
|
||||
///
|
||||
pub trait BytesExt {
|
||||
///
|
||||
/// Convert `bytes::Bytes` into type `<T>` using `serde::Deserialize`
|
||||
///
|
||||
fn parse_struct<'de, T>(
|
||||
&'de self,
|
||||
type_name: &'static str,
|
||||
@ -199,13 +178,9 @@ impl BytesExt for bytes::Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Extending functionalities of `[u8]` for performing parsing
|
||||
///
|
||||
pub trait ByteSliceExt {
|
||||
///
|
||||
/// Convert `[u8]` into type `<T>` by using `serde::Deserialize`
|
||||
///
|
||||
fn parse_struct<'de, T>(
|
||||
&'de self,
|
||||
type_name: &'static str,
|
||||
@ -229,13 +204,9 @@ impl ByteSliceExt for [u8] {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Extending functionalities of `serde_json::Value` for performing parsing
|
||||
///
|
||||
pub trait ValueExt {
|
||||
///
|
||||
/// Convert `serde_json::Value` into type `<T>` by using `serde::Deserialize`
|
||||
///
|
||||
fn parse_value<T>(self, type_name: &'static str) -> CustomResult<T, errors::ParsingError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned;
|
||||
@ -277,22 +248,16 @@ impl<E: ValueExt + Clone> ValueExt for crypto::Encryptable<E> {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Extending functionalities of `String` for performing parsing
|
||||
///
|
||||
pub trait StringExt<T> {
|
||||
///
|
||||
/// Convert `String` into type `<T>` (which being an `enum`)
|
||||
///
|
||||
fn parse_enum(self, enum_name: &'static str) -> CustomResult<T, errors::ParsingError>
|
||||
where
|
||||
T: std::str::FromStr,
|
||||
// Requirement for converting the `Err` variant of `FromStr` to `Report<Err>`
|
||||
<T as std::str::FromStr>::Err: std::error::Error + Send + Sync + 'static;
|
||||
|
||||
///
|
||||
/// Convert `serde_json::Value` into type `<T>` by using `serde::Deserialize`
|
||||
///
|
||||
fn parse_struct<'de>(
|
||||
&'de self,
|
||||
type_name: &'static str,
|
||||
@ -327,25 +292,20 @@ impl<T> StringExt<T> for String {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Extending functionalities of Wrapper types for idiomatic
|
||||
///
|
||||
#[cfg(feature = "async_ext")]
|
||||
#[cfg_attr(feature = "async_ext", async_trait::async_trait)]
|
||||
pub trait AsyncExt<A, B> {
|
||||
/// Output type of the map function
|
||||
type WrappedSelf<T>;
|
||||
///
|
||||
|
||||
/// Extending map by allowing functions which are async
|
||||
///
|
||||
async fn async_map<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
Fut: futures::Future<Output = B> + Send;
|
||||
|
||||
///
|
||||
/// Extending the `and_then` by allowing functions which are async
|
||||
///
|
||||
async fn async_and_then<F, Fut>(self, func: F) -> Self::WrappedSelf<B>
|
||||
where
|
||||
F: FnOnce(A) -> Fut + Send,
|
||||
@ -469,9 +429,7 @@ where
|
||||
|
||||
/// Extension trait for deserializing XML strings using `quick-xml` crate
|
||||
pub trait XmlExt {
|
||||
///
|
||||
/// Deserialize an XML string into the specified type `<T>`.
|
||||
///
|
||||
fn parse_xml<T>(self) -> Result<T, de::DeError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned;
|
||||
|
||||
@ -348,7 +348,6 @@ where
|
||||
}
|
||||
|
||||
/// Strategy for masking UPI VPA's
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UpiVpaMaskingStrategy {}
|
||||
|
||||
|
||||
@ -6,10 +6,8 @@ use futures::StreamExt;
|
||||
use router_env::logger;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
///
|
||||
/// This functions is meant to run in parallel to the application.
|
||||
/// It will send a signal to the receiver when a SIGTERM or SIGINT is received
|
||||
///
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub async fn signal_handler(mut sig: signal_hook_tokio::Signals, sender: mpsc::Sender<()>) {
|
||||
if let Some(signal) = sig.next().await {
|
||||
@ -34,47 +32,35 @@ pub async fn signal_handler(mut sig: signal_hook_tokio::Signals, sender: mpsc::S
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// This functions is meant to run in parallel to the application.
|
||||
/// It will send a signal to the receiver when a SIGTERM or SIGINT is received
|
||||
///
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn signal_handler(_sig: DummySignal, _sender: mpsc::Sender<()>) {}
|
||||
|
||||
///
|
||||
/// This function is used to generate a list of signals that the signal_handler should listen for
|
||||
///
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub fn get_allowed_signals() -> Result<signal_hook_tokio::SignalsInfo, std::io::Error> {
|
||||
signal_hook_tokio::Signals::new([signal_hook::consts::SIGTERM, signal_hook::consts::SIGINT])
|
||||
}
|
||||
|
||||
///
|
||||
/// This function is used to generate a list of signals that the signal_handler should listen for
|
||||
///
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_allowed_signals() -> Result<DummySignal, std::io::Error> {
|
||||
Ok(DummySignal)
|
||||
}
|
||||
|
||||
///
|
||||
/// Dummy Signal Handler for windows
|
||||
///
|
||||
#[cfg(target_os = "windows")]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySignal;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
impl DummySignal {
|
||||
///
|
||||
/// Dummy handler for signals in windows (empty)
|
||||
///
|
||||
pub fn handle(&self) -> Self {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
///
|
||||
/// Hollow implementation, for windows compatibility
|
||||
///
|
||||
pub fn close(self) {}
|
||||
}
|
||||
|
||||
@ -334,7 +334,6 @@ impl AmountConvertor for FloatMajorUnitForConnector {
|
||||
}
|
||||
|
||||
/// Connector required amount type
|
||||
|
||||
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq)]
|
||||
pub struct MinorUnitForConnector;
|
||||
|
||||
@ -503,7 +502,6 @@ impl Sum for MinorUnit {
|
||||
}
|
||||
|
||||
/// Connector specific types to send
|
||||
|
||||
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
|
||||
pub struct StringMinorUnit(String);
|
||||
|
||||
@ -749,7 +747,7 @@ mod client_secret_type {
|
||||
{
|
||||
struct ClientSecretVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ClientSecretVisitor {
|
||||
impl Visitor<'_> for ClientSecretVisitor {
|
||||
type Value = ClientSecret;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
@ -393,7 +393,7 @@ impl<'de> Deserialize<'de> for DecryptedData {
|
||||
{
|
||||
struct DecryptedDataVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for DecryptedDataVisitor {
|
||||
impl Visitor<'_> for DecryptedDataVisitor {
|
||||
type Value = DecryptedData;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@ -449,7 +449,7 @@ impl<'de> Deserialize<'de> for EncryptedData {
|
||||
{
|
||||
struct EncryptedDataVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for EncryptedDataVisitor {
|
||||
impl Visitor<'_> for EncryptedDataVisitor {
|
||||
type Value = EncryptedData;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
Reference in New Issue
Block a user