feat: optimize code

This commit is contained in:
2023-10-15 11:53:29 +08:00
parent 12aa3b48d2
commit 1a3c670bad
5 changed files with 52 additions and 84 deletions

View File

@@ -5,11 +5,22 @@ use std::path::{Path, PathBuf};
use base64::Engine;
use base64::engine::general_purpose;
use rand::random;
use rust_util::{information, simple_error, warning, XResult};
use rust_util::{information, simple_error, util_term, warning, XResult};
use zeroize::Zeroize;
use crate::consts::TINY_ENC_FILE_EXT;
pub fn read_pin(pin: &Option<String>) -> String {
match pin {
Some(pin) => pin.to_string(),
None => if util_term::read_yes_no("Use default PIN 123456, please confirm") {
"123456".into()
} else {
rpassword::prompt_password("Please input PIN: ").expect("Read PIN failed")
}
}
}
pub fn remove_file_with_msg(path: &PathBuf) {
match fs::remove_file(path) {
Err(e) => warning!("Remove file: {} failed: {}", path.display(), e),