text stringlengths 70 351k | source stringclasses 4 values |
|---|---|
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use error_stack::ResultExt;
use ring::aead::{self, BoundKey};
fn decrypt(&self, input: Vec<u8>) -> Self::ReturnType<'_, Vec<u8>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use ring::aead::{self, BoundKey};
fn encrypt(&self, mut input: Vec<u8>) -> Self::ReturnType<'_, Vec<u8>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use ring::aead::{self, BoundKey};
fn advance(&mut self) -> Result<ring::aead::Nonce, ring::error::Unspecified> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
use ring::aead::{self, BoundKey};
/// Constructs a nonce sequence from bytes
fn from_bytes(bytes: [u8; ring::aead::NONCE_LEN]) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use ring::aead::{self, BoundKey};
/// Returns the current nonce value as bytes.
fn current(&self) -> [u8; ring::aead::NONCE_LEN] {
let mut nonce = [0_u8; ring::aead::NONCE_LEN];
nonce.copy_from_slice(&self.0.to_be_bytes()[Self::SEQUENCE_NUMBER_START_INDEX..]);
nonce
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src
pub fn new(key: Vec<u8>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn health_check_keymanager(
tenant_app_state: &TenantAppState,
) -> Result<health::HealthState, ContainerError<error::KeyManagerHealthCheckError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn create_key_in_key_manager(
tenant_app_state: &TenantAppState,
request_body: DataKeyCreateRequest,
) -> Result<DataKeyCreateResponse, ContainerError<error::KeyManagerError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
use masking::{Secret, StrongSecret};
async fn decrypt_data(
&self,
tenant_app_state: &TenantAppState,
encrypted_data: Secret<Vec<u8>>,
) -> Result<StrongSecret<Vec<u8>>, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
use masking::{Secret, StrongSecret};
async fn encrypt_data(
&self,
tenant_app_state: &TenantAppState,
decryted_data: StrongSecret<Vec<u8>>,
) -> Result<Secret<Vec<u8>>, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
fn get_inner(&self) -> &Entity {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
fn from_entity(entity: Entity) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
async fn find_by_entity_id(
&self,
tenant_app_state: &TenantAppState,
entity_id: String,
) -> Result<Box<dyn CryptoOperationsManager>, ContainerError<error::ApiError>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn call_encryption_service<T, E>(
tenant_app_state: &TenantAppState,
url: String,
method: Method,
request_body: T,
) -> Result<ApiResponse, ContainerError<E>>
where
T: serde::Serialize + Send + Sync + 'static,
ContainerError<E>: From<ContainerError<error::ApiClientError>> + Send + Sync,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn health_check_keymanager(
tenant_app_state: &TenantAppState,
) -> Result<health::HealthState, ContainerError<error::KeyManagerHealthCheckError>> {
let url = format!(
"{}/health",
tenant_app_state.config.external_key_manager.url
);
call_encryption_service::<_, error::KeyManagerHealthCheckError>(
tenant_app_state,
url,
Method::Get,
(),
)
.await?;
Ok(health::HealthState::Working)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn decrypt_data_using_key_manager(
tenant_app_state: &TenantAppState,
request_body: DataDecryptionRequest,
) -> Result<DecryptedData, ContainerError<error::KeyManagerError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn encrypt_data_using_key_manager(
tenant_app_state: &TenantAppState,
request_body: DataEncryptionRequest,
) -> Result<EncryptedData, ContainerError<error::KeyManagerError>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
/// Method required to transfer the old dek of merchant to key manager.
/// Can be removed after migration of all keys.
pub async fn transfer_key_to_key_manager(
tenant_app_state: &TenantAppState,
request_body: DataKeyTransferRequest,
) -> Result<DataKeyCreateResponse, ContainerError<error::KeyManagerError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager.rs | crate: src
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
external_keymanager::{
self,
types::{
DataDecryptionRequest, DataDecryptionResponse, DataEncryptionRequest,
DataKeyCreateRequest, DataKeyCreateResponse, DataKeyTransferRequest,
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
};
pub async fn create_key_in_key_manager(
tenant_app_state: &TenantAppState,
request_body: DataKeyCreateRequest,
) -> Result<DataKeyCreateResponse, ContainerError<error::KeyManagerError>> {
let url = format!(
"{}/key/create",
tenant_app_state.config.external_key_manager.url
);
let response = call_encryption_service::<_, error::DataKeyCreationError>(
tenant_app_state,
url,
Method::Post,
request_body,
)
.await?
.deserialize_json::<DataKeyCreateResponse, error::DataKeyCreationError>()
.await?;
Ok(response)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager/utils.rs | crate: src
use std::collections::HashSet;
use hyper::header::{AUTHORIZATION, CONTENT_TYPE};
use masking::{Mask, Maskable};
use crate::storage::consts::X_TENANT_ID;
use crate::{app::TenantAppState, crypto::consts::BASE64_ENGINE};
pub fn get_key_manager_header(
tenant_app_state: &TenantAppState,
) -> HashSet<(String, Maskable<String>)> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/crypto/keymanager/external_keymanager/utils.rs | crate: src
use std::collections::HashSet;
use hyper::header::{AUTHORIZATION, CONTENT_TYPE};
use masking::{Mask, Maskable};
use crate::storage::consts::X_TENANT_ID;
use crate::{app::TenantAppState, crypto::consts::BASE64_ENGINE};
pub fn get_key_manager_header(
tenant_app_state: &TenantAppState,
) -> HashSet<(String, Maskable<String>)> {
let broken_master_key = {
let broken_master_key = &tenant_app_state.config.tenant_secrets.master_key;
let (left_half, right_half) = broken_master_key.split_at(broken_master_key.len() / 2);
let hex_left = hex::encode(left_half);
let hex_right = hex::encode(right_half);
BASE64_ENGINE.encode(format!("{}:{}", hex_left, hex_right))
};
[
(CONTENT_TYPE.to_string(), "application/json".into()),
(
AUTHORIZATION.to_string(),
format!("Basic {}", broken_master_key).into_masked(),
),
(
X_TENANT_ID.to_string(),
tenant_app_state.config.tenant_id.clone().into(),
),
]
.into_iter()
.collect::<std::collections::HashSet<_>>()
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use serde::ser::{SerializeMap, Serializer};
use serde_json::Value;
use super::storage::Storage;
use time::format_description::well_known::Iso8601;
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
/// Serialize common for both span and event entries.
fn common_serialize<S>(
&self,
map_serializer: &mut impl SerializeMap<Error = serde_json::Error>,
metadata: &Metadata<'_>,
span: Option<&SpanRef<'_, S>>,
storage: &Storage<'_>,
name: &str,
) -> Result<(), std::io::Error>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
{let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);<|fim_suffix|>
<|fim_middle|>
Ok(())}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use serde_json::Value;
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
mut default_fields: HashMap<String, Value>,
) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
fn on_close(&self, id: tracing::Id, ctx: Context<'_, S>) {
let span = ctx.span(&id).expect("No span");
if let Ok(serialized) = self.span_serialize(&span, RecordType::ExitSpan) {
let _ = self.flush(serialized);
}
} | ast_fragments |
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use serde::ser::{SerializeMap, Serializer};
use serde_json::Value;
use super::storage::Storage;
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
/// Serialize event into a buffer of bytes using parent span.
pub fn event_serialize<S>(
&self,
span: &Option<&SpanRef<'_, S>>,
event: &Event<'_>,
) -> std::io::Result<Vec<u8>>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let mut buffer = Vec::new();
let mut serializer = serde_json::Serializer::new(&mut buffer);
let mut map_serializer = serializer.serialize_map(None)?;
let mut storage = Storage::default();
event.record(&mut storage);
let name = span.map_or("?", SpanRef::name);
Self::event_message(span, event, &mut storage);
self.common_serialize(&mut map_serializer, event.metadata(), *span, &storage, name)?;
map_serializer.end()?;
Ok(buffer)
} | ast_fragments |
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
///
/// Flush memory buffer into an output stream trailing it with next line.
///
/// Should be done by single `write_all` call to avoid fragmentation of log because of mutlithreading.
///
fn flush(&self, mut buffer: Vec<u8>) -> Result<(), std::io::Error> {
buffer.write_all(b"\n")?;
self.dst_writer.make_writer().write_all(&buffer)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
///
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/formatter.rs | crate: src
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
{
Self::EnterSpan => "START",<|fim_suffix|>
<|fim_middle|>
Self::Event => "EVENT",
}
} | ast_fragments |
// file: hyperswitch-card-vault/src/logger/setup.rs | crate: src
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer};
use super::{config, formatter::FormattingLayer, storage::StorageSubscription};
/// Setup logging sub-system specifying the logging configuration, service (binary) name, and a
/// list of external crates for which a more verbose logging must be enabled. All crates within the
/// current cargo workspace are automatically considered for verbose logging.
pub fn setup(
config: &config::Log,
service_name: &str,
crates_to_filter: impl AsRef<[&'static str]>,
) -> TelemetryGuard {
let mut guards = Vec::new();
#[cfg(feature = "console")]
let console_layer = console_subscriber::spawn();
let subscriber = tracing_subscriber::registry().with(StorageSubscription);
#[cfg(feature = "console")]
let subscriber = subscriber.with(console_layer);
// Setup console logging
if config.console.enabled {
let (console_writer, guard) = tracing_appender::non_blocking(std::io::stdout());
guards.push(guard);
let console_filter = get_envfilter(
config.console.filtering_directive.as_ref(),
config::Level(tracing::Level::WARN),
config.console.level,
&crates_to_filter,
);
println!("Using console logging filter: {console_filter}");
match config.console.log_format {
config::LogFormat::Default => {
let logging_layer = fmt::layer()
.with_timer(fmt::time::time())
.pretty()
.with_writer(console_writer)
.with_filter(console_filter);
subscriber.with(logging_layer).init();
}
config::LogFormat::Json => {
error_stack::Report::set_color_mode(error_stack::fmt::ColorMode::None);
let logging_layer =
FormattingLayer::new(service_name, console_writer).with_filter(console_filter);
subscriber.with(logging_layer).init();
}
}
} else {
subscriber.init();
};
// Returning the TelemetryGuard for logs to be printed and metrics to be collected until it is
// dropped
TelemetryGuard {
_log_guards: guards,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/logger/setup.rs | crate: src
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer};
use super::{config, formatter::FormattingLayer, storage::StorageSubscription};
/// Setup logging sub-system specifying the logging configuration, service (binary) name, and a
/// list of external crates for which a more verbose logging must be enabled. All crates within the
/// current cargo workspace are automatically considered for verbose logging.
pub fn setup(
config: &config::Log,
service_name: &str,
crates_to_filter: impl AsRef<[&'static str]>,
) -> TelemetryGuard {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
use super::schema;
pub fn new(request: StoreCardRequest, hash_id: &'a str, enc_data: Encrypted) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn get_encrypted_inner_value(&self) -> Option<Secret<Vec<u8>>> {
{
Self::Encrypted(secret) => Some(secret.clone()),<|fim_suffix|>
<|fim_middle|>
Self::Decrypted(_) => None,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
fn encrypt(
self,
algo: &Self::Algorithm,
) -> <Self::Algorithm as Encryption<Vec<u8>, Vec<u8>>>::ReturnType<'_, Self::Output> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
fn decrypt(
self,
algo: &Self::Algorithm,
) -> <Self::Algorithm as Encryption<Vec<u8>, Vec<u8>>>::ReturnType<'_, Self::Output> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
fn from_sql(bytes: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
<Secret<Vec<u8>>>::from_sql(bytes).map(Self::new)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
fn from(value: Secret<Vec<u8>>) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
fn from(value: Vec<u8>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn get_inner(&self) -> &Secret<Vec<u8>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn into_inner(self) -> Secret<Vec<u8>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn new(item: Secret<Vec<u8>>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
fn deref(&self) -> &StrongSecret<String> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
pub fn into_bytes(self) -> Vec<u8> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
fn validate(&self) -> Result<(), Self::Error> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
use super::schema;
pub fn new(request: StoreCardRequest, hash_id: &'a str, enc_data: Encrypted) -> Self {
Self {
locker_id: request
.requestor_card_reference
.unwrap_or_else(super::utils::generate_uuid)
.into(),
merchant_id: request.merchant_id,
customer_id: request.merchant_customer_id,
enc_data,
hash_id,
ttl: *request.ttl,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
fn from(value: Encrypted) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn from_decrypted_data(decrypted_data: StrongSecret<Vec<u8>>) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn get_decrypted_inner_value(&self) -> Option<StrongSecret<Vec<u8>>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use diesel::{
backend::Backend,
deserialize::{self, FromSql},
serialize::ToSql,
sql_types, AsExpression, Identifiable, Insertable, Queryable,
};
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
pub fn get_encrypted_inner_value(&self) -> Option<Secret<Vec<u8>>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/types.rs | crate: src
use crate::{
crypto::encryption_manager::{encryption_interface::Encryption, managers::aes::GcmAes256},
error,
routes::data::types::{StoreCardRequest, Validation},
};
fn from(value: LockerInner) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/types.rs | crate: src
use crate::{
routes::routes_v2::data::types::StoreDataRequest,
storage::{
schema,
types::{Encryptable, Encrypted},
},
};
pub fn new(request: StoreDataRequest, encrypted_data: Encrypted) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/types.rs | crate: src
use crate::{
routes::routes_v2::data::types::StoreDataRequest,
storage::{
schema,
types::{Encryptable, Encrypted},
},
};
fn from(value: VaultInner) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/storage/storage_v2/types.rs | crate: src
use crate::{
routes::routes_v2::data::types::StoreDataRequest,
storage::{
schema,
types::{Encryptable, Encrypted},
},
};
pub fn new(request: StoreDataRequest, encrypted_data: Encrypted) -> Self {
Self {
vault_id: request.vault_id.into(),
entity_id: request.entity_id,
encrypted_data,
expires_at: *request.ttl,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/db.rs | crate: src
use diesel::{
associations::HasTable, query_dsl::methods::FilterDsl, BoolExpressionMethods, ExpressionMethods,
};
use crate::{
crypto::encryption_manager::managers::aes::GcmAes256,
error::{self, ContainerError, ResultContainerExt},
storage::{schema, Storage},
};
use super::{types, VaultInterface};
async fn insert_or_get_from_vault(
&self,
new: types::VaultNew,
) -> Result<types::Vault, ContainerError<Self::Error>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/db.rs | crate: src
use diesel::{
associations::HasTable, query_dsl::methods::FilterDsl, BoolExpressionMethods, ExpressionMethods,
};
use masking::{ExposeInterface, Secret};
use crate::{
crypto::encryption_manager::managers::aes::GcmAes256,
error::{self, ContainerError, ResultContainerExt},
storage::{schema, Storage},
};
use super::{types, VaultInterface};
async fn find_by_vault_id_entity_id(
&self,
vault_id: Secret<String>,
entity_id: &str,
) -> Result<types::Vault, ContainerError<Self::Error>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/db.rs | crate: src
use diesel::{
associations::HasTable, query_dsl::methods::FilterDsl, BoolExpressionMethods, ExpressionMethods,
};
use masking::{ExposeInterface, Secret};
use crate::{
crypto::encryption_manager::managers::aes::GcmAes256,
error::{self, ContainerError, ResultContainerExt},
storage::{schema, Storage},
};
use super::{types, VaultInterface};
async fn find_by_vault_id_entity_id(
&self,
vault_id: Secret<String>,
entity_id: &str,
) -> Result<types::Vault, ContainerError<Self::Error>> {
{
diesel::result::Error::NotFound => {
Err(err).change_error(error::StorageError::NotFoundError)
}<|fim_suffix|>
<|fim_middle|>
_ => Err(err).change_error(error::StorageError::FindError),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/storage_v2/db.rs | crate: src
use diesel::{
associations::HasTable, query_dsl::methods::FilterDsl, BoolExpressionMethods, ExpressionMethods,
};
use masking::{ExposeInterface, Secret};
use crate::{
crypto::encryption_manager::managers::aes::GcmAes256,
error::{self, ContainerError, ResultContainerExt},
storage::{schema, Storage},
};
use super::{types, VaultInterface};
async fn delete_from_vault(
&self,
vault_id: Secret<String>,
entity_id: &str,
) -> Result<usize, ContainerError<Self::Error>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/storage/caching/hash_table.rs | crate: src
use crate::{
error::ContainerError,
storage::{self, types},
};
async fn find_by_data_hash(
&self,
data_hash: &[u8],
) -> Result<Option<types::HashTable>, ContainerError<Self::Error>> {
{
value @ Some(_) => Ok(value),<|fim_suffix|>
<|fim_middle|>
None => Ok(match self.inner.find_by_data_hash(data_hash).await? {
None => None,
Some(value) => {
self.cache_data::<types::HashTable>(data_hash.to_vec(), value.clone())
.await;
Some(value)
}
}),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataEncryptionError) -> Self {
{
super::DataEncryptionError::RequestSendFailed
| super::DataEncryptionError::ResponseDecodingFailed
| super::DataEncryptionError::InternalServerError
| super::DataEncryptionError::Unexpected
| super::DataEncryptionError::BadRequest
| super::DataEncryptionError::CertificateParseFailed
| super::DataEncryptionError::RequestConstructionFailed => Self::EncryptionFailed,<|fim_suffix|>
<|fim_middle|>
super::DataEncryptionError::Unauthorized => Self::Unauthorized,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataKeyCreationError) -> Self {
{
super::DataKeyCreationError::RequestSendFailed
| super::DataKeyCreationError::ResponseDecodingFailed
| super::DataKeyCreationError::InternalServerError
| super::DataKeyCreationError::Unexpected
| super::DataKeyCreationError::BadRequest
| super::DataKeyCreationError::CertificateParseFailed
| super::DataKeyCreationError::RequestConstructionFailed => Self::KeyAddFailed,<|fim_suffix|>
<|fim_middle|>
super::DataKeyCreationError::Unauthorized => Self::Unauthorized,
}
} | ast_fragments |
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::ApiClientError) -> Self {
match value {
super::ApiClientError::ClientConstructionFailed
| super::ApiClientError::HeaderMapConstructionFailed
| super::ApiClientError::IdentityParseFailed
| super::ApiClientError::CertificateParseFailed { .. }
| super::ApiClientError::UrlEncodingFailed
| super::ApiClientError::RequestNotSent
| super::ApiClientError::ResponseDecodingFailed
| super::ApiClientError::BadRequest(_)
| super::ApiClientError::Unexpected { .. }
| super::ApiClientError::InternalServerError(_)
| super::ApiClientError::Unauthorized(_) => Self::FailedToConnect,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::ApiClientError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataDecryptionError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataEncryptionError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataKeyTransferError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::DataKeyCreationError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::KeyManagerError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::EntityDBError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::StorageError) -> Self {
{
super::StorageError::DBPoolError | super::StorageError::PoolClientFailure => {
Self::DBError
}<|fim_suffix|>
<|fim_middle|>
super::StorageError::InsertError => Self::DBInsertError,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::TestDBError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::HashDBError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::VaultDBError) -> Self {
{
super::VaultDBError::DataEncryptionError | super::VaultDBError::DataDecryptionError => {
Self::MerchantKeyError
}
super::VaultDBError::DBError => Self::DatabaseError,<|fim_suffix|>
<|fim_middle|>
super::VaultDBError::UnknownError => Self::UnknownError,
super::VaultDBError::NotFoundError => Self::NotFoundError,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::MerchantDBError) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::CryptoError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::FingerprintDBError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::StorageError) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-card-vault/src/error/transforms.rs | crate: src
fn from(value: &'a super::StorageError) -> Self {
match value {
super::StorageError::DBPoolError | super::StorageError::PoolClientFailure => {
Self::DBError
}
super::StorageError::FindError => Self::DBFilterError,
super::StorageError::DecryptionError | super::StorageError::EncryptionError => {
Self::UnknownError
}
super::StorageError::InsertError => Self::DBInsertError,
super::StorageError::DeleteError => Self::DBDeleteError,
super::StorageError::NotFoundError => Self::NotFoundError,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
fn change_error(self, error: E2) -> Result<T, ContainerError<E2>> {
{
Ok(value) => Ok(value),<|fim_suffix|>
<|fim_middle|>
Err(err) => Err(ContainerError {
error: error_stack::Report::from(err).change_context(error),
}),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
fn source(&self) -> Option<&(dyn Error + 'static)> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
fn change_error(self, error: E2) -> Result<T, ContainerError<E2>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
fn from(value: ContainerError<T>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
fn source(&self) -> Option<&(dyn Error + 'static)> {
Error::source(self.error.current_context())
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/error/container.rs | crate: src
use std::error::Error;
pub fn get_inner(&self) -> &E {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/routes_v2/data.rs | crate: src
use axum::Json;
use crate::{
crypto::keymanager::{self, KeyProvider},
custom_extractors::TenantStateResolver,
error::{self, ContainerError, ResultContainerExt},
logger,
routes::data::{crypto_operation, types::Validation},
storage::storage_v2::VaultInterface,
utils,
};
pub async fn retrieve_data(
TenantStateResolver(tenant_app_state): TenantStateResolver,
Json(request): Json<types::RetrieveDataRequest>,
) -> Result<Json<types::RetrieveDataResponse>, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/routes_v2/data.rs | crate: src
use axum::Json;
use crate::{
crypto::keymanager::{self, KeyProvider},
custom_extractors::TenantStateResolver,
error::{self, ContainerError, ResultContainerExt},
logger,
routes::data::{crypto_operation, types::Validation},
storage::storage_v2::VaultInterface,
utils,
};
pub async fn delete_data(
TenantStateResolver(tenant_app_state): TenantStateResolver,
Json(request): Json<types::DeleteDataRequest>,
) -> Result<Json<types::DeleteDataResponse>, ContainerError<error::ApiError>> {
{
0 => logger::info!(delete_data_response = "data not found to delete"),<|fim_suffix|>
<|fim_middle|>
_ => logger::info!(delete_data_response=?response, "delete data was successful"),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/routes_v2/data.rs | crate: src
use axum::Json;
use crate::{
crypto::keymanager::{self, KeyProvider},
custom_extractors::TenantStateResolver,
error::{self, ContainerError, ResultContainerExt},
logger,
routes::data::{crypto_operation, types::Validation},
storage::storage_v2::VaultInterface,
utils,
};
pub async fn add_data(
TenantStateResolver(tenant_app_state): TenantStateResolver,
Json(request): Json<types::StoreDataRequest>,
) -> Result<Json<types::StoreDataResponse>, ContainerError<error::ApiError>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/routes_v2/data.rs | crate: src
use axum::Json;
use crate::{
crypto::keymanager::{self, KeyProvider},
custom_extractors::TenantStateResolver,
error::{self, ContainerError, ResultContainerExt},
logger,
routes::data::{crypto_operation, types::Validation},
storage::storage_v2::VaultInterface,
utils,
};
pub async fn delete_data(
TenantStateResolver(tenant_app_state): TenantStateResolver,
Json(request): Json<types::DeleteDataRequest>,
) -> Result<Json<types::DeleteDataResponse>, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
pub fn get_data_duplication_status(
stored_payload: &storage::types::Locker,
request_data: &types::Data,
) -> Result<DataDuplicationCheck, ContainerError<error::ApiError>> {
{
true => DataDuplicationCheck::Duplicated,<|fim_suffix|>
<|fim_middle|>
false => DataDuplicationCheck::MetaDataChanged,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn try_from(value: storage::types::Locker) -> Result<Self, Self::Error> {
{
types::StoredData::EncData(data) => (None, Some(data)),<|fim_suffix|>
<|fim_middle|>
types::StoredData::CardData(card) => (Some(card), None),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
pub fn get_data_duplication_status(
stored_payload: &storage::types::Locker,
request_data: &types::Data,
) -> Result<DataDuplicationCheck, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
pub fn get_hash<T>(
request: &types::Data,
hash_algorithm: T,
) -> Result<Vec<u8>, ContainerError<error::ApiError>>
where
T: Encode<
Vec<u8>,
Vec<u8>,
ReturnType<Vec<u8>> = Result<Vec<u8>, error::ContainerError<error::CryptoError>>,
>,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn eq(&self, other: &types::Data) -> bool {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn from(value: storage::types::Fingerprint) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn try_from(value: storage::types::Locker) -> Result<Self, Self::Error> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn from(value: storage::storage_v2::types::Vault) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-card-vault/src/routes/data/transformers.rs | crate: src
use crate::{
crypto::hash_manager::hash_interface::Encode,
error::{self, ContainerError, ResultContainerExt},
storage,
};
use super::types::{self, DataDuplicationCheck};
fn from(
(duplication_check, value): (Option<DataDuplicationCheck>, storage::types::Locker),
) -> Self {
Self {
status: types::Status::Ok,
payload: Some(super::types::StoreCardRespPayload {
card_reference: value.locker_id.expose(),
duplication_check,
dedup: None,
}),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/crypto_operation.rs | crate: src
use crate::{
app::TenantAppState,
crypto::keymanager::CryptoOperationsManager,
error::{self, ContainerError, ResultContainerExt},
routes::data::types,
storage::{
storage_v2::{types::VaultNew, VaultInterface},
types::{Locker, LockerNew},
LockerInterface,
},
};
pub async fn encrypt_data_and_insert_into_db_v2(
tenant_app_state: &TenantAppState,
crypto_operator: Box<dyn CryptoOperationsManager>,
request: crate::routes::routes_v2::data::types::StoreDataRequest,
) -> Result<crate::storage::storage_v2::types::Vault, ContainerError<error::ApiError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-card-vault/src/routes/data/crypto_operation.rs | crate: src
use crate::{
app::TenantAppState,
crypto::keymanager::CryptoOperationsManager,
error::{self, ContainerError, ResultContainerExt},
routes::data::types,
storage::{
storage_v2::{types::VaultNew, VaultInterface},
types::{Locker, LockerNew},
LockerInterface,
},
};
pub async fn encrypt_data_and_insert_into_db_v2(
tenant_app_state: &TenantAppState,
crypto_operator: Box<dyn CryptoOperationsManager>,
request: crate::routes::routes_v2::data::types::StoreDataRequest,
) -> Result<crate::storage::storage_v2::types::Vault, ContainerError<error::ApiError>> {
let data_to_be_encrypted = serde_json::to_vec(&request.data.clone().expose())
.change_error(error::ApiError::EncodingError)?;
let encrypted_data = crypto_operator
.encrypt_data(tenant_app_state, data_to_be_encrypted.into())
.await?;
let vault_new = VaultNew::new(request, encrypted_data.into());
let vault = tenant_app_state
.db
.insert_or_get_from_vault(vault_new)
.await?;
Ok(vault)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/crypto_operation.rs | crate: src
use crate::{
app::TenantAppState,
crypto::keymanager::CryptoOperationsManager,
error::{self, ContainerError, ResultContainerExt},
routes::data::types,
storage::{
storage_v2::{types::VaultNew, VaultInterface},
types::{Locker, LockerNew},
LockerInterface,
},
};
pub async fn decrypt_data<T>(
tenant_app_state: &TenantAppState,
crypto_operator: Box<dyn CryptoOperationsManager>,
mut data: T,
) -> Result<T, ContainerError<error::ApiError>>
where
T: types::SecretDataManager,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-card-vault/src/routes/data/crypto_operation.rs | crate: src
use crate::{
app::TenantAppState,
crypto::keymanager::CryptoOperationsManager,
error::{self, ContainerError, ResultContainerExt},
routes::data::types,
storage::{
storage_v2::{types::VaultNew, VaultInterface},
types::{Locker, LockerNew},
LockerInterface,
},
};
pub async fn encrypt_data_and_insert_into_db<'a>(
tenant_app_state: &'a TenantAppState,
crypto_operator: Box<dyn CryptoOperationsManager>,
request: types::StoreCardRequest,
hash_id: &'a str,
) -> Result<Locker, ContainerError<error::ApiError>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.