aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-06 23:44:18 +0200
committerDaniel Mueller <deso@posteo.net>2020-09-07 10:05:15 -0700
commit4d25d79f18cd2c5627c46727b425c745c78cf942 (patch)
treedda037f0b979415c6307d3b91ce9e81bf5636939 /src/commands.rs
parent1f8e482cfebb13b64002d65e61e29932770388be (diff)
downloadnitrocli-4d25d79f18cd2c5627c46727b425c745c78cf942.tar.gz
nitrocli-4d25d79f18cd2c5627c46727b425c745c78cf942.tar.bz2
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.
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs7
1 files changed, 7 insertions, 0 deletions
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<nitrokey::DeviceInfo>
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)
}