Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unstable_features = true

group_imports = "StdExternalCrate" # Unstable
imports_granularity = "Crate" # Unstable
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tartarus"
version = "0.1.3"
edition = "2021"
edition = "2024"
default-run = "locker"
rust-version = "1.85"

Expand Down
7 changes: 5 additions & 2 deletions benches/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
clippy::unwrap_in_result
)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use josekit::jwe;
use rand::rngs::OsRng;
use rsa::{pkcs8::EncodePrivateKey, pkcs8::EncodePublicKey, RsaPrivateKey, RsaPublicKey};
use rsa::{
RsaPrivateKey, RsaPublicKey,
pkcs8::{EncodePrivateKey, EncodePublicKey},
};
use tartarus::crypto::encryption_manager::{
encryption_interface::Encryption,
managers::{aes, jw},
Expand Down
2 changes: 1 addition & 1 deletion benches/hashing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::expect_used)]
#![allow(clippy::missing_panics_doc)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use tartarus::crypto::hash_manager::{hash_interface::Encode, managers::sha::HmacSha512};

const ITERATION: u32 = 14;
Expand Down
4 changes: 2 additions & 2 deletions benches/luhn-test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tartarus::validations::{luhn, MAX_CARD_NUMBER_LENGTH};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use tartarus::validations::{MAX_CARD_NUMBER_LENGTH, luhn};

#[allow(clippy::expect_used)]
fn card_number_generator() -> Vec<u8> {
Expand Down
16 changes: 8 additions & 8 deletions src/api_client.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::str::FromStr;

#[cfg(feature = "external_key_manager")]
use crate::config::ExternalKeyManagerConfig;
use crate::{
config::GlobalConfig,
error::{self, ResultContainerExt},
};
use hyperswitch_masking::Maskable;
#[cfg(feature = "external_key_manager")]
use hyperswitch_masking::PeekInterface;
use reqwest::StatusCode;
use reqwest::{
Response, StatusCode,
header::{HeaderMap, HeaderName, HeaderValue},
Response,
};

#[cfg(feature = "external_key_manager")]
use crate::config::ExternalKeyManagerConfig;
use crate::{
config::GlobalConfig,
error::{self, ResultContainerExt},
};

pub type Headers = std::collections::HashSet<(String, Maskable<String>)>;
Expand Down
15 changes: 6 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::sync::Arc;

#[cfg(feature = "middleware")]
use axum::middleware;
use axum::{extract::Request, routing::post};
use axum_server::tls_rustls::RustlsConfig;
use error_stack::ResultExt;
use tower_http::trace as tower_trace;

#[cfg(feature = "middleware")]
use crate::middleware as custom_middleware;

#[cfg(feature = "middleware")]
use axum::middleware;

use std::sync::Arc;

#[cfg(feature = "caching")]
use crate::storage::caching::Caching;
use crate::{
api_client::ApiClient,
config::{self, GlobalConfig, TenantConfig},
Expand All @@ -21,9 +21,6 @@ use crate::{
utils,
};

#[cfg(feature = "caching")]
use crate::storage::caching::Caching;

#[cfg(feature = "caching")]
type Storage = Caching<storage::Storage>;

Expand Down
4 changes: 2 additions & 2 deletions src/bin/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
//! Simple Cli tool for generating keys to be used in the locker before deployment
//!

use std::io::{stdin, stdout, Read, Write};
use std::io::{Read, Write, stdin, stdout};

use josekit::jwe;
use tartarus::{
crypto::encryption_manager::{
encryption_interface::Encryption,
managers::{
aes::{generate_aes256_key, GcmAes256},
aes::{GcmAes256, generate_aes256_key},
jw::JWEncryption,
},
},
Expand Down
20 changes: 11 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
use std::{
collections::HashMap,
ops::{Deref, DerefMut},
path::PathBuf,
};

use error_stack::ResultExt;
use hyperswitch_masking::ExposeInterface;
#[cfg(feature = "external_key_manager")]
use hyperswitch_masking::Secret;

use crate::{
api_client::ApiClientConfig,
crypto::secrets_manager::{
Expand All @@ -6,15 +17,6 @@ use crate::{
error,
logger::config::Log,
};
use error_stack::ResultExt;
use hyperswitch_masking::ExposeInterface;
#[cfg(feature = "external_key_manager")]
use hyperswitch_masking::Secret;
use std::{
collections::HashMap,
ops::{Deref, DerefMut},
path::PathBuf,
};

#[derive(Clone, serde::Deserialize, Debug)]
pub struct GlobalConfig {
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/encryption_manager/managers/aes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use error_stack::ResultExt;
use ring::aead::{self, BoundKey};

use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use error_stack::ResultExt;
use ring::aead::{self, BoundKey};
///
/// GcmAes256
///
Expand Down
13 changes: 9 additions & 4 deletions src/crypto/encryption_manager/managers/jw.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use hyperswitch_masking::PeekInterface;
use josekit::{jwe, jws};

use crate::{
crypto::encryption_manager::encryption_interface::Encryption,
error::{self, ContainerError},
};
use hyperswitch_masking::PeekInterface;
use josekit::{jwe, jws};

pub struct JWEncryption {
pub(crate) private_key: hyperswitch_masking::Secret<String>,
Expand Down Expand Up @@ -176,9 +177,13 @@ pub fn verify_sign(jws_body: String, key: impl AsRef<[u8]>) -> Result<String, er
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used)]

use super::*;
use rand::rngs::OsRng;
use rsa::{pkcs8::EncodePrivateKey, pkcs8::EncodePublicKey, RsaPrivateKey, RsaPublicKey};
use rsa::{
RsaPrivateKey, RsaPublicKey,
pkcs8::{EncodePrivateKey, EncodePublicKey},
};

use super::*;

fn generate_rsa_key_pair() -> (String, String) {
let mut rng = OsRng;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/keymanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pub mod internal_keymanager;
#[cfg(feature = "external_key_manager")]
pub mod external_keymanager;

pub use crate::config::ExternalKeyManagerConfig;
use hyperswitch_masking::{Secret, StrongSecret};

pub use crate::config::ExternalKeyManagerConfig;
use crate::{
app::TenantAppState,
error::{self, ContainerError},
};
use hyperswitch_masking::{Secret, StrongSecret};

#[async_trait::async_trait]
pub trait KeyProvider: Send + Sync {
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/keymanager/external_keymanager.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
pub mod types;
pub mod utils;

pub use crate::config::ExternalKeyManagerConfig;
use hyperswitch_masking::{Secret, StrongSecret};

pub use crate::config::ExternalKeyManagerConfig;
use crate::{
api_client::{ApiResponse, Method},
app::TenantAppState,
crypto::keymanager::{
CryptoOperationsManager,
external_keymanager::{
self,
types::{
Expand All @@ -15,13 +17,11 @@ use crate::{
DateEncryptionResponse, DecryptedData, EncryptedData,
},
},
CryptoOperationsManager,
},
error::{self, ContainerError, NotFoundError},
routes::health,
storage::{types::Entity, EntityInterface},
storage::{EntityInterface, types::Entity},
};
use hyperswitch_masking::{Secret, StrongSecret};

pub async fn create_key_in_key_manager(
tenant_app_state: &TenantAppState,
Expand Down
16 changes: 9 additions & 7 deletions src/crypto/keymanager/external_keymanager/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::{
crypto::{self, consts::BASE64_ENGINE},
error::{self, ResultContainerExt},
storage::{consts, types::Encrypted, utils},
};
use std::fmt;

use base64::Engine;
use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
use serde::{
de::{self, Unexpected, Visitor},
Deserialize, Deserializer, Serialize, Serializer,
de::{self, Unexpected, Visitor},
};

use crate::{
crypto::{self, consts::BASE64_ENGINE},
error::{self, ResultContainerExt},
storage::{consts, types::Encrypted, utils},
};
use std::fmt;

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct DataKeyCreateRequest {
Expand Down
3 changes: 1 addition & 2 deletions src/crypto/keymanager/external_keymanager/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use base64::Engine;
use hyper::header::{AUTHORIZATION, CONTENT_TYPE};
use hyperswitch_masking::{Mask, Maskable};

use crate::storage::consts::X_TENANT_ID;
use crate::{app::TenantAppState, crypto::consts::BASE64_ENGINE};
use crate::{app::TenantAppState, crypto::consts::BASE64_ENGINE, storage::consts::X_TENANT_ID};

pub fn get_key_manager_header(
tenant_app_state: &TenantAppState,
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/secrets_manager/managers/aws_kms/core.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Interactions with the AWS KMS SDK

use aws_config::meta::region::RegionProviderChain;
use aws_sdk_kms::{config::Region, primitives::Blob, Client};
use aws_sdk_kms::{Client, config::Region, primitives::Blob};
use base64::Engine;
use error_stack::{report, ResultExt};
use error_stack::{ResultExt, report};

use crate::{crypto::consts::BASE64_ENGINE, error::ConfigurationError, logger};

Expand Down
1 change: 0 additions & 1 deletion src/crypto/secrets_manager/secrets_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::crypto::secrets_manager::managers::aws_kms::core::{AwsKmsClient, AwsK
use crate::crypto::secrets_manager::managers::hcvault::core::{
HashiCorpVault, HashiCorpVaultConfig,
};

use crate::{
crypto::secrets_manager::{
managers::hollow::core::NoEncryption,
Expand Down
6 changes: 3 additions & 3 deletions src/logger/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use std::{
use once_cell::sync::Lazy;
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::{
Layer,
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};

use super::storage::Storage;

// TODO: Documentation coverage for this crate

// Implicit keys
Expand Down
2 changes: 1 addition & 1 deletion src/logger/setup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Setup logging subsystem.

use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, prelude::*, util::SubscriberInitExt, EnvFilter, Layer};
use tracing_subscriber::{EnvFilter, Layer, fmt, prelude::*, util::SubscriberInitExt};

use super::{config, formatter::FormattingLayer, storage::StorageSubscription};

Expand Down
4 changes: 2 additions & 2 deletions src/logger/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use std::{collections::HashMap, fmt, time::Instant};

use tracing::{
Id, Subscriber,
field::{Field, Visit},
span::{Attributes, Record},
Id, Subscriber,
};
use tracing_subscriber::{layer::Context, Layer};
use tracing_subscriber::{Layer, layer::Context};

/// Storage to store key value pairs of spans.
#[derive(Clone, Debug)]
Expand Down
17 changes: 9 additions & 8 deletions src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use axum::{
body::Body,
http::{Request, request, response},
middleware::Next,
};
use http_body_util::BodyExt;
use josekit::jwe;

use crate::{
crypto::encryption_manager::{
encryption_interface::Encryption,
managers::jw::{self, JWEncryption},
},
custom_extractors::TenantStateResolver,
error::{self, ContainerError, ResultContainerExt},
};

use crate::custom_extractors::TenantStateResolver;
use axum::body::Body;
use axum::http::{request, response};
use axum::{http::Request, middleware::Next};

use http_body_util::BodyExt;
use josekit::jwe;

/// Middleware providing implementation to perform JWE + JWS encryption and decryption around the
/// card APIs
pub async fn middleware(
Expand Down
6 changes: 2 additions & 4 deletions src/routes/data.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;

use axum::{routing::post, Json};

use axum::{Json, routing::post};
#[cfg(feature = "limit")]
use axum::{error_handling::HandleErrorLayer, response::IntoResponse};

use self::types::Validation;
use crate::{
crypto::{hash_manager::managers::sha::Sha512, keymanager},
custom_extractors::TenantStateResolver,
Expand All @@ -15,8 +15,6 @@ use crate::{
utils,
};

use self::types::Validation;

pub mod crypto_operation;
mod transformers;
pub mod types;
Expand Down
Loading
Loading