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
sourcefn get_serial_number(&self) -> Result<String, CommandError>
fn get_serial_number(&self) -> Result<String, CommandError>
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),
};
sourcefn get_user_retry_count(&self) -> u8
fn get_user_retry_count(&self) -> u8
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);
sourcefn get_admin_retry_count(&self) -> u8
fn get_admin_retry_count(&self) -> u8
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);
sourcefn get_major_firmware_version(&self) -> i32
fn get_major_firmware_version(&self) -> i32
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(),
);
sourcefn get_minor_firmware_version(&self) -> i32
fn get_minor_firmware_version(&self) -> i32
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(),
);
sourcefn get_config(&self) -> Result<Config, CommandError>
fn get_config(&self) -> Result<Config, CommandError>
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);
sourcefn change_admin_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
fn change_admin_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
Changes the administrator PIN.
Errors
InvalidString
if one of the provided passwords contains a null byteWrongPassword
if the current admin password is wrong
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),
};
sourcefn change_user_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
fn change_user_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
Changes the user PIN.
Errors
InvalidString
if one of the provided passwords contains a null byteWrongPassword
if the current user password is wrong
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),
};
sourcefn unlock_user_pin(
&self,
admin_pin: &str,
user_pin: &str
) -> Result<(), CommandError>
fn unlock_user_pin(
&self,
admin_pin: &str,
user_pin: &str
) -> Result<(), CommandError>
Unlocks the user PIN after three failed login attempts and sets it to the given value.
Errors
InvalidString
if one of the provided passwords contains a null byteWrongPassword
if the admin password is wrong
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),
};
sourcefn lock(&self) -> Result<(), CommandError>
fn lock(&self) -> Result<(), CommandError>
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),
};