aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-08 18:23:30 +0200
committerDaniel Mueller <deso@posteo.net>2021-01-10 17:37:57 -0800
commit9593dfd03a6ca085d649ca090b6ec5e5f0104e78 (patch)
treecef944516af5c92561c2610f9c8a21776e95cac9 /src/commands.rs
parent9975f8810399d5e535f2e2fd62b4dc56b313f955 (diff)
downloadnitrocli-9593dfd03a6ca085d649ca090b6ec5e5f0104e78.tar.gz
nitrocli-9593dfd03a6ca085d649ca090b6ec5e5f0104e78.tar.bz2
Add --usb-path option to select device
This patch adds the --usb-path option as an additional way to filter the Nitrokey device to connect to. While the serial number is a better identifier in theory, the Nitrokey Storage devices do not send their serial number in the USB device descriptor. Having the --usb-path options allows users to select one of multiple Nitrokey Storage devices. While we could directly call the nitrokey::Manager::connect_path function with the specified path, we integrate the --usb-path option into the existing find_device function for consistent error messages and to avoid having to duplicate the --model and --serial-number checks.
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 455ff4d..d352ca2 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -55,6 +55,9 @@ fn format_filter(config: &config::Config) -> String {
.collect::<Vec<_>>();
filters.push(format!("serial number in [{}]", serial_numbers.join(", ")));
}
+ if let Some(path) = &config.usb_path {
+ filters.push(format!("usb path={}", path));
+ }
if filters.is_empty() {
String::new()
} else {
@@ -75,7 +78,8 @@ fn find_device(config: &config::Config) -> anyhow::Result<nitrokey::DeviceInfo>
.serial_number
.map(|sn| config.serial_numbers.contains(&sn))
.unwrap_or_default()
- });
+ })
+ .filter(|device| config.usb_path.is_none() || config.usb_path.as_ref() == Some(&device.path));
let device = iter
.next()
@@ -83,8 +87,8 @@ fn find_device(config: &config::Config) -> anyhow::Result<nitrokey::DeviceInfo>
anyhow::ensure!(
iter.next().is_none(),
- "Multiple Nitrokey devices found{}. Use the --model and --serial-number options to \
- select one",
+ "Multiple Nitrokey devices found{}. Use the --model, --serial-number, and --usb-path options \
+ to select one",
format_filter(config)
);
Ok(device)