From 6f029e744abc0f6d4cfe756d7e6b771be1be3999 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/commands.rs') diff --git a/src/commands.rs b/src/commands.rs index ac3d020..883110a 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.1