[−][src]Trait nitrokey::Device
A Nitrokey device.
This trait provides the commands that can be executed without authentication and that are present on all supported Nitrokey devices.
Required methods
fn get_model(&self) -> Model
Returns the model of the connected Nitrokey device.
Example
use nitrokey::Device; let device = nitrokey::connect()?; println!("Connected to a Nitrokey {}", device.get_model());
Provided methods
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), };
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);
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);
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(), );
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(), );
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);
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), };
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), };
fn unlock_user_pin(
&self,
admin_pin: &str,
user_pin: &str
) -> Result<(), CommandError>
&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), };
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), };
fn factory_reset(&self, admin_pin: &str) -> Result<(), CommandError>
Performs a factory reset on the Nitrokey device.
This commands performs a factory reset on the smart card (like the factory reset via gpg --card-edit
) and then clears the flash memory (password safe, one-time passwords etc.).
After a factory reset, build_aes_key
has to be called before the password safe or the
encrypted volume can be used.
Errors
- [
InvalidString
][] if the provided password contains a null byte - [
WrongPassword
][] if the admin password is wrong
Example
use nitrokey::Device; let device = nitrokey::connect()?; match device.factory_reset("12345678") { Ok(()) => println!("Performed a factory reset."), Err(err) => println!("Could not perform a factory reset: {}", err), };
fn build_aes_key(&self, admin_pin: &str) -> Result<(), CommandError>
Builds a new AES key on the Nitrokey.
The AES key is used to encrypt the password safe and the encrypted volume. You may need
to call this method after a factory reset, either using factory_reset
or using gpg --card-edit
. You can also use it to destroy the data stored in the password safe or on
the encrypted volume.
Errors
- [
InvalidString
][] if the provided password contains a null byte - [
WrongPassword
][] if the admin password is wrong
Example
use nitrokey::Device; let device = nitrokey::connect()?; match device.build_aes_key("12345678") { Ok(()) => println!("New AES keys have been built."), Err(err) => println!("Could not build new AES keys: {}", err), };