[][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 Debug for DeviceWrapper[src]

impl Device for DeviceWrapper[src]

impl GenerateOtp for DeviceWrapper[src]

impl GetPasswordSafe for DeviceWrapper[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.