feat: support pin entry file cmd

This commit is contained in:
2024-08-14 23:55:06 +08:00
parent 55e0bf79dc
commit 5d410e76b2

View File

@@ -17,7 +17,9 @@ use std::{env, fs};
use pinentry::PassphraseInput;
use secrecy::ExposeSecret;
const HOME_ENV: &str = "HOME";
const PIN_ENTRY_ENV: &str = "PIN_ENTRY_CMD";
const PIN_ENTRY_CMD_FILE: &str = ".pinentry.cmd";
const PIN_ENTRY_1: &str = "/usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac";
const PIN_ENTRY_DEFAULT: &str = "pinentry";
@@ -56,6 +58,11 @@ fn get_pin_entry() -> String {
if let Ok(pin_entry) = env::var(PIN_ENTRY_ENV) {
return pin_entry;
}
if let Ok(home) = env::var(HOME_ENV) {
if let Ok(pin_entry_cmd) = fs::read_to_string(format!("{}/{}", home, PIN_ENTRY_CMD_FILE)) {
return pin_entry_cmd.trim().to_string();
}
}
if let Ok(m) = fs::metadata(PIN_ENTRY_1) {
if m.is_file() {
return PIN_ENTRY_1.to_string();