feat: refactor naming
This commit is contained in:
16
src/spec.rs
16
src/spec.rs
@@ -49,6 +49,7 @@ pub struct TinyEncryptMeta {
|
|||||||
pub nonce: String,
|
pub nonce: String,
|
||||||
pub file_length: u64,
|
pub file_length: u64,
|
||||||
pub file_last_modified: u64,
|
pub file_last_modified: u64,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub file_edit_count: Option<u64>,
|
pub file_edit_count: Option<u64>,
|
||||||
pub compress: bool,
|
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() {
|
if self.envelops.is_none() {
|
||||||
self.envelops = Some(vec![]);
|
self.envelops = Some(vec![]);
|
||||||
}
|
}
|
||||||
self.normalize_envelop();
|
self.normalize_kms_envelop();
|
||||||
self.normalize_pgp_envelop();
|
self.normalize_pgp_rsa_envelop();
|
||||||
self.normalize_age_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) {
|
if let (Some(envelop), Some(envelops)) = (&self.envelop, &mut self.envelops) {
|
||||||
envelops.push(TinyEncryptEnvelop {
|
envelops.push(TinyEncryptEnvelop {
|
||||||
r#type: TinyEncryptEnvelopType::Kms,
|
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))
|
if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops))
|
||||||
= (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) {
|
= (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) {
|
||||||
envelops.push(TinyEncryptEnvelop {
|
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))
|
if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops))
|
||||||
= (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) {
|
= (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) {
|
||||||
envelops.push(TinyEncryptEnvelop {
|
envelops.push(TinyEncryptEnvelop {
|
||||||
|
|||||||
@@ -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)> {
|
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 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
|
meta_len_and_meta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user