From 3a3ebd64bfb789327e0b52de5ae5f5822c7e9407 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 29 Oct 2023 17:01:38 +0800 Subject: [PATCH] feat: v0.7.1, compiles without smart card(encrypt only) --- Cargo.lock | 2 +- Cargo.toml | 12 ++++++++---- README.md | 5 +++++ src/cmd_version.rs | 9 +++++++-- src/lib.rs | 6 ++++++ src/main.rs | 6 +++++- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1133a70..5e2a74c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "0.7.0" +version = "0.7.1" dependencies = [ "aes-gcm-stream", "base64", diff --git a/Cargo.toml b/Cargo.toml index 6f90e0d..414175f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "0.7.0" +version = "0.7.1" edition = "2021" license = "MIT" description = "A simple and tiny file encrypt tool" @@ -8,6 +8,10 @@ repository = "https://git.hatter.ink/hatter/tiny-encrypt-rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["smartcard"] +smartcard = ["openpgp-card", "openpgp-card-pcsc", "yubikey"] + [dependencies] aes-gcm-stream = "0.2" base64 = "0.21" @@ -18,8 +22,8 @@ flate2 = "1.0" fs-set-times = "0.20" hex = "0.4" indicatif = "0.17" -openpgp-card = "0.3" -openpgp-card-pcsc = "0.3" +openpgp-card = { version = "0.3", optional = true } +openpgp-card-pcsc = { version = "0.3", optional = true } p256 = { version = "0.13", features = ["pem", "ecdh", "pkcs8"] } p384 = { version = "0.13", features = ["pem", "ecdh", "pkcs8"] } rand = "0.8" @@ -35,7 +39,7 @@ simpledateformat = "0.1" tabled = "0.14" x25519-dalek = "2.0" x509-parser = "0.15" -yubikey = { version = "0.8", features = ["untested"] } +yubikey = { version = "0.8", features = ["untested"], optional = true } zeroize = "1.6" [patch.crates-io] diff --git a/README.md b/README.md index 49222c5..f5871c3 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,11 @@ Set default encryption algorithm: export TINY_ENCRYPT_DEFAULT_ALGORITHM='AES' # or CHACHA20 ``` +Compile only encrypt: +```shell +cargo build --release --no-default-features +``` +
Encrypt config `~/.tinyencrypt/config-rs.json`: diff --git a/src/cmd_version.rs b/src/cmd_version.rs index 08df834..500a3d0 100644 --- a/src/cmd_version.rs +++ b/src/cmd_version.rs @@ -7,10 +7,15 @@ use crate::util; pub struct CmdVersion {} pub fn version(_cmd_version: CmdVersion) -> XResult<()> { + let mut features: Vec<&str> = vec![]; + #[cfg(feature = "smartcard")] + features.push("smartcard"); + if features.is_empty() { features.push("-"); } println!( - "User-Agent: {}\n{}", + "User-Agent: {} [ with features: {} ]\n{}", util::get_user_agent(), - env!("CARGO_PKG_DESCRIPTION"), + features.join(", "), + env!("CARGO_PKG_DESCRIPTION") ); Ok(()) } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d21b10e..6d313a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,10 @@ pub use cmd_config::CmdConfig; pub use cmd_config::config; +#[cfg(feature = "smartcard")] pub use cmd_decrypt::CmdDecrypt; +#[cfg(feature = "smartcard")] pub use cmd_decrypt::decrypt; +#[cfg(feature = "smartcard")] pub use cmd_decrypt::decrypt_single; pub use cmd_directdecrypt::CmdDirectDecrypt; pub use cmd_directdecrypt::direct_decrypt; @@ -20,7 +23,9 @@ mod util; mod util_env; mod util_digest; mod util_progress; +#[cfg(feature = "smartcard")] mod util_piv; +#[cfg(feature = "smartcard")] mod util_pgp; mod util_p256; mod util_p384; @@ -38,6 +43,7 @@ mod util_enc_file; mod cmd_version; mod cmd_config; mod cmd_info; +#[cfg(feature = "smartcard")] mod cmd_decrypt; mod cmd_encrypt; mod cmd_directdecrypt; diff --git a/src/main.rs b/src/main.rs index 028bf88..7438e7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ extern crate core; use clap::{Parser, Subcommand}; use rust_util::XResult; -use tiny_encrypt::{CmdConfig, CmdDecrypt, CmdDirectDecrypt, CmdEncrypt, CmdInfo, CmdVersion}; +use tiny_encrypt::{CmdConfig, CmdDirectDecrypt, CmdEncrypt, CmdInfo, CmdVersion}; +#[cfg(feature = "smartcard")] +use tiny_encrypt::CmdDecrypt; #[derive(Debug, Parser)] #[command(name = "tiny-encrypt-rs")] @@ -18,6 +20,7 @@ enum Commands { /// Encrypt file(s) #[command(arg_required_else_help = true, short_flag = 'e')] Encrypt(CmdEncrypt), + #[cfg(feature = "smartcard")] /// Decrypt file(s) #[command(arg_required_else_help = true, short_flag = 'd')] Decrypt(CmdDecrypt), @@ -39,6 +42,7 @@ fn main() -> XResult<()> { let args = Cli::parse(); match args.command { Commands::Encrypt(cmd_encrypt) => tiny_encrypt::encrypt(cmd_encrypt), + #[cfg(feature = "smartcard")] Commands::Decrypt(cmd_decrypt) => tiny_encrypt::decrypt(cmd_decrypt), Commands::DirectDecrypt(cmd_direct_decrypt) => tiny_encrypt::direct_decrypt(cmd_direct_decrypt), Commands::Info(cmd_info) => tiny_encrypt::info(cmd_info),