feat: update tiny-encrypt info
This commit is contained in:
@@ -3,7 +3,11 @@ use std::fs::File;
|
||||
use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use rust_util::{iff, information, opt_result, simple_error, success, XResult};
|
||||
|
||||
use rust_util::{iff, opt_result, success, XResult};
|
||||
use rust_util::util_time::get_current_millis;
|
||||
use simpledateformat::format_human2;
|
||||
|
||||
use crate::file;
|
||||
|
||||
pub fn info(path: PathBuf, raw_meta: bool) -> XResult<()> {
|
||||
@@ -20,15 +24,24 @@ pub fn info(path: PathBuf, raw_meta: bool) -> XResult<()> {
|
||||
let mut infos = vec![];
|
||||
infos.push("Tiny Encrypt File Info".to_string());
|
||||
let compressed = if meta.compress { " [compressed]" } else { "" };
|
||||
infos.push(format!("{}: {}{}", header("File"), path_display, compressed));
|
||||
infos.push(format!("{}: {}{}", header("File name"), path_display, compressed));
|
||||
infos.push(format!("{}: {} bytes", header("File size"), meta.file_length));
|
||||
infos.push(format!("{}: Version: {}, Agent: {}",
|
||||
header("Enc file summary"), meta.version, meta.user_agent)
|
||||
header("File summary"), meta.version, meta.user_agent)
|
||||
);
|
||||
|
||||
let now_millis = get_current_millis() as u64;
|
||||
let fmt = simpledateformat::fmt("EEE MMM dd HH:mm:ss z yyyy").unwrap();
|
||||
infos.push(format!("{}: {}", header("Last modified"), fmt.format_local(from_unix_epoch(meta.file_last_modified))));
|
||||
infos.push(format!("{}: {}", header("Enc file created"), fmt.format_local(from_unix_epoch(meta.created))));
|
||||
infos.push(format!("{}: {}, {} ago",
|
||||
header("Last modified"),
|
||||
fmt.format_local(from_unix_epoch(meta.file_last_modified)),
|
||||
format_human2(Duration::from_millis(now_millis - meta.file_last_modified))
|
||||
));
|
||||
infos.push(format!("{}: {}, {} ago",
|
||||
header("Created"),
|
||||
fmt.format_local(from_unix_epoch(meta.created)),
|
||||
format_human2(Duration::from_millis(now_millis - meta.created))
|
||||
));
|
||||
|
||||
meta.envelops.as_ref().map(|envelops| envelops.iter().enumerate().for_each(|(i, envelop)| {
|
||||
infos.push(format!("{}: {}{}{}",
|
||||
|
||||
41
src/spec.rs
41
src/spec.rs
@@ -2,6 +2,11 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const TINY_ENCRYPT_VERSION: &'static str = "1.0";
|
||||
|
||||
pub const ENVELOP_TYPE_KMS: &'static str = "kms";
|
||||
pub const ENVELOP_TYPE_PGP: &'static str = "pgp";
|
||||
pub const ENVELOP_TYPE_AGE: &'static str = "age";
|
||||
pub const ENVELOP_TYPE_ECDH: &'static str = "ecdh";
|
||||
|
||||
/// Specification: [Tiny Encrypt Spec V1.1](https://git.hatter.ink/hatter/tiny-encrypt-java/src/branch/master/TinyEncryptSpecV1.1.md)
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -51,17 +56,29 @@ impl TinyEncryptMeta {
|
||||
if self.envelops.is_none() {
|
||||
self.envelops = Some(vec![]);
|
||||
}
|
||||
self.normalize_ppg_envelop();
|
||||
self.normalize_envelop();
|
||||
self.normalize_pgp_envelop();
|
||||
self.normalize_age_envelop();
|
||||
self.normalize_ecdh_envelop();
|
||||
self.normalize_envelop();
|
||||
}
|
||||
|
||||
fn normalize_ppg_envelop(&mut self) {
|
||||
fn normalize_envelop(&mut self) {
|
||||
if let (Some(envelop), Some(envelops)) = (&self.envelop, &mut self.envelops) {
|
||||
envelops.push(TinyEncryptEnvelop {
|
||||
r#type: ENVELOP_TYPE_KMS.into(),
|
||||
kid: "".into(),
|
||||
desc: None,
|
||||
encrypted_key: envelop.into(),
|
||||
});
|
||||
self.envelop = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_pgp_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 {
|
||||
r#type: "pgp".to_string(),
|
||||
r#type: ENVELOP_TYPE_PGP.into(),
|
||||
kid: pgp_fingerprint.into(),
|
||||
desc: None,
|
||||
encrypted_key: pgp_envelop.into(),
|
||||
@@ -75,7 +92,7 @@ impl TinyEncryptMeta {
|
||||
if let (Some(age_envelop), Some(age_recipient), Some(envelops))
|
||||
= (&self.age_envelop, &self.age_recipient, &mut self.envelops) {
|
||||
envelops.push(TinyEncryptEnvelop {
|
||||
r#type: "age".to_string(),
|
||||
r#type: ENVELOP_TYPE_AGE.into(),
|
||||
kid: age_recipient.into(),
|
||||
desc: None,
|
||||
encrypted_key: age_envelop.into(),
|
||||
@@ -89,7 +106,7 @@ impl TinyEncryptMeta {
|
||||
if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops))
|
||||
= (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) {
|
||||
envelops.push(TinyEncryptEnvelop {
|
||||
r#type: "ecdh".to_string(),
|
||||
r#type: ENVELOP_TYPE_ECDH.into(),
|
||||
kid: ecdh_point.into(),
|
||||
desc: None,
|
||||
encrypted_key: ecdh_envelop.into(),
|
||||
@@ -98,16 +115,4 @@ impl TinyEncryptMeta {
|
||||
self.ecdh_point = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_envelop(&mut self) {
|
||||
if let (Some(envelop), Some(envelops)) = (&self.envelop, &mut self.envelops) {
|
||||
envelops.push(TinyEncryptEnvelop {
|
||||
r#type: "kms".to_string(),
|
||||
kid: "".into(),
|
||||
desc: None,
|
||||
encrypted_key: envelop.into(),
|
||||
});
|
||||
self.envelop = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user