diff options
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/mod.rs | 20 | ||||
-rw-r--r-- | src/device/pro.rs | 2 | ||||
-rw-r--r-- | src/device/storage.rs | 2 | ||||
-rw-r--r-- | src/device/wrapper.rs | 1 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/device/mod.rs b/src/device/mod.rs index 067fdf6..7fec18b 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -10,8 +10,6 @@ use std::ffi; use std::fmt; use std::str; -use nitrokey_sys; - use crate::auth::Authenticate; use crate::config::{Config, RawConfig}; use crate::error::{CommunicationError, Error, LibraryError}; @@ -30,6 +28,7 @@ pub use wrapper::DeviceWrapper; /// Available Nitrokey models. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] pub enum Model { /// The Nitrokey Storage. Storage, @@ -225,9 +224,8 @@ fn get_hidapi_serial_number(serial_number: &str) -> Option<SerialNumber> { return None; } - let iter = serial_number.char_indices().rev(); - let first_non_null = iter.skip_while(|(_, c)| *c == '0').next(); - if let Some((i, _)) = first_non_null { + let mut iter = serial_number.char_indices().rev(); + if let Some((i, _)) = iter.find(|(_, c)| *c != '0') { let substr = if len - i < 8 { // The last eight characters contain at least one non-zero character --> use them serial_number.split_at(len - 8).1 @@ -307,6 +305,8 @@ pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt /// } /// # Ok::<(), nitrokey::Error>(()) /// ``` + /// + /// [`Manager`]: struct.Manager.html fn into_manager(self) -> &'a mut crate::Manager; /// Returns the model of the connected Nitrokey device. @@ -464,9 +464,9 @@ pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt /// let mut manager = nitrokey::take()?; /// let device = manager.connect()?; /// let config = device.get_config()?; - /// println!("numlock binding: {:?}", config.numlock); - /// println!("capslock binding: {:?}", config.capslock); - /// println!("scrollock binding: {:?}", config.scrollock); + /// println!("Num Lock binding: {:?}", config.num_lock); + /// println!("Caps Lock binding: {:?}", config.caps_lock); + /// println!("Scroll Lock binding: {:?}", config.scroll_lock); /// println!("require password for OTP: {:?}", config.user_password); /// # Ok(()) /// # } @@ -644,6 +644,8 @@ pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt /// # } /// ``` /// + /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString + /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword /// [`build_aes_key`]: #method.build_aes_key fn factory_reset(&mut self, admin_pin: &str) -> Result<(), Error> { let admin_pin_string = get_cstring(admin_pin)?; @@ -679,6 +681,8 @@ pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt /// # } /// ``` /// + /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString + /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword /// [`factory_reset`]: #method.factory_reset fn build_aes_key(&mut self, admin_pin: &str) -> Result<(), Error> { let admin_pin_string = get_cstring(admin_pin)?; diff --git a/src/device/pro.rs b/src/device/pro.rs index 591b730..0d5443e 100644 --- a/src/device/pro.rs +++ b/src/device/pro.rs @@ -1,8 +1,6 @@ // Copyright (C) 2018-2019 Robin Krahl <robin.krahl@ireas.org> // SPDX-License-Identifier: MIT -use nitrokey_sys; - use crate::device::{Device, Model, Status}; use crate::error::Error; use crate::otp::GenerateOtp; diff --git a/src/device/storage.rs b/src/device/storage.rs index 5669a91..a18d94f 100644 --- a/src/device/storage.rs +++ b/src/device/storage.rs @@ -5,8 +5,6 @@ use std::convert::TryFrom as _; use std::fmt; use std::ops; -use nitrokey_sys; - use crate::device::{Device, FirmwareVersion, Model, SerialNumber, Status}; use crate::error::{CommandError, Error}; use crate::otp::GenerateOtp; diff --git a/src/device/wrapper.rs b/src/device/wrapper.rs index 69291ad..942a905 100644 --- a/src/device/wrapper.rs +++ b/src/device/wrapper.rs @@ -64,6 +64,7 @@ use crate::otp::GenerateOtp; /// /// [`connect`]: struct.Manager.html#method.connect #[derive(Debug)] +#[non_exhaustive] pub enum DeviceWrapper<'a> { /// A Nitrokey Storage device. Storage(Storage<'a>), |