~ireas/nitrokey-rs

ref: db48656015d958594b4818582439f7515359cd60 nitrokey-rs/src d---------
Refactor PWS slot access

Previously, the PasswordSafe::get_slot_{name,login,password} methods
would return a SlotNotProgrammed error if the libnitrokey functions
return an empty string.  This was because libnitrokey does not return an
error code when accessing an unprogrammed slot.  But this was ambigous
as the slot values might actually be empty.

With this patch, we deprecate the existing methods for accessing the
slot data.  Instead, we introduce the PasswordSlot struct that can be
used to access the (empty or non-empty) values of programmed slots.
Instances of this struct can be obtained using the get_slots (all
programmed slots), get_slot (one slot that is checked to be programmed)
and get_slot_unchecked (one slot without checking whether it is
programmed) methods.

See this discussion for more information:
	https://github.com/d-e-s-o/nitrocli/issues/133
Fix example for PasswordSafe::write_slot

Previously, the documentation for the PasswordSafe::write_slot method
contained an example that only showed the usage of the get_slot_*
methods.  With this patch, we demonstrate the usage of the write_slot
method instead.
Implement From<LogLevel> for i32

Previously, we implemented Into<i32> for LogLevel.  As implementing From
is preferred over Into, this patch replaces this implementation with
From<LogLevel> for i32.
Merge branch 'nitrokey-sys-v3.6.0' into next

This patch series updates the nitrokey-sys dependency to version 3.6.0
and makes use of the new features.
Support the Librem Key model

This patch adds support for the Librem Key model, a clone of the
Nitrokey Pro.  Functionally, it is identical to the Nitrokey Pro, but it
has a different USB vendor and product ID.

With this patch, we also change the Display implementation for Model to
return the complete name of the model, i. e. Nitrokey Pro, Nitrokey
Storage or Librem Key.
Add get_struct utility function

This patch adds the internal get_struct utility function that can be
used for querying a struct with a libnitrokey function that uses an
output parameter.  Instead of this:

    let mut out = R::default();
    get_command_result(op(&mut out))?;
    Ok(out.into())

We can now write this:

    get_struct(|out| op(out))
Use Default::default for nitrokey-sys structs

Since version 3.6.0, nitrokey-sys derives the Default trait for all
structs.  This allows us to simplify code snippets where we have to
construct an empty struct that is then filled by nitrokey-sys.
Use NK_config struct for configuration handling

Previously, the Nitrokey configuration was represented as an array in
libnitrokey.  libnitrokey 3.6 added the NK_config struct and the
NK_{read,write}_config_struct for type-safe configuration handling.
This patch replaces the old functions with the new versions using the
NK_config struct.  This makes the RawConfig struct obsolete as it is
identical to NK_config.
Correctly free pointer to PWS status

The NK_get_password_safe_slot_status function returns a pointer to an
array that has been allocated using new[].  As we only have access to
libc’s free function, we could not free this pointer properly (using
delete[]).  libnitrokey 3.6 added the NK_free_password_safe_slot_status
function which we now use to properly free the pointer.
Use NK_device_serial_number_as_u32

Previously, we called the NK_device_serial_number function in
Device::get_serial which returned a string that we had to parse into an
unsigned integer to use with the SerialNumber struct.  libnitrokey 3.6
introduced the NK_device_serial_number_as_u32 function that returns the
serial number as an unsigned integer.  This patch replaces the call to
NK_device_serial_number with this new function.
Rename *lock fields of the Config struct

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”.
Fix dead links in Device documentation
Fix link in User doc comment
Make *Error, Model, DeviceWrapper non-exhaustive

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.
Export the FirmwareVersion struct

This patch adds the FirmwareVersion struct to the re-exports in lib.rs.
Previosuly, nitrokey users where able to access FirmwareVersion values
as part of the Status struct and the Device::get_firmware_version method
but could not see its definition.
Use map_err(|_| x) instead of or_else(|_| Err(x))
Remove custom source implementation for Error

This patch removes the custom implementation of the source method of the
std::error::Error trait for the error::Error type.  This means that the
default implementation is used that always returns None.  The reason for
this change is that we already print the error message of the source
error in the Display implementation.  This leads to a duplicated error
message if both Display and source are checked, for example with
anyhow’s error formatting.

See this thread for more information:
	https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C6e0b4dc8-9059-a113-e98e-b49e52818c75%40posteo.net%3E
Merge branch 'poison-error' into next

This patch series refactors the Error enum and ensures that it is Send,
Sync and 'static.  This makes sure that it is compatible with the anyhow
crate.  To achieve this, we drop the RandError variant and remove the
sync::PoisonError value from the PoisonError variant.
Ensure Error trait implementations

The anyhow crate requires that error types are error::Error, Send, Sync
and 'static.  This patch implements a simple static assertion that our
Error type implements these traits.
Remove Error::RandError variant

Since we update rand_os to version 0.2 in commit
6c138eaa850c745b97b7e48a201db0cbaad8e1e0, the random number generation
can no longer fail.  Therefore the Error::RandError variant is no longer
needed.

As we did not want to break the public API, we still kept the RandError
variant.  This patch removes the RandError variant for good.
Next