feat: compatible with 1.0
This commit is contained in:
@@ -8,12 +8,12 @@ use clap::Args;
|
||||
use rsa::Pkcs1v15Encrypt;
|
||||
use rust_util::{debugging, failure, opt_result, simple_error, success, XResult};
|
||||
|
||||
use crate::util;
|
||||
use crate::compress::GzStreamEncoder;
|
||||
use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop};
|
||||
use crate::crypto_aes::aes_gcm_encrypt;
|
||||
use crate::crypto_rsa::parse_spki;
|
||||
use crate::spec::{EncMetadata, TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta};
|
||||
use crate::util;
|
||||
use crate::spec::{EncMetadata, TINY_ENCRYPT_VERSION_10, TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta};
|
||||
use crate::util::{ENC_AES256_GCM_P256, encode_base64, encode_base64_url_no_pad, make_key256_and_nonce, simple_kdf, TINY_ENC_CONFIG_FILE, zeroize};
|
||||
use crate::util_ecdh::compute_shared_secret;
|
||||
use crate::wrap_key::{WrapKey, WrapKeyHeader};
|
||||
@@ -86,17 +86,23 @@ fn encrypt_single(path: &PathBuf, envelops: &[&TinyEncryptConfigEnvelop], cmd_en
|
||||
debugging!("Encrypted meta: {:?}", encrypt_meta);
|
||||
|
||||
if cmd_encrypt.compatible_with_1_0 {
|
||||
if let Some(envelops) = &encrypt_meta.envelops {
|
||||
if let Some(envelops) = encrypt_meta.envelops {
|
||||
let mut filter_envelops = vec![];
|
||||
for envelop in envelops {
|
||||
if (envelop.r#type == TinyEncryptEnvelopType::Pgp) && encrypt_meta.pgp_envelop.is_none() {
|
||||
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_envelop.is_none() {
|
||||
} else if (envelop.r#type == TinyEncryptEnvelopType::Ecdh) && encrypt_meta.ecdh_envelop.is_none() {
|
||||
encrypt_meta.ecdh_point = Some(format!("KID:{}", envelop.kid));
|
||||
encrypt_meta.ecdh_envelop = Some(envelop.encrypted_key.clone());
|
||||
} else {
|
||||
filter_envelops.push(envelop);
|
||||
}
|
||||
}
|
||||
encrypt_meta.envelops = if filter_envelops.is_empty() { None } else { Some(filter_envelops) };
|
||||
if encrypt_meta.envelops.is_none() {
|
||||
encrypt_meta.version = TINY_ENCRYPT_VERSION_10.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::util::{encode_base64, get_user_agent};
|
||||
|
||||
// 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";
|
||||
|
||||
/// Specification: [Tiny Encrypt Spec V1.1](https://git.hatter.ink/hatter/tiny-encrypt-java/src/branch/master/TinyEncryptSpecV1.1.md)
|
||||
|
||||
Reference in New Issue
Block a user