From d6729e99babb27079a785635e186deefc6477517 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 30 Jul 2024 05:27:06 +0000 Subject: [PATCH] dialoguer 0.11 --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- i18n/en-US/age_plugin_yubikey.ftl | 1 + src/error.rs | 8 ++++++++ src/key.rs | 6 +++--- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f182c7..111589d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,12 +499,13 @@ dependencies = [ [[package]] name = "dialoguer" -version = "0.10.4" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59c6f2989294b9a498d3ad5491a79c6deb604617378e1cdc4bfc1c1361fe2f87" +checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" dependencies = [ "console", "shell-words", + "thiserror", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index 144f559..1b1fe1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ age-plugin = "0.5" base64 = "0.21" bech32 = "0.9" console = { version = "0.15", default-features = false } -dialoguer = { version = "0.10", default-features = false, features = ["password"] } +dialoguer = { version = "0.11", default-features = false, features = ["password"] } env_logger = "0.10" gumdrop = "0.8" hex = "0.4" diff --git a/i18n/en-US/age_plugin_yubikey.ftl b/i18n/en-US/age_plugin_yubikey.ftl index 42e115d..2174b6c 100644 --- a/i18n/en-US/age_plugin_yubikey.ftl +++ b/i18n/en-US/age_plugin_yubikey.ftl @@ -204,6 +204,7 @@ err-invalid-flag-tui = Flag '{$flag}' cannot be used with the interactive in err-invalid-pin-policy = Invalid PIN policy '{$policy}' (expected [{$expected}]). err-invalid-slot = Invalid slot '{$slot}' (expected number between 1 and 20). err-invalid-touch-policy = Invalid touch policy '{$policy}' (expected [{$expected}]). +err-io-user = Failed to get input from user: {$err} err-io = Failed to set up {-yubikey}: {$err} err-multiple-commands = Only one of {-cmd-generate}, {-cmd-identity}, {-cmd-list}, {-cmd-list-all} can be specified. err-multiple-yubikeys = Multiple {-yubikeys} are plugged in. Use {-flag-serial} to select a single {-yubikey}. diff --git a/src/error.rs b/src/error.rs index 1674ffa..5f4e17c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,6 +15,7 @@ macro_rules! wlnfl { pub enum Error { CustomManagementKey, + Dialog(dialoguer::Error), InvalidFlagCommand(String, String), InvalidFlagTui(String), InvalidPinPolicy(String), @@ -35,6 +36,12 @@ pub enum Error { YubiKey(yubikey::Error), } +impl From for Error { + fn from(e: dialoguer::Error) -> Self { + Error::Dialog(e) + } +} + impl From for Error { fn from(e: io::Error) -> Self { Error::Io(e) @@ -65,6 +72,7 @@ impl fmt::Debug for Error { url = CHANGE_MGMT_KEY_URL )?; } + Error::Dialog(e) => wlnfl!(f, "err-io-user", err = e.to_string())?, Error::InvalidFlagCommand(flag, command) => wlnfl!( f, "err-invalid-flag-command", diff --git a/src/key.rs b/src/key.rs index d86a0ad..05d80b4 100644 --- a/src/key.rs +++ b/src/key.rs @@ -274,10 +274,10 @@ pub(crate) fn disconnect_without_reset(yubikey: YubiKey) { let _ = yubikey.disconnect(pcsc::Disposition::LeaveCard); } -fn request_pin( - mut prompt: impl FnMut(Option) -> io::Result>, +fn request_pin( + mut prompt: impl FnMut(Option) -> Result, E2>, serial: Serial, -) -> io::Result> { +) -> Result, E2> { let mut prev_error = None; loop { prev_error = Some(match prompt(prev_error)? {