~ireas/nitrokey-rs

f3d541e77f4389bd483fb2799dab6e99f4750d44 — Robin Krahl 3 months ago 60210fe
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.
3 files changed, 5 insertions(+), 7 deletions(-)

M CHANGELOG.md
M TODO.md
M src/device/mod.rs
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 11,6 11,8 @@ SPDX-License-Identifier: CC0-1.0
- Rename the `numlock`, `capslock`, `scrollock` fields of the `Config` struct
  to `num_lock`, `caps_lock`, `scroll_lock`.
- Update the `nitrokey-sys` dependency to v3.6.0.
  - Use `NK_device_serial_number_as_u32` instead of `NK_device_serial_number`
    in `Device::get_serial_number`.

# v0.7.1 (2020-08-30)
- Remove the custom `std::error::Error::source` implementation for

M TODO.md => TODO.md +0 -1
@@ 14,7 14,6 @@ SPDX-License-Identifier: CC0-1.0
  - New structures:
    - `NK_config`
  - New functions:
    - `NK_device_serial_number_as_u32`
    - `NK_write_config_struct`
    - `NK_free_config`
    - `NK_read_config_struct`

M src/device/mod.rs => src/device/mod.rs +3 -6
@@ 15,9 15,7 @@ use crate::config::{Config, RawConfig};
use crate::error::{CommunicationError, Error, LibraryError};
use crate::otp::GenerateOtp;
use crate::pws::GetPasswordSafe;
use crate::util::{
    get_command_result, get_cstring, owned_str_from_ptr, result_or_error, run_with_string,
};
use crate::util::{get_command_result, get_cstring, owned_str_from_ptr, result_or_error};

pub use pro::Pro;
pub use storage::{


@@ 375,9 373,8 @@ pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt
    /// # }
    /// ```
    fn get_serial_number(&self) -> Result<SerialNumber, Error> {
        run_with_string(unsafe { nitrokey_sys::NK_device_serial_number() }, |s| {
            s.parse()
        })
        let serial_number = unsafe { nitrokey_sys::NK_device_serial_number_as_u32() };
        result_or_error(SerialNumber::new(serial_number))
    }

    /// Returns the number of remaining authentication attempts for the user.  The total number of