Skip to content

Commit

Permalink
Upgrade versions of encryption library and db client library.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Jul 18, 2022
1 parent a5c9f87 commit e83ca57
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 105 deletions.
89 changes: 44 additions & 45 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tardis"
version = "0.1.0-alpha15"
version = "0.1.0-alpha16"
authors = ["gudaoxuri <i@sunisle.org>"]
description = "Elegant, clean Rust development framework"
keywords = ["http", "database", "web", "redis", "mq"]
Expand Down Expand Up @@ -32,7 +32,7 @@ crypto = ["rust-crypto", "rsa"]
crypto_with_sm = ["libsm", "num-bigint"]
rt_tokio = ["tokio"]
future = ["rt_tokio", "futures", "async-stream", "futures-util", "async-trait"]
reldb = ["future", "sqlparser", "sea-orm", "sea-query"]
reldb = ["future", "sqlparser", "sea-orm"]
web-server = ["trace", "future", "poem", "poem-openapi", "poem-openapi-derive"]
web-client = ["rt_tokio", "reqwest"]
cache = ["futures-util", "redis"]
Expand All @@ -43,77 +43,76 @@ test = ["testcontainers"]

[dependencies]
# Basic
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
derive_more = { version = "^0.99" }
nanoid = { version = "^0.4" }
base64 = { version = "^0.13" }
hex = { version = "^0.4" }
lazy_static = { version = "^1.4" }
log = { version = "^0.4" }
rand = { version = "^0.8" }
rand_core = { version = "^0.6" }
chrono = { version = "^0.4" }
env_logger = { version = "^0.9" }
config = { version = "^0.13" }
regex = { version = "^1.5" }
url = { version = "^2.2" }
openssl = { version = "^0.10", features = ["vendored"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
derive_more = { version = "0.99" }
nanoid = { version = "0.4" }
base64 = { version = "0.13" }
hex = { version = "0.4" }
lazy_static = { version = "1.4" }
log = { version = "0.4" }
rand = { version = "0.8" }
rand_core = { version = "0.6" }
chrono = { version = "0.4" }
env_logger = { version = "0.9" }
config = { version = "0.13" }
regex = { version = "1.5" }
url = { version = "2.2" }
openssl = { version = "0.10", features = ["vendored"] }

# Tokio
tokio = { version = "^1.18", features = ["macros", "rt-multi-thread", "signal", "time"], optional = true }
tokio = { version = "1.18", features = ["macros", "rt-multi-thread", "signal", "time"], optional = true }

# Crypto
rust-crypto = { version = "^0.2", optional = true }
rsa = { version = "^0.5", optional = true }
libsm = { version = "^0.5", optional = true }
num-bigint = { version = "^0.4.3", optional = true }
rust-crypto = { version = "0.2", optional = true }
rsa = { version = "0.6", features = ["pem"], optional = true }
libsm = { version = "0.5", optional = true }
num-bigint = { version = "0.4.3", optional = true }

# Future
futures = { version = "^0.3", optional = true }
async-stream = { version = "^0.3", optional = true }
futures-util = { version = "^0.3", optional = true }
async-trait = { version = "^0.1", optional = true }
futures = { version = "0.3", optional = true }
async-stream = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true }
async-trait = { version = "0.1", optional = true }

# Tracing
tracing = { version = "^0.1", optional = true }
tracing-subscriber = { version = "^0.3", features = ["env-filter"], optional = true }
tracing = { version = "0.1", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }

# RelDB
sea-orm = { version = "^0.8", features = ["sqlx-all", "macros", "runtime-tokio-native-tls", "debug-print"], optional = true }
sea-query = { version = "^0.24", optional = true }
sqlparser = { version = "^0.17", optional = true }
sea-orm = { version = "0.9", features = ["sqlx-all", "macros", "runtime-tokio-native-tls", "debug-print"], optional = true }
sqlparser = { version = "0.17", optional = true }

# Web Server
poem-openapi = { version = "^2", features = ["rapidoc", "chrono"], optional = true }
poem-openapi-derive = { version = "^2", optional = true }
poem = { version = "^1.3", features = ["csrf", "opentelemetry", "rustls", "prometheus", "websocket"], optional = true }
poem-openapi = { version = "2", features = ["rapidoc", "chrono"], optional = true }
poem-openapi-derive = { version = "2", optional = true }
poem = { version = "1.3", features = ["csrf", "opentelemetry", "rustls", "prometheus", "websocket"], optional = true }

# Web Client
reqwest = { version = "^0.11", features = ["json"], optional = true }
reqwest = { version = "0.11", features = ["json"], optional = true }

# Redis
redis = { version = "^0.21", features = ["tokio-comp", "tokio-native-tls-comp"], optional = true }
redis = { version = "0.21", features = ["tokio-comp", "tokio-native-tls-comp"], optional = true }

# Rabbit
lapin = { version = "^2.0", optional = true }
amq-protocol-types = { version = "^7.0", optional = true }
async-global-executor = { version = "^2.0", optional = true }
lapin = { version = "2.0", optional = true }
amq-protocol-types = { version = "7.0", optional = true }
async-global-executor = { version = "2.0", optional = true }

#Mail
lettre = { version = "0.10.0-rc.6", features = ["smtp-transport", "tokio1", "tokio1-native-tls", "builder"], optional = true }

#Object Storage
rust-s3 = { version = "^0.31", optional = true }
anyhow = { version = "^1.0", optional = true }
rust-s3 = { version = "0.31", optional = true }
anyhow = { version = "1.0", optional = true }

# Test
testcontainers = { version = "^0.14", optional = true }
testcontainers = { version = "0.14", optional = true }

[dev-dependencies]
# Common
tokio = { version = "^1.18", features = ["time", "rt", "macros"] }
criterion = { version = "^0.3" }
tokio = { version = "1.18", features = ["time", "rt", "macros"] }
criterion = { version = "0.3" }

[[test]]
name = "test_basic_config"
Expand Down
2 changes: 1 addition & 1 deletion benches/crypto_benchmark.rs
Expand Up @@ -42,7 +42,7 @@ Rust 拥有出色的文档、友好的编译器和清晰的错误提示信息,
let private_key = TardisFuns::crypto.rsa.new_private_key(2048).unwrap();
let public_key = TardisFuns::crypto.rsa.new_public_key(&private_key).unwrap();
let signed_data = private_key.sign("测试").unwrap();
let encrypted_data = private_key.encrypt("测试").unwrap();
let encrypted_data = public_key.encrypt("测试").unwrap();
c.bench_function("CRYPTO: rsa_sign", |b| {
b.iter(|| {
private_key.sign("测试").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-apps/doc/Cargo.toml
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
serde = { version = "^1", features = ["derive"] }

tardis = { path = "../../..", features = ["reldb", "web-server"] }
sea-orm = { version = "^0.8", features = ["macros"] }
sea-orm = { version = "^0.9", features = ["macros"] }
poem-openapi = { version = "^2" }
2 changes: 1 addition & 1 deletion examples/multi-apps/tag/Cargo.toml
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
serde = { version = "^1", features = ["derive"] }

tardis = { path = "../../..", features = ["reldb", "web-server"] }
sea-orm = { version = "^0.8", features = ["macros"] }
sea-orm = { version = "^0.9", features = ["macros"] }
poem-openapi = { version = "^2" }
2 changes: 1 addition & 1 deletion examples/multi-apps/tag/src/serv/tag_serv.rs
@@ -1,8 +1,8 @@
use tardis::basic::dto::TardisContext;
use tardis::basic::error::TardisError;
use tardis::basic::result::TardisResult;
use tardis::db::sea_orm::sea_query::{Expr, Query};
use tardis::db::sea_orm::*;
use tardis::db::sea_query::{Expr, Query};
use tardis::TardisFunsInst;

use crate::domain::tag;
Expand Down
2 changes: 1 addition & 1 deletion examples/perf-test/Cargo.toml
Expand Up @@ -10,4 +10,4 @@ tardis = { path = "../..", features = ["web-server", "reldb"] }
# Web server dependencies
poem-openapi = { version = "^2" }
# Reldb dependencies
sea-orm = { version = "^0.8", features = ["macros"] }
sea-orm = { version = "^0.9", features = ["macros"] }
2 changes: 1 addition & 1 deletion examples/perf-test/src/processor.rs
@@ -1,6 +1,6 @@
use tardis::basic::dto::TardisContext;
use tardis::db::sea_orm::sea_query::Query as DbQuery;
use tardis::db::sea_orm::*;
use tardis::db::sea_query::Query as DbQuery;
use tardis::serde::{self, Deserialize, Serialize};
use tardis::web::poem_openapi::param::Query;
use tardis::web::poem_openapi::{param::Path, payload::Json, Object, OpenApi};
Expand Down
2 changes: 1 addition & 1 deletion examples/reldb/Cargo.toml
Expand Up @@ -6,4 +6,4 @@ edition = "2021"

[dependencies]
tardis = { path = "../..", features = ["reldb", "test"] }
sea-orm = { version = "^0.8", features = ["macros"] }
sea-orm = { version = "^0.9", features = ["macros"] }
2 changes: 1 addition & 1 deletion examples/todos/Cargo.toml
Expand Up @@ -11,5 +11,5 @@ tardis = { path = "../..", features = ["web-server", "reldb", "test"] }
# Web server dependencies
poem-openapi = { version = "^2" }
# Reldb dependencies
sea-orm = { version = "^0.8", features = ["macros"] }
sea-orm = { version = "^0.9", features = ["macros"] }

2 changes: 1 addition & 1 deletion examples/todos/src/processor.rs
Expand Up @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize};

use tardis::basic::error::TardisError;
use tardis::basic::field::TrimString;
use tardis::db::sea_orm::sea_query::Query as DbQuery;
use tardis::db::sea_orm::*;
use tardis::db::sea_query::Query as DbQuery;
use tardis::web::context_extractor::TardisContextExtractor;
use tardis::web::poem_openapi::param::Query;
use tardis::web::poem_openapi::{param::Path, payload::Json, Object, OpenApi};
Expand Down
32 changes: 19 additions & 13 deletions src/basic/crypto.rs
Expand Up @@ -13,8 +13,8 @@ use libsm::{
#[cfg(feature = "crypto_with_sm")]
use num_bigint::BigUint;
use rand_core::RngCore;
use rsa::pkcs8::{FromPrivateKey, FromPublicKey, ToPrivateKey, ToPublicKey};
use rsa::{pkcs8, PublicKey};
use rsa::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey, EncodePublicKey, LineEnding};
use rsa::PublicKey;

use crate::basic::error::TardisError;
use crate::basic::result::TardisResult;
Expand All @@ -40,29 +40,41 @@ pub struct TardisCrypto {
#[cfg(feature = "crypto_with_sm")]
pub sm2: TardisCryptoSm2,
}

pub struct TardisCryptoHex;

pub struct TardisCryptoBase64;

pub struct TardisCryptoAes;

pub struct TardisCryptoRsa;

pub struct TardisCryptoRsaPrivateKey {
pri_key: rsa::RsaPrivateKey,
}

pub struct TardisCryptoRsaPublicKey {
pub_key: rsa::RsaPublicKey,
}

#[cfg(feature = "crypto_with_sm")]
pub struct TardisCryptoSm4;

#[cfg(feature = "crypto_with_sm")]
pub struct TardisCryptoSm2;

#[cfg(feature = "crypto_with_sm")]
pub struct TardisCryptoSm2PrivateKey {
pri_key: BigUint,
}

#[cfg(feature = "crypto_with_sm")]
pub struct TardisCryptoSm2PublicKey {
pub_key: Point,
}

pub struct TardisCryptoDigest;

pub struct TardisCryptoKey;

impl TardisCryptoHex {
Expand Down Expand Up @@ -229,12 +241,12 @@ impl TardisCryptoRsaPrivateKey {

pub fn from(private_key_pem: &str) -> TardisResult<Self> {
Ok(TardisCryptoRsaPrivateKey {
pri_key: rsa::RsaPrivateKey::from_pkcs8_pem(private_key_pem)?,
pri_key: rsa::RsaPrivateKey::from_pkcs8_pem(private_key_pem).map_err(|e| TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", e)))?,
})
}

pub fn serialize(&self) -> TardisResult<String> {
Ok(self.pri_key.to_pkcs8_pem()?.to_string())
Ok(self.pri_key.to_pkcs8_pem(LineEnding::LF).map_err(|e| TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", e)))?.to_string())
}

pub fn decrypt(&self, encrypted_data: &str) -> TardisResult<String> {
Expand All @@ -256,19 +268,19 @@ impl TardisCryptoRsaPublicKey {
}

pub fn from_private_key_str(private_key_pem: &str) -> TardisResult<Self> {
let private_key = rsa::RsaPrivateKey::from_pkcs8_pem(private_key_pem)?;
let private_key = rsa::RsaPrivateKey::from_pkcs8_pem(private_key_pem).map_err(|e| TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", e)))?;
let public_key = rsa::RsaPublicKey::from(private_key);
Ok(TardisCryptoRsaPublicKey { pub_key: public_key })
}

pub fn from_public_key_str(public_key_pem: &str) -> TardisResult<Self> {
Ok(TardisCryptoRsaPublicKey {
pub_key: rsa::RsaPublicKey::from_public_key_pem(public_key_pem)?,
pub_key: rsa::RsaPublicKey::from_public_key_pem(public_key_pem).map_err(|e| TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", e)))?,
})
}

pub fn serialize(&self) -> TardisResult<String> {
Ok(self.pub_key.to_public_key_pem()?)
self.pub_key.to_public_key_pem(LineEnding::LF).map_err(|e| TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", e)))
}

pub fn encrypt(&self, data: &str) -> TardisResult<String> {
Expand Down Expand Up @@ -554,9 +566,3 @@ impl From<rsa::errors::Error> for TardisError {
TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", error))
}
}

impl From<pkcs8::Error> for TardisError {
fn from(error: pkcs8::Error) -> Self {
TardisError::FormatError(format!("[Tardis.Crypto] RSA crypto error, {}", error))
}
}
1 change: 0 additions & 1 deletion src/db.rs
@@ -1,5 +1,4 @@
pub use sea_orm;
pub use sea_query;

pub mod domain;
pub mod reldb_client;
2 changes: 1 addition & 1 deletion src/db/domain/tardis_db_config.rs
Expand Up @@ -5,9 +5,9 @@ use crate::basic::dto::TardisContext;
use crate::db::domain::tardis_db_config;
use crate::db::reldb_client::{TardisActiveModel, TardisRelDBlConnection};
use crate::db::sea_orm::entity::prelude::*;
use crate::db::sea_orm::sea_query::{ColumnDef, Table, TableCreateStatement};
use crate::db::sea_orm::ActiveValue::Set;
use crate::db::sea_orm::{ActiveModelBehavior, DbBackend};
use crate::db::sea_query::{ColumnDef, Table, TableCreateStatement};
use crate::TardisResult;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
Expand Down
2 changes: 1 addition & 1 deletion src/db/domain/tardis_db_del_record.rs
@@ -1,9 +1,9 @@
use crate::basic::dto::TardisContext;
use crate::db::reldb_client::TardisActiveModel;
use crate::db::sea_orm::entity::prelude::*;
use crate::db::sea_orm::sea_query::{ColumnDef, Table, TableCreateStatement};
use crate::db::sea_orm::ActiveValue::Set;
use crate::db::sea_orm::{ActiveModelBehavior, DbBackend};
use crate::db::sea_query::{ColumnDef, Table, TableCreateStatement};
use crate::TardisFuns;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
Expand Down

0 comments on commit e83ca57

Please sign in to comment.