pub trait ConfigureOtp {
    fn write_hotp_slot(
        &self,
        data: OtpSlotData,
        counter: u64
    ) -> Result<(), CommandError>; fn write_totp_slot(
        &self,
        data: OtpSlotData,
        time_window: u16
    ) -> Result<(), CommandError>; fn erase_hotp_slot(&self, slot: u8) -> Result<(), CommandError>; fn erase_totp_slot(&self, slot: u8) -> Result<(), CommandError>; }
Expand description

Provides methods to configure and erase OTP slots on a Nitrokey device.

Required Methods

Configure an HOTP slot with the given data and set the HOTP counter to the given value (default 0).

Errors
  • InvalidSlot if there is no slot with the given number
  • InvalidString if the provided token ID contains a null byte
  • NoName if the provided name is empty
Example
use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData};

let device = nitrokey::connect()?;
let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::SixDigits);
match device.authenticate_admin("12345678") {
    Ok(admin) => {
        match admin.write_hotp_slot(slot_data, 0) {
            Ok(()) => println!("Successfully wrote slot."),
            Err(err) => println!("Could not write slot: {}", err),
        }
    },
    Err((_, err)) => println!("Could not authenticate as admin: {}", err),
}

Configure a TOTP slot with the given data and set the TOTP time window to the given value (default 30).

Errors
  • InvalidSlot if there is no slot with the given number
  • InvalidString if the provided token ID contains a null byte
  • NoName if the provided name is empty
Example
use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData};

let device = nitrokey::connect()?;
let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::EightDigits);
match device.authenticate_admin("12345678") {
    Ok(admin) => {
        match admin.write_totp_slot(slot_data, 30) {
            Ok(()) => println!("Successfully wrote slot."),
            Err(err) => println!("Could not write slot: {}", err),
        }
    },
    Err((_, err)) => println!("Could not authenticate as admin: {}", err),
}

Erases an HOTP slot.

Errors
  • InvalidSlot if there is no slot with the given number
Example
use nitrokey::{Authenticate, ConfigureOtp};

let device = nitrokey::connect()?;
match device.authenticate_admin("12345678") {
    Ok(admin) => {
        match admin.erase_hotp_slot(1) {
            Ok(()) => println!("Successfully erased slot."),
            Err(err) => println!("Could not erase slot: {}", err),
        }
    },
    Err((_, err)) => println!("Could not authenticate as admin: {}", err),
}

Erases a TOTP slot.

Errors
  • InvalidSlot if there is no slot with the given number
Example
use nitrokey::{Authenticate, ConfigureOtp};

let device = nitrokey::connect()?;
match device.authenticate_admin("12345678") {
    Ok(admin) => {
        match admin.erase_totp_slot(1) {
            Ok(()) => println!("Successfully erased slot."),
            Err(err) => println!("Could not erase slot: {}", err),
        }
    },
    Err((_, err)) => println!("Could not authenticate as admin: {}", err),
}

Implementors