pub struct Storage {}
Expand description
A Nitrokey Storage device without user or admin authentication.
Use the global function connect
to obtain an instance wrapper or the method
connect
to directly obtain an instance. If you want to execute a
command that requires user or admin authentication, use authenticate_admin
or
authenticate_user
.
Examples
Authentication with error handling:
use nitrokey::{Authenticate, User, Storage};
fn perform_user_task(device: &User<Storage>) {}
fn perform_other_task(device: &Storage) {}
let device = nitrokey::Storage::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);
Implementations
sourceimpl Storage
impl Storage
pub fn connect() -> Result<Storage, CommandError>
sourcepub fn enable_encrypted_volume(&self, user_pin: &str) -> Result<(), CommandError>
pub fn enable_encrypted_volume(&self, user_pin: &str) -> Result<(), CommandError>
Enables the encrypted storage volume.
Once the encrypted volume is enabled, it is presented to the operating system as a block device. The API does not provide any information on the name or path of this block device.
Errors
InvalidString
if the provided password contains a null byteWrongPassword
if the provided user password is wrong
Example
let device = nitrokey::Storage::connect()?;
match device.enable_encrypted_volume("123456") {
Ok(()) => println!("Enabled the encrypted volume."),
Err(err) => println!("Could not enable the encrypted volume: {}", err),
};
sourcepub fn disable_encrypted_volume(&self) -> Result<(), CommandError>
pub fn disable_encrypted_volume(&self) -> Result<(), CommandError>
Disables the encrypted storage volume.
Once the volume is disabled, it can be no longer accessed as a block device. If the encrypted volume has not been enabled, this method still returns a success.
Example
fn use_volume() {}
let device = nitrokey::Storage::connect()?;
match device.enable_encrypted_volume("123456") {
Ok(()) => {
println!("Enabled the encrypted volume.");
use_volume();
match device.disable_encrypted_volume() {
Ok(()) => println!("Disabled the encrypted volume."),
Err(err) => {
println!("Could not disable the encrypted volume: {}", err);
},
};
},
Err(err) => println!("Could not enable the encrypted volume: {}", err),
};
sourcepub fn get_status(&self) -> Result<StorageStatus, CommandError>
pub fn get_status(&self) -> Result<StorageStatus, CommandError>
Returns the status of the connected storage device.
Example
fn use_volume() {}
let device = nitrokey::Storage::connect()?;
match device.get_status() {
Ok(status) => {
println!("SD card ID: {:#x}", status.serial_number_sd_card);
},
Err(err) => println!("Could not get Storage status: {}", err),
};
Trait Implementations
sourceimpl Authenticate for Storage
impl Authenticate for Storage
sourcefn authenticate_user(
self,
password: &str
) -> Result<User<Self>, (Self, CommandError)>
fn authenticate_user(
self,
password: &str
) -> Result<User<Self>, (Self, CommandError)>
sourcefn authenticate_admin(
self,
password: &str
) -> Result<Admin<Self>, (Self, CommandError)>
fn authenticate_admin(
self,
password: &str
) -> Result<Admin<Self>, (Self, CommandError)>
sourceimpl Device for Storage
impl Device for Storage
sourcefn get_serial_number(&self) -> Result<String, CommandError>
fn get_serial_number(&self) -> Result<String, CommandError>
sourcefn get_user_retry_count(&self) -> u8
fn get_user_retry_count(&self) -> u8
sourcefn get_admin_retry_count(&self) -> u8
fn get_admin_retry_count(&self) -> u8
sourcefn get_major_firmware_version(&self) -> i32
fn get_major_firmware_version(&self) -> i32
sourcefn get_minor_firmware_version(&self) -> i32
fn get_minor_firmware_version(&self) -> i32
sourcefn get_config(&self) -> Result<Config, CommandError>
fn get_config(&self) -> Result<Config, CommandError>
sourcefn change_admin_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
fn change_admin_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
sourcefn change_user_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
fn change_user_pin(&self, current: &str, new: &str) -> Result<(), CommandError>
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>
sourceimpl GenerateOtp for Storage
impl GenerateOtp for Storage
sourcefn set_time(&self, time: u64) -> Result<(), CommandError>
fn set_time(&self, time: u64) -> Result<(), CommandError>
time
is the number of seconds since January 1st, 1970 (Unix timestamp). Read moresourcefn get_hotp_slot_name(&self, slot: u8) -> Result<String, CommandError>
fn get_hotp_slot_name(&self, slot: u8) -> Result<String, CommandError>
sourcefn get_totp_slot_name(&self, slot: u8) -> Result<String, CommandError>
fn get_totp_slot_name(&self, slot: u8) -> Result<String, CommandError>
sourcefn get_hotp_code(&self, slot: u8) -> Result<String, CommandError>
fn get_hotp_code(&self, slot: u8) -> Result<String, CommandError>
get_config
). Read moresourcefn get_totp_code(&self, slot: u8) -> Result<String, CommandError>
fn get_totp_code(&self, slot: u8) -> Result<String, CommandError>
get_config
). Read more