[][src]Enum nitrokey::DeviceWrapper

pub enum DeviceWrapper {
    Storage(Storage),
    Pro(Pro),
}

A wrapper for a Nitrokey device of unknown type.

Use the function connect to obtain a wrapped instance. The wrapper implements all traits that are shared between all Nitrokey devices so that the shared functionality can be used without knowing the type of the underlying device. If you want to use functionality that is not available for all devices, you have to extract the device.

Examples

Authentication with error handling:

use nitrokey::{Authenticate, DeviceWrapper, User};

fn perform_user_task(device: &User<DeviceWrapper>) {}
fn perform_other_task(device: &DeviceWrapper) {}

let device = nitrokey::connect()?;
let device = match device.authenticate_user("123456") {
    Ok(user) => {
        perform_user_task(&user);
        user.device()
    },
    Err((device, err)) => {
        println!("Could not authenticate as user: {}", err);
        device
    },
};
perform_other_task(&device);

Device-specific commands:

use nitrokey::{DeviceWrapper, Storage};

fn perform_common_task(device: &DeviceWrapper) {}
fn perform_storage_task(device: &Storage) {}

let device = nitrokey::connect()?;
perform_common_task(&device);
match device {
    DeviceWrapper::Storage(storage) => perform_storage_task(&storage),
    _ => (),
};

Variants

Storage(Storage)

A Nitrokey Storage device.

Pro(Pro)

A Nitrokey Pro device.

Trait Implementations

impl Authenticate for DeviceWrapper
[src]

impl Device for DeviceWrapper
[src]

fn get_serial_number(&self) -> Result<String, CommandError>
[src]

Returns the serial number of the Nitrokey device. The serial number is the string representation of a hex number. Read more

fn get_user_retry_count(&self) -> u8
[src]

Returns the number of remaining authentication attempts for the user. The total number of available attempts is three. Read more

fn get_admin_retry_count(&self) -> u8
[src]

Returns the number of remaining authentication attempts for the admin. The total number of available attempts is three. Read more

fn get_major_firmware_version(&self) -> i32
[src]

Returns the major part of the firmware version (should be zero). Read more

fn get_minor_firmware_version(&self) -> i32
[src]

Returns the minor part of the firmware version (for example 8 for version 0.8). Read more

fn get_config(&self) -> Result<Config, CommandError>
[src]

Returns the current configuration of the Nitrokey device. Read more

fn change_admin_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
[src]

Changes the administrator PIN. Read more

fn change_user_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
[src]

Changes the user PIN. Read more

fn unlock_user_pin(
    &self,
    admin_pin: &str,
    user_pin: &str
) -> Result<(), CommandError>
[src]

Unlocks the user PIN after three failed login attempts and sets it to the given value. Read more

fn lock(&self) -> Result<(), CommandError>
[src]

Locks the Nitrokey device. Read more

fn factory_reset(&self, admin_pin: &str) -> Result<(), CommandError>
[src]

Performs a factory reset on the Nitrokey device. Read more

fn build_aes_key(&self, admin_pin: &str) -> Result<(), CommandError>
[src]

Builds a new AES key on the Nitrokey. Read more

impl GenerateOtp for DeviceWrapper
[src]

fn set_time(&self, time: u64, force: bool) -> Result<(), CommandError>
[src]

Sets the time on the Nitrokey. Read more

impl GetPasswordSafe for DeviceWrapper
[src]

impl Debug for DeviceWrapper
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]