diff --git a/Cargo.lock b/Cargo.lock index b92ec83..f346075 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1989,7 +1989,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "1.9.8" +version = "1.9.9" dependencies = [ "aes-gcm-stream", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index d662573..45f7189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "1.9.8" +version = "1.9.9" edition = "2021" license = "MIT" description = "A simple and tiny file encrypt tool" diff --git a/src/util.rs b/src/util.rs index d156673..de12214 100644 --- a/src/util.rs +++ b/src/util.rs @@ -40,23 +40,26 @@ pub fn read_stdin() -> XResult> { } pub fn read_pin(pin: &Option) -> XResult { - let rpin = match pin { - Some(pin) => pin.to_string(), - None => if is_use_default_pin() { - "123456".into() + if let Some(pin) = pin { + if pin != "#INPUT#" { + return Ok(pin.to_string()); + } + } + if is_use_default_pin() { + return Ok("123456".into()); + } + let rpin = { + let pin_entry = util_env::get_default_pin_entry().unwrap_or_else(|| "pinentry".to_string()); + if let Some(mut input) = PassphraseInput::with_binary(pin_entry) { + let secret = input + .with_description("Please input your PIN.") + .with_prompt("PIN:") + .interact(); + opt_result!(secret, "Read PIN from pinentry failed: {}") + .expose_secret() + .to_string() } else { - let pin_entry = util_env::get_default_pin_entry().unwrap_or_else(|| "pinentry".to_string()); - if let Some(mut input) = PassphraseInput::with_binary(pin_entry) { - let secret = input - .with_description("Please input your PIN.") - .with_prompt("PIN:") - .interact(); - opt_result!(secret, "Read PIN from pinentry failed: {}") - .expose_secret() - .to_string() - } else { - opt_result!(rpassword::prompt_password("Please input PIN: "), "Read PIN failed: {}") - } + opt_result!(rpassword::prompt_password("Please input PIN: "), "Read PIN failed: {}") } }; Ok(rpin)