From 4d25d79f18cd2c5627c46727b425c745c78cf942 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 6 Sep 2020 23:44:18 +0200 Subject: Fail if multiple matching devices are attached Previously, we just applied our filter (if any) to all attached Nitrokey devices and selected the first match when connection to a Nitrokey device. This may lead to unexpected behavior if multiple devices are attached. This patch changes the find_device function to return an error if multiple matching devices are found. --- src/commands.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/commands.rs b/src/commands.rs index ff95c31..05038e0 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -61,6 +61,13 @@ fn find_device(config: &config::Config) -> anyhow::Result let device = iter .next() .with_context(|| format!("Nitrokey device not found{}", format_filter(config)))?; + + anyhow::ensure!( + iter.next().is_none(), + "Multiple Nitrokey devices found{}. Use the --model and --serial-number options to \ + select one", + format_filter(config) + ); Ok(device) } -- cgit v1.2.3