diff --git a/Cargo.lock b/Cargo.lock index 7d7d2d4..7f6e972 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1556,9 +1556,9 @@ dependencies = [ [[package]] name = "rust_util" -version = "0.6.49" +version = "0.6.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "753ff5a55fa0dcb75b1249a306b037537cfe5b9ff84f685c9a85d17974453a8a" +checksum = "01736dfb1c97fec6b874d4939aac6db3b748c61cfd62183c7b80c4f1db003635" dependencies = [ "lazy_static", "libc", @@ -1989,7 +1989,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "1.9.9" +version = "1.9.10" dependencies = [ "aes-gcm-stream", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 45f7189..0f5f7fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "1.9.9" +version = "1.9.10" 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 7515d66..6272d46 100644 --- a/src/cmd_decrypt.rs +++ b/src/cmd_decrypt.rs @@ -1,4 +1,4 @@ -use std::{env, fs}; +use std::fs; use std::env::temp_dir; use std::fs::File; use std::io::{Read, Write}; @@ -16,6 +16,7 @@ use rust_util::{ debugging, failure, iff, information, opt_result, opt_value_result, println_ex, simple_error, success, util_cmd, util_msg, util_size, util_time, warning, XResult, }; +use rust_util::util_env as rust_util_env; use rust_util::util_time::UnixEpochTime; use x509_parser::prelude::FromDer; use x509_parser::x509::SubjectPublicKeyInfo; @@ -327,12 +328,12 @@ fn run_file_editor_and_wait_content(editor: &str, temp_file: &PathBuf, secure_ed } fn get_file_editor() -> (bool, String) { - if let Ok(secure_editor) = env::var("SECURE_EDITOR") { + if let Some(secure_editor) = rust_util_env::env_var("SECURE_EDITOR") { // cmd "aes-256-gcm" information!("Found secure editor: {}", &secure_editor); return (true, secure_editor); } - match env::var("EDITOR").ok() { + match rust_util_env::env_var("EDITOR") { Some(editor) => (false, editor), None => { warning!("EDITOR is not assigned, use default editor vi"); diff --git a/src/config.rs b/src/config.rs index df57043..f95cd4e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; use std::{env, fs}; +use rust_util::util_env as rust_util_env; use rust_util::util_file::resolve_file_path; use rust_util::{debugging, opt_result, simple_error, warning, XResult}; use serde::{Deserialize, Serialize}; - use crate::consts::{ENV_TINY_ENC_CONFIG_FILE, TINY_ENC_CONFIG_FILE, TINY_ENC_CONFIG_FILE_2, TINY_ENC_CONFIG_FILE_3, TINY_ENC_FILE_EXT}; use crate::spec::TinyEncryptEnvelopType; @@ -75,7 +75,7 @@ pub struct TinyEncryptConfigEnvelop { impl TinyEncryptConfig { pub fn load_default() -> XResult { - let resolved_file0 = env::var(ENV_TINY_ENC_CONFIG_FILE).ok(); + let resolved_file0 = rust_util_env::env_var(ENV_TINY_ENC_CONFIG_FILE); let resolved_file_1 = resolve_file_path(TINY_ENC_CONFIG_FILE); let resolved_file_2 = resolve_file_path(TINY_ENC_CONFIG_FILE_2); let resolved_file_3 = resolve_file_path(TINY_ENC_CONFIG_FILE_3); @@ -386,10 +386,10 @@ pub fn load_includes_and_merge(mut config: TinyEncryptConfig) -> TinyEncryptConf pub fn search_include_configs(includes_path: &str) -> Vec { let includes_path = if includes_path.starts_with("$") { let includes_path_env_var = includes_path.chars().skip(1).collect::(); - match env::var(&includes_path_env_var) { - Ok(includes_path) => includes_path, - Err(e) => { - warning!("Cannot find env var: {}, failed: {}", &includes_path_env_var, e); + match rust_util_env::env_var(&includes_path_env_var) { + Some(includes_path) => includes_path, + None => { + warning!("Cannot find env var: {}", &includes_path_env_var); return vec![]; } } diff --git a/src/util_env.rs b/src/util_env.rs index cc4005b..efbb92a 100644 --- a/src/util_env.rs +++ b/src/util_env.rs @@ -18,7 +18,7 @@ pub const TINY_ENCRYPT_ENV_NO_DEFAULT_PIN_HINT: &str = "TINY_ENCRYPT_NO_DEFAULT_ pub const TINY_ENCRYPT_ENV_PIN_ENTRY: &str = "TINY_ENCRYPT_PIN_ENTRY"; pub fn get_default_encryption_algorithm() -> Option<&'static str> { - let env_default_algorithm = env::var(TINY_ENCRYPT_ENV_DEFAULT_ALGORITHM).ok(); + let env_default_algorithm = rust_util_env::env_var(TINY_ENCRYPT_ENV_DEFAULT_ALGORITHM); debugging!("Environment variable {} = {:?}", TINY_ENCRYPT_ENV_DEFAULT_ALGORITHM, env_default_algorithm); if let Some(env_algorithm) = env_default_algorithm { let lower_default_algorithm = env_algorithm.to_lowercase(); @@ -36,11 +36,11 @@ pub fn get_pin() -> Option { } pub fn get_key_id() -> Option { - env::var(TINY_ENCRYPT_ENV_KEY_ID).ok() + rust_util_env::env_var(TINY_ENCRYPT_ENV_KEY_ID) } pub fn get_gpg_cmd() -> Option { - env::var(TINY_ENCRYPT_ENV_GPG_COMMAND).ok() + rust_util_env::env_var(TINY_ENCRYPT_ENV_GPG_COMMAND) } pub fn get_default_pin_entry() -> Option { @@ -54,7 +54,7 @@ pub fn get_default_pin_entry() -> Option { } pub fn get_pin_entry() -> Option { - env::var(TINY_ENCRYPT_ENV_PIN_ENTRY).ok() + rust_util_env::env_var(TINY_ENCRYPT_ENV_PIN_ENTRY) } pub fn get_auto_select_key_ids() -> Option> { @@ -66,7 +66,7 @@ pub fn get_auto_compress_file_exts() -> Option> { } pub fn get_default_compress() -> Option { - env::var(TINY_ENCRYPT_ENV_DEFAULT_COMPRESS).ok().map(|val| util_env::is_on(&val)) + rust_util_env::env_var(TINY_ENCRYPT_ENV_DEFAULT_COMPRESS).map(|val| util_env::is_on(&val)) } pub fn get_no_progress() -> bool { @@ -82,7 +82,7 @@ pub fn get_use_dialoguer() -> bool { } fn get_env_with_split(env_name: &str) -> Option> { - let val = env::var(env_name).ok(); + let val = rust_util_env::env_var(env_name); debugging!("Environment variable {} = {:?}", env_name, &val); val.map(|env_values| { env_values.split(',').map(ToString::to_string).collect::>()