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