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.
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),
_ => (),
};
A Nitrokey Storage device.
Performs user authentication. This method consumes the device. If successful, an authenticated device is returned. Otherwise, the current unauthenticated device and the error are returned. Read more
Performs admin authentication. This method consumes the device. If successful, an authenticated device is returned. Otherwise, the current unauthenticated device and the error are returned. Read more
Returns the model of the connected Nitrokey device. Read more
Returns the serial number of the Nitrokey device. The serial number is the string representation of a hex number. Read more
Returns the number of remaining authentication attempts for the user. The total number of available attempts is three. Read more
Returns the number of remaining authentication attempts for the admin. The total number of available attempts is three. Read more
Returns the major part of the firmware version (should be zero). Read more
Returns the minor part of the firmware version (for example 8 for version 0.8). Read more
Returns the current configuration of the Nitrokey device. Read more
Unlocks the user PIN after three failed login attempts and sets it to the given value. Read more
Performs a factory reset on the Nitrokey device. Read more
Builds a new AES key on the Nitrokey. Read more
Returns the name of the given HOTP slot. Read more
Returns the name of the given TOTP slot. Read more
Generates an HOTP code on the given slot. This operation may require user authorization, depending on the device configuration (see [get_config
][]). Read more
Generates a TOTP code on the given slot. This operation may require user authorization, depending on the device configuration (see [get_config
][]). Read more
Enables and returns the password safe. Read more
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static