feat: v1.7.3, supports pinentry

This commit is contained in:
2024-01-10 00:35:38 +08:00
parent 2e53130ead
commit 2bcb0fe5c4
6 changed files with 85 additions and 6 deletions

View File

@@ -4,12 +4,15 @@ use std::path::{Path, PathBuf};
use base64::Engine;
use base64::engine::general_purpose;
use pinentry::PassphraseInput;
use rand::random;
use rust_util::{information, opt_result, print_ex, simple_error, util_term, warning, XResult};
use secrecy::ExposeSecret;
use zeroize::Zeroize;
use crate::consts::TINY_ENC_FILE_EXT;
use crate::util_digest::DigestWrite;
use crate::util_env;
pub struct SecVec(pub Vec<u8>);
@@ -28,10 +31,22 @@ impl AsRef<[u8]> for SecVec {
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") {
None => if !util_env::get_no_default_pin_hint() && util_term::read_yes_no("Use default PIN 123456, please confirm") {
"123456".into()
} else {
rpassword::prompt_password("Please input PIN: ").expect("Read PIN failed")
let pin_entry = util_env::get_pin_entry().unwrap_or_else(|| "pinentry".to_string());
if let Some(mut input) = PassphraseInput::with_binary(pin_entry) {
let secret = input
.with_description("Enter new passphrase for FooBar")
.with_prompt("Passphrase:")
.with_confirmation("Confirm passphrase:", "Passphrases do not match")
.interact();
secret.expect("Read PIN from pinentry failed")
.expose_secret()
.to_string()
} else {
rpassword::prompt_password("Please input PIN: ").expect("Read PIN failed")
}
}
}
}