From f039c183b26d4393c44c4f92f63ccb8a9aa5e39d Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 25 Oct 2023 01:20:37 +0800 Subject: [PATCH] feat: 0.5.2, add --split-print --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- src/cmd_decrypt.rs | 17 +++++++++++------ src/util.rs | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a89901..91ce94a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,9 +183,9 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "base64ct" @@ -233,9 +233,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytecount" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad152d03a2c813c80bb94fedbf3a3f02b28f793e39e7c214c8a0bcc196343de7" +checksum = "d1a12477b7237a01c11a80a51278165f9ba0edd28fa6db00a65ab230320dc58c" [[package]] name = "byteorder" @@ -1141,9 +1141,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b" +checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023" [[package]] name = "powerfmt" @@ -1380,9 +1380,9 @@ dependencies = [ [[package]] name = "rust_util" -version = "0.6.43" +version = "0.6.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1934a25d960599cde936954c2b88942c63a7decf585cf12fa6aabcaa7e67644" +checksum = "45c3036388284b69995eb2864a943b0de55de76ad5b56fc2d3c60fecd7b9ad82" dependencies = [ "lazy_static", "libc", @@ -1729,7 +1729,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "0.5.1" +version = "0.5.2" dependencies = [ "aes-gcm-stream", "base64", diff --git a/Cargo.toml b/Cargo.toml index b493816..9caa5c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "0.5.1" +version = "0.5.2" edition = "2021" license = "MIT" description = "A simple and tiny file encrypt tool" diff --git a/src/cmd_decrypt.rs b/src/cmd_decrypt.rs index f132760..e094bc3 100644 --- a/src/cmd_decrypt.rs +++ b/src/cmd_decrypt.rs @@ -5,10 +5,7 @@ use std::time::{Instant, SystemTime}; use clap::Args; use openpgp_card::crypto_data::Cryptogram; -use rust_util::{ - debugging, failure, iff, information, opt_result, simple_error, success, - warning, XResult, -}; +use rust_util::{debugging, failure, iff, information, opt_result, println_ex, simple_error, success, util_msg, warning, XResult}; use rust_util::util_time::UnixEpochTime; use x509_parser::prelude::FromDer; use x509_parser::x509::SubjectPublicKeyInfo; @@ -51,6 +48,9 @@ pub struct CmdDecrypt { /// Direct print to the console, file must less than 10K #[arg(long, short = 'P')] pub direct_print: bool, + /// Split std out and std err + #[arg(long)] + pub split_print: bool, /// Digest file #[arg(long, short = 'D')] pub digest_file: bool, @@ -66,6 +66,7 @@ impl Drop for CmdDecrypt { } pub fn decrypt(cmd_decrypt: CmdDecrypt) -> XResult<()> { + if cmd_decrypt.split_print { util_msg::set_logger_std_out(false); } debugging!("Cmd decrypt: {:?}", cmd_decrypt); let config = TinyEncryptConfig::load(TINY_ENC_CONFIG_FILE).ok(); @@ -155,7 +156,11 @@ pub fn decrypt_single(config: &Option, )?; match String::from_utf8(output) { Err(_) => warning!("File is not UTF-8 content."), - Ok(output) => println!(">>>>> BEGIN CONTENT >>>>>\n{}\n<<<<< END CONTENT <<<<<", &output), + Ok(output) => if cmd_decrypt.split_print { + print!("{}", &output) + } else { + println!(">>>>> BEGIN CONTENT >>>>>\n{}\n<<<<< END CONTENT <<<<<", &output) + } } return Ok(meta.file_length); } @@ -381,7 +386,7 @@ fn select_envelop<'a>(meta: &'a TinyEncryptMeta, config: &Option XResult> { pub fn read_number(hint: &str, from: usize, to: usize) -> usize { loop { - print!("{} ({}-{}): ", hint, from, to); + print_ex!("{} ({}-{}): ", hint, from, to); io::stdout().flush().ok(); let mut buff = String::new(); let _ = io::stdin().read_line(&mut buff).expect("Read line from stdin");