ref: b181dd0b64b99cadf2ea8c2dbd099e1297b93f8f nitrokey-rs/src/pws.rs -rw-r--r-- 13.9 KiB
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.
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.
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.
Remove unused imports
Merge branch 'release-0.4.0'
Merge branch 'connection-manager-mut' into next

Refactor the connection management to prevent multiple device
connections at the same time.

RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190126174327.tbuyk2s535kfiqm4%40localhost%3E
Update documentation for Manager refactoring

This patch updates the documentation to reflect the latest changes to
connection handling.  It also updates the doc tests to prefer the new
methods over the old ones.
Introduce into_manager for Device

To enable applications like nitrokey-test to go back to a manager
instance from a Device instance, we add the into_manager function to the
Device trait.  To do that, we have to keep track of the Manager’s
lifetime by adding a lifetime to Device (and then to some other traits
that use Device).
Store mutable reference to Manager in Device

In the last patches, we ensured that devices can only be obtained using
the Manager struct.  But we did not ensure that there is only one device
at a time.  This patch adds a mutable reference to the Manager instance
to the Device implementations.  The borrow checker makes sure that there
is only one mutable reference at a time.

In this patch, we have to remove the old connect, Pro::connect and
Storage::connect functions as they do no longer compile.  (They discard
the MutexGuard which invalidates the reference to the Manager.)
Therefore the tests do no longer compile.
Merge branch 'revert' into next

The tests with the 0.4.0-alpha.1 version showed that the approach using
mutable references to the Device in User, Admin and PasswordSafe causes
problems in nitrocli, see [0].  Therefore, these changes are reverted.

[0] https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C43cc304d-23e8-7f95-2167-ce3f0530b81e%40posteo.net%3E

* revert:
  Revert "Store mutable reference to Device in PasswordSafe"
  Revert "Refactor User and Admin to use a mutable reference"
Revert "Store mutable reference to Device in PasswordSafe"

This reverts commit 13006c00dcbd570cf8347d89557834e320427377.
Merge branch 'mutable-references' into next


* mutable-references:
  Store mutable reference to Device in PasswordSafe
  Refactor User and Admin to use a mutable reference
  Require mutable reference if method changes device state
  Add device_mut method to DeviceWrapper
  Implement DerefMut for User and Admin
Store mutable reference to Device in PasswordSafe

The current implementation of PasswordSafe stored a normal reference to
the Device.  This patch changes the PasswordSafe struct to use a mutable
reference instead.  This allows the borrow checker to make sure that
there is only one PasswordSafe instance at a time.  While this is
currently not needed, it will become important once we can lock the PWS
on the Nitrokey when dropping the PasswordSafe instance.
Require mutable reference if method changes device state

Previously, all methods that access a Nitrokey device took a reference
to the device as input.  This method changes methods that change the
device state to require a mutable reference instead.  In most case,
this is straightforward as the method writes data to the device (for
example write_config or change_user_pin).  But there are two edge cases:
- Authenticating with a PIN changes the device state as it may decrease
  the PIN retry counter if the authentication fails.
- Generating an HOTP code changes the device state as it increases the
  HOTP counter.
Prefer eprintln over println for error messages
Add license and copyright information

This patch adds license and copyright information to all files to make
nitrokey-rs compliant with the REUSE practices [0].

[0] https://reuse.software/practices/2.0/
Refactor and clean up all code

This includes:
- using idiomatic Rust
- limiting the scope of unsafe blocks
- simplifying code
Merge branch 'feature/error-refactoring' into next

RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190117000856.slgb6jwkwd3qu6ey%40localhost%3E
Check specific error codes in the tests

If possible, check specific error codes instead of `is_err()`.  This
makes the code more readable and catches bugs resulting in the wrong
error code.  Also, using the assert_*_err and assert_ok macros yields
error messages containing the expected and the actual value.

To be able to use these macros with the `get_password_safe` method, we
also have to implement `Debug` for `PasswordSafe` and `Device`.