[][src]Struct nitrokey::Manager

pub struct Manager { /* fields omitted */ }

A manager for connections to Nitrokey devices.

Currently, libnitrokey only provides access to one Nitrokey device at the same time. This manager struct makes sure that nitrokey-rs does not try to connect to two devices at the same time.

To obtain a reference to an instance of this manager, use the take function. Use one of the connect methods – connect, connect_model, connect_pro or connect_storage – to retrieve a Device instance.

Examples

Connect to a single device:

use nitrokey::Device;

let mut manager = nitrokey::take()?;
let device = manager.connect()?;
println!("{}", device.get_serial_number()?);

Connect to a Pro and a Storage device:

use nitrokey::{Device, Model};

let mut manager = nitrokey::take()?;
let device = manager.connect_model(Model::Pro)?;
println!("Pro: {}", device.get_serial_number()?);
drop(device);
let device = manager.connect_model(Model::Storage)?;
println!("Storage: {}", device.get_serial_number()?);

Methods

impl Manager[src]

pub fn connect(&mut self) -> Result<DeviceWrapper, Error>[src]

Connects to a Nitrokey device.

This method can be used to connect to any connected device, both a Nitrokey Pro and a Nitrokey Storage.

Errors

Example

use nitrokey::DeviceWrapper;

fn do_something(device: DeviceWrapper) {}

let mut manager = nitrokey::take()?;
match manager.connect() {
    Ok(device) => do_something(device),
    Err(err) => println!("Could not connect to a Nitrokey: {}", err),
}

pub fn connect_model(&mut self, model: Model) -> Result<DeviceWrapper, Error>[src]

Connects to a Nitrokey device of the given model.

Errors

  • NotConnected if no Nitrokey device of the given model is connected

Example

use nitrokey::DeviceWrapper;
use nitrokey::Model;

fn do_something(device: DeviceWrapper) {}

match nitrokey::take()?.connect_model(Model::Pro) {
    Ok(device) => do_something(device),
    Err(err) => println!("Could not connect to a Nitrokey Pro: {}", err),
}

pub fn connect_path<S: Into<Vec<u8>>>(
    &mut self,
    path: S
) -> Result<DeviceWrapper, Error>
[src]

Connects to a Nitrokey device at the given USB path.

To get a list of all connected Nitrokey devices, use the list_devices function. The DeviceInfo structs returned by that function contain the USB path in the path field.

Errors

  • InvalidString if the USB path contains a null byte
  • NotConnected if no Nitrokey device can be found at the given USB path
  • UnsupportedModelError if the model of the Nitrokey device at the given USB path is not supported by this crate

Example

use nitrokey::DeviceWrapper;

fn use_device(device: DeviceWrapper) {}

let mut manager = nitrokey::take()?;
let devices = nitrokey::list_devices()?;
for device in devices {
    let device = manager.connect_path(device.path)?;
    use_device(device);
}

pub fn connect_pro(&mut self) -> Result<Pro, Error>[src]

Connects to a Nitrokey Pro.

Errors

  • NotConnected if no Nitrokey device of the given model is connected

Example

use nitrokey::Pro;

fn use_pro(device: Pro) {}

match nitrokey::take()?.connect_pro() {
    Ok(device) => use_pro(device),
    Err(err) => println!("Could not connect to the Nitrokey Pro: {}", err),
}

pub fn connect_storage(&mut self) -> Result<Storage, Error>[src]

Connects to a Nitrokey Storage.

Errors

  • NotConnected if no Nitrokey device of the given model is connected

Example

use nitrokey::Storage;

fn use_storage(device: Storage) {}

match nitrokey::take()?.connect_storage() {
    Ok(device) => use_storage(device),
    Err(err) => println!("Could not connect to the Nitrokey Storage: {}", err),
}

Trait Implementations

impl Debug for Manager[src]

Auto Trait Implementations

impl RefUnwindSafe for Manager

impl Send for Manager

impl Sync for Manager

impl Unpin for Manager

impl UnwindSafe for Manager

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.