feat: set default encryption algorithm

This commit is contained in:
2023-09-30 22:55:03 +08:00
parent b656d49933
commit 015fa42ca7
3 changed files with 6 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ use rust_util::{iff, opt_result, success, XResult};
use rust_util::util_time::get_current_millis; use rust_util::util_time::get_current_millis;
use simpledateformat::format_human2; use simpledateformat::format_human2;
use crate::file; use crate::{file, util};
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct CmdInfo { pub struct CmdInfo {
@@ -71,7 +71,7 @@ pub fn info(cmd_info: CmdInfo) -> XResult<()> {
let encryption_algorithm = if let Some(encryption_algorithm) = &meta.encryption_algorithm { let encryption_algorithm = if let Some(encryption_algorithm) = &meta.encryption_algorithm {
encryption_algorithm.to_string() encryption_algorithm.to_string()
} else { } else {
"AES/GCM (default)".to_string() format!("{} (default)", util::TINY_ENC_AES_GCM)
}; };
infos.push(format!("{}: {}", header("Encryption algorithm"), encryption_algorithm)); infos.push(format!("{}: {}", header("Encryption algorithm"), encryption_algorithm));

View File

@@ -4,7 +4,7 @@ use rust_util::util_time;
use rust_util::util_time::get_millis; use rust_util::util_time::get_millis;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::util::{encode_base64, get_user_agent}; use crate::util::{encode_base64, get_user_agent, TINY_ENC_AES_GCM};
pub const TINY_ENCRYPT_VERSION_10: &'static str = "1.0"; pub const TINY_ENCRYPT_VERSION_10: &'static str = "1.0";
pub const TINY_ENCRYPT_VERSION_11: &'static str = "1.1"; pub const TINY_ENCRYPT_VERSION_11: &'static str = "1.1";
@@ -96,7 +96,7 @@ impl TinyEncryptMeta {
ecdh_point: None, ecdh_point: None,
envelop: None, envelop: None,
envelops: Some(envelops), envelops: Some(envelops),
encryption_algorithm: None, // use none default encryption_algorithm: Some(TINY_ENC_AES_GCM.to_string()),
nonce: encode_base64(nonce), nonce: encode_base64(nonce),
file_length: metadata.len(), file_length: metadata.len(),
file_last_modified: match metadata.modified() { file_last_modified: match metadata.modified() {

View File

@@ -12,6 +12,8 @@ pub const ENC_AES256_GCM_P256: &str = "aes256-gcm-p256";
pub const TINY_ENC_FILE_EXT: &str = ".tinyenc"; pub const TINY_ENC_FILE_EXT: &str = ".tinyenc";
pub const TINY_ENC_CONFIG_FILE: &str = "~/.tinyencrypt/config-rs.json"; pub const TINY_ENC_CONFIG_FILE: &str = "~/.tinyencrypt/config-rs.json";
pub const TINY_ENC_AES_GCM: &str = "AES/GCM";
pub const TINY_ENC_MAGIC_TAG: u16 = 0x01; pub const TINY_ENC_MAGIC_TAG: u16 = 0x01;
pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> { pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {