Struct nitrokey::Storage

source ·
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

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
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),
};

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),
};

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

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
Formats the value using the given formatter. 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
Changes the administrator PIN. Read more
Changes the user PIN. Read more
Unlocks the user PIN after three failed login attempts and sets it to the given value. Read more
Locks the Nitrokey device. Read more
Executes the destructor for this type. Read more
Sets the time on the Nitrokey. This command may set the time to arbitrary values. time is the number of seconds since January 1st, 1970 (Unix timestamp). 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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.