|
|
|
|
@@ -1,5 +1,8 @@
|
|
|
|
|
use std::cmp::max;
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::ops::Add;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::time::{Duration, SystemTime};
|
|
|
|
|
use rust_util::{information, opt_result, simple_error, XResult};
|
|
|
|
|
use crate::file;
|
|
|
|
|
|
|
|
|
|
@@ -10,24 +13,43 @@ pub fn info(path: PathBuf) -> XResult<()> {
|
|
|
|
|
|
|
|
|
|
let mut infos = vec![];
|
|
|
|
|
infos.push("Tiny Encrypt File Info".to_string());
|
|
|
|
|
infos.push(format!("File..............: {}", path_display));
|
|
|
|
|
infos.push(format!("File size.........: {} bytes", meta.file_length));
|
|
|
|
|
infos.push(format!("Enc file summary..: Version: {}, Agent: {}", meta.version, meta.user_agent));
|
|
|
|
|
infos.push(format!("Last modified.....: {}", meta.file_last_modified));
|
|
|
|
|
infos.push(format!("Enc file created..: {}", meta.created));
|
|
|
|
|
infos.push(format!("Envelops..........: KMS: {}, PGP: {}",
|
|
|
|
|
let compressed = if meta.compress { " [compressed]" } else { "" };
|
|
|
|
|
infos.push(format!("{}: {}{}", header("File"), 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)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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!("{}: KMS: {}, PGP: {}",
|
|
|
|
|
header("Envelops"),
|
|
|
|
|
to_yes_or_no(&meta.envelop),
|
|
|
|
|
to_yes_or_no(&meta.pgp_envelop)
|
|
|
|
|
));
|
|
|
|
|
meta.pgp_fingerprint.map(|fingerprint| {
|
|
|
|
|
infos.push(format!("PGP fingerprint...: {}", fingerprint));
|
|
|
|
|
infos.push(format!("{}: {}", header("PGP fingerprint"), fingerprint));
|
|
|
|
|
});
|
|
|
|
|
infos.push(format!("Encrypted comment.: {}", to_yes_or_no(&meta.encrypted_comment)));
|
|
|
|
|
meta.comment.map(|comment| {
|
|
|
|
|
infos.push(format!("{}: {}", header("Comment"), comment));
|
|
|
|
|
});
|
|
|
|
|
infos.push(format!("{}: {}", header("Encrypted comment"), to_yes_or_no(&meta.encrypted_comment)));
|
|
|
|
|
|
|
|
|
|
information!("{}\n", infos.join("\n"));
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_unix_epoch(t: u64) -> SystemTime {
|
|
|
|
|
SystemTime::UNIX_EPOCH.add(Duration::from_millis(t))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn header(h: &str) -> String {
|
|
|
|
|
let width = 18;
|
|
|
|
|
h.to_string() + ".".repeat(max(width - h.len(), 0)).as_str()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn to_yes_or_no(opt: &Option<String>) -> String {
|
|
|
|
|
opt.as_ref().map(|_| "YES".to_string()).unwrap_or_else(|| "NO".to_string())
|
|
|
|
|
}
|