Trait nitrokey::Device

source ·
pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp {
    fn get_serial_number(&self) -> Result<String, CommandError> { ... }
    fn get_user_retry_count(&self) -> u8 { ... }
    fn get_admin_retry_count(&self) -> u8 { ... }
    fn get_major_firmware_version(&self) -> i32 { ... }
    fn get_minor_firmware_version(&self) -> i32 { ... }
    fn get_config(&self) -> Result<Config, CommandError> { ... }
    fn change_admin_pin(
        &self,
        current: &str,
        new: &str
    ) -> Result<(), CommandError> { ... } fn change_user_pin(
        &self,
        current: &str,
        new: &str
    ) -> Result<(), CommandError> { ... } fn unlock_user_pin(
        &self,
        admin_pin: &str,
        user_pin: &str
    ) -> Result<(), CommandError> { ... } fn lock(&self) -> Result<(), CommandError> { ... } }
Expand description

A Nitrokey device.

This trait provides the commands that can be executed without authentication and that are present on all supported Nitrokey devices.

Provided Methods

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

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
match device.get_serial_number() {
    Ok(number) => println!("serial no: {}", number),
    Err(err) => println!("Could not get serial number: {}", err),
};

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

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
let count = device.get_user_retry_count();
println!("{} remaining authentication attempts (user)", count);

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

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
let count = device.get_admin_retry_count();
println!("{} remaining authentication attempts (admin)", count);

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

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
println!(
    "Firmware version: {}.{}",
    device.get_major_firmware_version(),
    device.get_minor_firmware_version(),
);

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

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
println!(
    "Firmware version: {}.{}",
    device.get_major_firmware_version(),
    device.get_minor_firmware_version(),
);

Returns the current configuration of the Nitrokey device.

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
let config = device.get_config()?;
println!("numlock binding:          {:?}", config.numlock);
println!("capslock binding:         {:?}", config.capslock);
println!("scrollock binding:        {:?}", config.scrollock);
println!("require password for OTP: {:?}", config.user_password);

Changes the administrator PIN.

Errors
Example
use nitrokey::Device;

let device = nitrokey::connect()?;
match device.change_admin_pin("12345678", "12345679") {
    Ok(()) => println!("Updated admin PIN."),
    Err(err) => println!("Failed to update admin PIN: {}", err),
};

Changes the user PIN.

Errors
Example
use nitrokey::Device;

let device = nitrokey::connect()?;
match device.change_user_pin("123456", "123457") {
    Ok(()) => println!("Updated admin PIN."),
    Err(err) => println!("Failed to update admin PIN: {}", err),
};

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

Errors
Example
use nitrokey::Device;

let device = nitrokey::connect()?;
match device.unlock_user_pin("12345678", "123456") {
    Ok(()) => println!("Unlocked user PIN."),
    Err(err) => println!("Failed to unlock user PIN: {}", err),
};

Locks the Nitrokey device.

This disables the password store if it has been unlocked. On the Nitrokey Storage, this also disables the volumes if they have been enabled.

Example
use nitrokey::Device;

let device = nitrokey::connect()?;
match device.lock() {
    Ok(()) => println!("Locked the Nitrokey device."),
    Err(err) => println!("Could not lock the Nitrokey device: {}", err),
};

Implementors