feat: optimize decrypt
This commit is contained in:
@@ -124,16 +124,17 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
|||||||
|
|
||||||
if cmd_decrypt.direct_print {
|
if cmd_decrypt.direct_print {
|
||||||
if meta.file_length > 10 * 1024 {
|
if meta.file_length > 10 * 1024 {
|
||||||
return simple_error!("File too large(more than 10K) cannot direct print on console.");
|
warning!("File too large(more than 10K) cannot direct print on console.");
|
||||||
}
|
} else {
|
||||||
let mut output: Vec<u8> = Vec::with_capacity(10 * 1024);
|
let mut output: Vec<u8> = Vec::with_capacity(10 * 1024);
|
||||||
let _ = decrypt_file(
|
let _ = decrypt_file(
|
||||||
&mut file_in, meta.file_length, &mut output, &key, &nonce, meta.compress,
|
&mut file_in, meta.file_length, &mut output, &key, &nonce, meta.compress,
|
||||||
)?;
|
)?;
|
||||||
match String::from_utf8(output) {
|
match String::from_utf8(output) {
|
||||||
Err(_) => return simple_error!("File is not UTF-8 content."),
|
Err(_) => warning!("File is not UTF-8 content."),
|
||||||
Ok(output) => println!(">>>>> BEGIN CONTENT >>>>>\n{}\n<<<<< END CONTENT <<<<<", &output),
|
Ok(output) => println!(">>>>> BEGIN CONTENT >>>>>\n{}\n<<<<< END CONTENT <<<<<", &output),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut file_out = File::create(path_out)?;
|
let mut file_out = File::create(path_out)?;
|
||||||
let _ = decrypt_file(
|
let _ = decrypt_file(
|
||||||
@@ -150,7 +151,7 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
|||||||
util::zeroize(key);
|
util::zeroize(key);
|
||||||
util::zeroize(nonce);
|
util::zeroize(nonce);
|
||||||
drop(file_in);
|
drop(file_in);
|
||||||
if do_write_file_out && cmd_decrypt.remove_file { util::remove_file_with_msg(path); }
|
if do_write_file_out & &cmd_decrypt.remove_file { util::remove_file_with_msg(path); }
|
||||||
Ok(meta.file_length)
|
Ok(meta.file_length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user