feat: v1.9.7

This commit is contained in:
2025-07-27 11:01:40 +08:00
parent 920aa92b0e
commit e308809b20
4 changed files with 16 additions and 10 deletions

2
Cargo.lock generated
View File

@@ -1989,7 +1989,7 @@ dependencies = [
[[package]]
name = "tiny-encrypt"
version = "1.9.6"
version = "1.9.7"
dependencies = [
"aes-gcm-stream",
"base64 0.22.1",

View File

@@ -1,6 +1,6 @@
[package]
name = "tiny-encrypt"
version = "1.9.6"
version = "1.9.7"
edition = "2021"
license = "MIT"
description = "A simple and tiny file encrypt tool"

View File

@@ -7,7 +7,7 @@ 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::{TINY_ENC_CONFIG_FILE, TINY_ENC_CONFIG_FILE_2, TINY_ENC_CONFIG_FILE_3, TINY_ENC_FILE_EXT};
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;
/// Config file sample:
@@ -75,12 +75,17 @@ pub struct TinyEncryptConfigEnvelop {
impl TinyEncryptConfig {
pub fn load_default() -> XResult<Self> {
let resolved_file = resolve_file_path(TINY_ENC_CONFIG_FILE);
let resolved_file0 = env::var(ENV_TINY_ENC_CONFIG_FILE).ok();
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);
let config_file = if fs::metadata(&resolved_file).is_ok() {
debugging!("Load config from: {resolved_file}");
resolved_file
if let Some(resolved_file) = resolved_file0 {
debugging!("Found tiny encrypt config file: {}", &resolved_file);
return Self::load(&resolved_file)
}
let config_file = if fs::metadata(&resolved_file_1).is_ok() {
debugging!("Load config from: {resolved_file_1}");
resolved_file_1
} else if fs::metadata(&resolved_file_2).is_ok() {
debugging!("Load config from: {resolved_file_2}");
resolved_file_2
@@ -88,8 +93,8 @@ impl TinyEncryptConfig {
debugging!("Load config from: {resolved_file_3}");
resolved_file_3
} else {
warning!("Cannot find config file from:\n- {resolved_file}\n- {resolved_file_2}\n- {resolved_file_3}");
resolved_file
warning!("Cannot find config file from:\n- {resolved_file_1}\n- {resolved_file_2}\n- {resolved_file_3}");
resolved_file_1
};
Self::load(&config_file)
}
@@ -294,7 +299,7 @@ pub fn resolve_path_namespace(
pub fn load_includes_and_merge(mut config: TinyEncryptConfig) -> TinyEncryptConfig {
if let Some(includes) = &config.includes {
let sub_configs = search_include_configs(&includes);
let sub_configs = search_include_configs(includes);
debugging!(
"Found {} sub configs, detail {:?}",
sub_configs.len(),

View File

@@ -11,6 +11,7 @@ pub const ENC_CHACHA20_POLY1305_KYBER1204: &str = "chacha20-poly1305-kyber1204";
// Extend and config file
pub const TINY_ENC_FILE_EXT: &str = ".tinyenc";
pub const TINY_ENC_PEM_FILE_EXT: &str = ".tinyenc.pem";
pub const ENV_TINY_ENC_CONFIG_FILE: &str = "TINY_ENCRYPT_CONFIG_FILE";
pub const TINY_ENC_CONFIG_FILE: &str = "~/.tinyencrypt/config-rs.json";
pub const TINY_ENC_CONFIG_FILE_2: &str = "~/.config/tinyencrypt-rs.json";
pub const TINY_ENC_CONFIG_FILE_3: &str = "/etc/tinyencrypt/config-rs.json";