Refactor connection handling for multiple devices #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch series refactors the connection handling into two new functions,
find_device
andconnect
, and improves the handling of multiple attached devices as discussed in issue #99: If mulitple attached devices match the filter set by the user, nitrocli now fails instead of just picking the first match. And the--serial-number
option now allows the user to filter the devices by serial number. (We already have the --model option to filter by model.)This means that we always list all attached Nitrokey devices before connecting. Still the overhead is very small as the list can be read from the sys file system without any communication with the Nitrokey device itself.
Unfortunately, the Nitrokey Storage sends a wrong serial number in the USB device descriptor that is used for listing the devices, see Nitrokey/nitrokey-storage-firmware#88. Therefore the new
--serial-number
option only works for Nitrokey Pro devices. Originally, I wanted to wait with this feature until this is fixed in the firmware, but I don’t think this will happen any time soon. (And we would still have to support devices with older firmware versions.)As a next step, we could add support for multiple devices to the
status
command.