feat: add comptible with 1.0

This commit is contained in:
2023-09-30 20:27:04 +08:00
parent 7ecee69c01
commit 7a3cb8d243
2 changed files with 23 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ pub struct CmdDecrypt {
/// PIN
#[arg(long, short = 'p')]
pub pin: Option<String>,
/// SLOT
/// Slot
#[arg(long, short = 's')]
pub slot: Option<String>,
}

View File

@@ -22,17 +22,21 @@ use crate::wrap_key::{WrapKey, WrapKeyHeader};
pub struct CmdEncrypt {
/// Files need to be decrypted
pub paths: Vec<PathBuf>,
// Comment
/// Comment
#[arg(long, short = 'c')]
pub comment: Option<String>,
// Comment
/// Encrypted comment
#[arg(long, short = 'C')]
pub encrypted_comment: Option<String>,
// Encryption profile
/// Encryption profile
#[arg(long, short = 'p')]
pub profile: Option<String>,
/// Compress before encrypt
#[arg(long, short = 'x')]
pub compress: bool,
/// Compatible with 1.0
#[arg(long, short = '1')]
pub compatible_with_1_0: bool,
}
pub fn encrypt(cmd_encrypt: CmdEncrypt) -> XResult<()> {
@@ -78,9 +82,23 @@ fn encrypt_single(path: &PathBuf, envelops: &[&TinyEncryptConfigEnvelop], cmd_en
compress: cmd_encrypt.compress,
};
let encrypt_meta = TinyEncryptMeta::new(&file_metadata, &enc_metadata, &nonce, envelops);
let mut encrypt_meta = TinyEncryptMeta::new(&file_metadata, &enc_metadata, &nonce, envelops);
debugging!("Encrypted meta: {:?}", encrypt_meta);
if cmd_encrypt.compatible_with_1_0 {
if let Some(envelops) = &encrypt_meta.envelops {
for envelop in envelops {
if envelop.r#type == TinyEncryptEnvelopType::Pgp {
encrypt_meta.pgp_fingerprint = Some(format!("KID:{}", envelop.kid));
encrypt_meta.pgp_envelop = Some(envelop.encrypted_key.clone());
}
if envelop.r#type == TinyEncryptEnvelopType::Ecdh {
encrypt_meta.ecdh_point = Some(format!("KID:{}", envelop.kid));
encrypt_meta.ecdh_envelop = Some(envelop.encrypted_key.clone());
}
}
}
}
let mut file_out = File::create(&path_out)?;
opt_result!(file_out.write_all(&util::TINY_ENC_MAGIC_TAG.to_be_bytes()), "Write tag failed: {}");