| Commit message (Collapse) | Author | Age |
|
|
|
|
|
|
|
|
|
|
|
| |
libnitrokey calls the configuration fields that set bindings for the Num
Lock, Caps Lock and Scroll Lock keys numlock, capslock, scrolllock. Due
to a typo, scrolllock with three l was renamed to scrollock with two l
in nitrokey-rs.
To make the field names easier to read (and type) and consistent with
the typical names for these keys, this patch changes them to num_lock,
caps_lock and scroll_lock. In the doc comments, we now use the spelling
“Num Lock”, “Caps Lock” and “Scroll Lock”.
|
| |
|
|
|
|
|
|
|
|
|
| |
Previously, all enums defined by the nitrokey crate were exhaustive.
This means that adding new variants to these enums is a breaking change.
To make it possible to add new features to nitrokey-rs without breaking
compatibility, this patch marks the Error, CommandError,
CommunicationError, LibraryError, Model and DeviceWrapper enums as
non-exhaustive.
|
|
|
|
|
| |
This patch replaces calls to skip_while(…).next() for an iter::Iterator
with a call to find(…), as suggested by clippy.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The util module provides helper methods to deal with the C strings
returned by libnitrokey. The current implementation has to problems:
- It causes unnecessary allocations if we only want to look at the
string, for example in get_serial_number.
- If the conversion from a CStr to a String fails, the string pointer
is not freed.
Therefore this patch introduces the run_with_str function that executes
a function with the string returned by libnitrokey and then makes sure
that the pointer is freed correctly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In a previous commit, we changed the serial number representation from a
string to an integer. This made it easier to compare serial numbers,
but also introduced new problems:
- Serial numbers should be formatted consistently, for example as
"{:#010x}". It is hard to ensure this for an integer value.
- The format of the serial number may be subject to change. Users
should not rely too much on the u32 representation.
Therefore we introduce a new SerialNumber struct that represents a
serial number. Currently it only stores a u32 value. The following
traits and functions can be used to access its value:
- FromStr for string parsing
- ToString/Display for string formatting
- as_u32 to access the underlying integer value
|
|
|
|
|
|
|
|
|
|
|
|
| |
libnitrokey’s NK_read_config function returns a pointer to an array that
has been allocated using new[]. We would have to delete this pointer
using delete[], but we only have access to free. Therefore this patch
modifies the Device::get_config function to call NK_get_status instead
of NK_read_config.
This also makes the code more safe as we get the data as a struct
instead of an array. It does not add much overhead as NK_read_config
also executes the GET_STATUS command on the Nitrokey device.
|
|
|
|
|
|
| |
This makes it easier to parse only the config part of the NK_status
struct and avoids code duplication in the upcoming get_config
refactoring.
|
|
|
|
|
|
|
|
| |
This patch consistently uses u32 integers to store and return the serial
number of a Nitrokey device. This makes it easier to convert and
compare the serial number, as it is a unique representation and as
formatting an integer cannot fail. For more details, see this RFC:
https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20200126074816.GA1314%40ireas.org%3E
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, we assumed that the serial number returned by hidapi
contains the Nitrokey serial number as the least significant bytes. As
disussed here [0], this is not true for Nitrokey Pro devices with
firmware version 0.8 or older: They write the serial number to the most
significant bytes instead.
This patch update the get_hidapi_serial_number function so that
list_devices now returns the correctly formatted and truncated serial
number for all Nitrokey Pro devices. It also makes sure that the serial
number is lowercase to be consistent with libnitrokey’s formatting.
|
|
|
|
|
|
|
| |
This patch adds support for the NK_get_progress_bar_value function: It
adds the OperationStatus enum that stores the return value of this
command and adds the get_operation_status function to the Storage struct
that executes the command.
|
|
|
|
|
|
| |
Somehow I forgot to derive the common traits for the new Status struct.
This patch adds the missing derive attribute for Clone, Copy, Debug and
PartialEq.
|
|
|
|
|
|
|
| |
In the last patch, we added the get_status function to the Device trait.
This patch renames the Storage::get_status function to
get_storage_status to resolve the name clash – though allowed by the
compiler, it is rather confusing for the end user.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch adds support for the GET_STATUS command that returns the
status information common to all Nitrokey devices. It can be accessed
using the Device::get_status function and is stored in a Status struct.
Due to a bug in the Storage firmware [0], the GET_STATUS command returns
wrong firmware versions and serial numbers. Until this is fixed in
libnitrokey [1], we have to manually execute the GET_DEVICE_STATUS
command to fix these values for the Nitrokey Storage.
Also, this leads to a name clash with the existing Storage::get_status
function, which will be renamed in an upcoming patch.
[0] https://github.com/Nitrokey/nitrokey-storage-firmware/issues/96
[1] https://github.com/Nitrokey/libnitrokey/issues/166
|
|
|
|
|
|
|
|
| |
In the next patch, we will add support for the NK_list_devices functions
that returns a list of NK_device_info structs with information about the
connected devices. This patch introduces the DeviceInfo struct that
holds the information returned by NK_list_devices and that can be
created from a NK_device_info struct.
|
|
|
|
|
|
| |
A nitrokey_sys::NK_device_model (= u32) value may correspond to a
nitrokey::Model, and vice versa. This patch adds the appropriate From
and TryFrom implementations.
|
|
|
|
|
|
| |
Since Rust 1.34.0, we no longer need a `fn main` comment in doc tests
that return results. It is sufficient to have an `Ok` return value with
type annotations.
|
|
This patch splits the rather large device module into the submodules
pro, storage and wrapper. This only changes the internal code structure
and does not affect the public API.
|