Prevent --slot from being used with --list-all

This commit is contained in:
Jack Grigg
2021-05-02 09:31:35 +12:00
parent bf58ee9b82
commit 65082edf22
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -18,6 +18,7 @@ pub enum Error {
SlotHasNoIdentity(RetiredSlotId), SlotHasNoIdentity(RetiredSlotId),
SlotIsNotEmpty(RetiredSlotId), SlotIsNotEmpty(RetiredSlotId),
TimedOut, TimedOut,
UseListForSingleSlot,
YubiKey(yubikey_piv::Error), YubiKey(yubikey_piv::Error),
} }
@@ -85,6 +86,9 @@ impl fmt::Debug for Error {
Error::TimedOut => { Error::TimedOut => {
writeln!(f, "Timed out while waiting for a YubiKey to be inserted.")? writeln!(f, "Timed out while waiting for a YubiKey to be inserted.")?
} }
Error::UseListForSingleSlot => {
writeln!(f, "Use --list to print the recipient for a single slot.")?
}
Error::YubiKey(e) => match e { Error::YubiKey(e) => match e {
yubikey_piv::error::Error::NotFound => { yubikey_piv::error::Error::NotFound => {
writeln!(f, "Please insert the YubiKey you want to set up")? writeln!(f, "Please insert the YubiKey you want to set up")?
+4
View File
@@ -271,6 +271,10 @@ fn identity(flags: PluginFlags) -> Result<(), Error> {
} }
fn list(flags: PluginFlags, all: bool) -> Result<(), Error> { fn list(flags: PluginFlags, all: bool) -> Result<(), Error> {
if all && flags.slot.is_some() {
return Err(Error::UseListForSingleSlot);
}
print_details("recipients", flags, all, |_, recipient, metadata| { print_details("recipients", flags, all, |_, recipient, metadata| {
println!("{}", metadata); println!("{}", metadata);
println!("{}", recipient.to_string()); println!("{}", recipient.to_string());