feat: updates
This commit is contained in:
@@ -18,8 +18,7 @@ pub fn decrypt(path: &PathBuf, pin: &Option<String>) -> XResult<()> {
|
||||
return simple_error!("File is not tiny encrypt file: {}", &path_display);
|
||||
}
|
||||
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
||||
let mut meta = opt_result!(file::read_tiny_encrypt_meta(&mut file_in), "Read file: {}, failed: {}", &path_display);
|
||||
meta.normalize();
|
||||
let meta = opt_result!(file::read_tiny_encrypt_meta_and_normalize(&mut file_in), "Read file: {}, failed: {}", &path_display);
|
||||
|
||||
let path_out = &path_display[0..path_display.len() - TINY_ENC_FILE_EXT.len()];
|
||||
if let Ok(_) = fs::metadata(path_out) {
|
||||
|
||||
@@ -13,8 +13,7 @@ use crate::file;
|
||||
pub fn info(path: PathBuf, raw_meta: bool) -> XResult<()> {
|
||||
let path_display = format!("{}", path.display());
|
||||
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
||||
let mut meta = opt_result!(file::read_tiny_encrypt_meta(&mut file_in), "Read file: {}, failed: {}", &path_display);
|
||||
meta.normalize();
|
||||
let meta = opt_result!(file::read_tiny_encrypt_meta_and_normalize(&mut file_in), "Read file: {}, failed: {}", &path_display);
|
||||
|
||||
if raw_meta {
|
||||
success!("Meta data:\n{}", serde_json::to_string_pretty(&meta).expect("SHOULD NOT HAPPEN"));
|
||||
|
||||
@@ -16,6 +16,12 @@ pub fn write_tiny_encrypt_meta<W: Write>(w: &mut W, meta: &TinyEncryptMeta) -> X
|
||||
Ok(meta_json_bytes_len + 2 + 4)
|
||||
}
|
||||
|
||||
pub fn read_tiny_encrypt_meta_and_normalize<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
let mut meta = read_tiny_encrypt_meta(r);
|
||||
let _ = meta.as_mut().map(|meta| meta.normalize());
|
||||
meta
|
||||
}
|
||||
|
||||
pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
let mut tag_buff = [0_u8; 2];
|
||||
opt_result!(r.read_exact(&mut tag_buff), "Read tag failed: {}");
|
||||
|
||||
Reference in New Issue
Block a user