feat: optimize code
This commit is contained in:
13
src/util.rs
13
src/util.rs
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user