From f9a5f39330bb169e4540da7deec3df616d94f2fa Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 10 Dec 2023 15:16:45 +0800 Subject: [PATCH] feat: refactor naming --- src/spec.rs | 16 +++++++++------- src/util_enc_file.rs | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/spec.rs b/src/spec.rs index 20810f2..1bfbfaf 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -49,6 +49,7 @@ pub struct TinyEncryptMeta { pub nonce: String, pub file_length: u64, pub file_last_modified: u64, + #[serde(skip_serializing_if = "Option::is_none")] pub file_edit_count: Option, pub compress: bool, } @@ -196,17 +197,18 @@ impl TinyEncryptMeta { } } - pub fn normalize(&mut self) { + // compatibility with legacy tiny encrypt format + pub fn normalize_envelops(&mut self) { if self.envelops.is_none() { self.envelops = Some(vec![]); } - self.normalize_envelop(); - self.normalize_pgp_envelop(); + self.normalize_kms_envelop(); + self.normalize_pgp_rsa_envelop(); self.normalize_age_envelop(); - self.normalize_ecdh_envelop(); + self.normalize_piv_p256_envelop(); } - fn normalize_envelop(&mut self) { + fn normalize_kms_envelop(&mut self) { if let (Some(envelop), Some(envelops)) = (&self.envelop, &mut self.envelops) { envelops.push(TinyEncryptEnvelop { r#type: TinyEncryptEnvelopType::Kms, @@ -218,7 +220,7 @@ impl TinyEncryptMeta { } } - fn normalize_pgp_envelop(&mut self) { + fn normalize_pgp_rsa_envelop(&mut self) { if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops)) = (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) { envelops.push(TinyEncryptEnvelop { @@ -246,7 +248,7 @@ impl TinyEncryptMeta { } } - fn normalize_ecdh_envelop(&mut self) { + fn normalize_piv_p256_envelop(&mut self) { if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops)) = (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) { envelops.push(TinyEncryptEnvelop { diff --git a/src/util_enc_file.rs b/src/util_enc_file.rs index c7c10cd..612780b 100644 --- a/src/util_enc_file.rs +++ b/src/util_enc_file.rs @@ -24,7 +24,7 @@ pub fn write_tiny_encrypt_meta(write: &mut impl Write, meta: &TinyEncryptMeta, c pub fn read_tiny_encrypt_meta_and_normalize(r: &mut impl Read) -> XResult<(u32, bool, TinyEncryptMeta)> { let mut meta_len_and_meta = read_tiny_encrypt_meta(r); - let _ = meta_len_and_meta.as_mut().map(|ml| ml.2.normalize()); + let _ = meta_len_and_meta.as_mut().map(|ml| ml.2.normalize_envelops()); meta_len_and_meta }