feat: optimize
This commit is contained in:
@@ -131,10 +131,7 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
||||
let path_out = &path_display[0..path_display.len() - TINY_ENC_FILE_EXT.len()];
|
||||
if !do_skip_file_out { util::require_file_not_exists(path_out)?; }
|
||||
|
||||
let digest_algorithm = match &cmd_decrypt.digest_algorithm {
|
||||
None => "sha256",
|
||||
Some(algo) => algo.as_str(),
|
||||
};
|
||||
let digest_algorithm = cmd_decrypt.digest_algorithm.as_deref().unwrap_or("sha256");
|
||||
if cmd_decrypt.digest_file { DigestWrite::from_algo(digest_algorithm)?; } // FAST CHECK
|
||||
|
||||
let selected_envelop = select_envelop(&meta, config)?;
|
||||
@@ -151,17 +148,20 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
||||
|
||||
// Decrypt to output
|
||||
if cmd_decrypt.direct_print {
|
||||
if meta.file_length > 10 * 1024 {
|
||||
warning!("File too large(more than 10K) cannot direct print on console.");
|
||||
if meta.file_length > 100 * 1024 {
|
||||
failure!("File too large(more than 100K) cannot direct print on console.");
|
||||
return Ok(0);
|
||||
}
|
||||
if meta.file_length > 10 * 1024 {
|
||||
warning!("File is large(more than 10K) print on console.");
|
||||
}
|
||||
|
||||
let mut output: Vec<u8> = Vec::with_capacity(10 * 1024);
|
||||
let _ = decrypt_file(
|
||||
&mut file_in, meta.file_length, &mut output, cryptor, &key_nonce, meta.compress,
|
||||
)?;
|
||||
match String::from_utf8(output) {
|
||||
Err(_) => warning!("File is not UTF-8 content."),
|
||||
Err(_) => failure!("File content is not UTF-8 encoded."),
|
||||
Ok(output) => if cmd_decrypt.split_print {
|
||||
print!("{}", &output)
|
||||
} else {
|
||||
@@ -201,7 +201,13 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
||||
let encrypt_duration = start.elapsed();
|
||||
debugging!("Inner decrypt file{}: {} elapsed: {} ms", compressed_desc, path_display, encrypt_duration.as_millis());
|
||||
|
||||
if do_skip_file_out & &cmd_decrypt.remove_file { util::remove_file_with_msg(path); }
|
||||
if cmd_decrypt.remove_file {
|
||||
if do_skip_file_out {
|
||||
warning!("Cannot remove encrypted file when file out is skipped.");
|
||||
} else {
|
||||
util::remove_file_with_msg(path);
|
||||
}
|
||||
}
|
||||
Ok(meta.file_length)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user