[][src]Enum nitrokey::DeviceWrapper

pub enum DeviceWrapper<'a> {
    Storage(Storage<'a>),
    Pro(Pro<'a>),
}

A wrapper for a Nitrokey device of unknown type.

Use the connect method 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<'a>(device: &User<'a, DeviceWrapper<'a>>) {}
fn perform_other_task(device: &DeviceWrapper) {}

let mut manager = nitrokey::take()?;
let device = manager.connect()?;
let device = match device.authenticate_user("123456") {
    Ok(user) => {
        perform_user_task(&user);
        user.device()
    },
    Err((device, err)) => {
        eprintln!("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 mut manager = nitrokey::take()?;
let device = manager.connect()?;
perform_common_task(&device);
match device {
    DeviceWrapper::Storage(storage) => perform_storage_task(&storage),
    _ => (),
};

Variants

Storage(Storage<'a>)

A Nitrokey Storage device.

Pro(Pro<'a>)

A Nitrokey Pro device.

Trait Implementations

impl<'a> Authenticate<'a> for DeviceWrapper<'a>[src]

impl<'a> Debug for DeviceWrapper<'a>[src]

impl<'a> Device<'a> for DeviceWrapper<'a>[src]

impl<'a> From<Pro<'a>> for DeviceWrapper<'a>[src]

impl<'a> From<Storage<'a>> for DeviceWrapper<'a>[src]

impl<'a> GenerateOtp for DeviceWrapper<'a>[src]

impl<'a> GetPasswordSafe<'a> for DeviceWrapper<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for DeviceWrapper<'a>

impl<'a> Send for DeviceWrapper<'a>

impl<'a> Sync for DeviceWrapper<'a>

impl<'a> Unpin for DeviceWrapper<'a>

impl<'a> !UnwindSafe for DeviceWrapper<'a>

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.