ConfigureOtp

Trait ConfigureOtp 

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

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

Required Methods§

Source

fn write_hotp_slot( &mut self, data: OtpSlotData, counter: u64, ) -> Result<(), Error>

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 mut manager = nitrokey::take()?;
let device = manager.connect()?;
let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::SixDigits);
match device.authenticate_admin("12345678") {
    Ok(mut admin) => {
        match admin.write_hotp_slot(slot_data, 0) {
            Ok(()) => println!("Successfully wrote slot."),
            Err(err) => eprintln!("Could not write slot: {}", err),
        }
    },
    Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err),
}
Source

fn write_totp_slot( &mut self, data: OtpSlotData, time_window: u16, ) -> Result<(), Error>

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 mut manager = nitrokey::take()?;
let device = manager.connect()?;
let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::EightDigits);
match device.authenticate_admin("12345678") {
    Ok(mut admin) => {
        match admin.write_totp_slot(slot_data, 30) {
            Ok(()) => println!("Successfully wrote slot."),
            Err(err) => eprintln!("Could not write slot: {}", err),
        }
    },
    Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err),
}
Source

fn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error>

Erases an HOTP slot.

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

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

fn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error>

Erases a TOTP slot.

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

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

Implementors§

Source§

impl<'a, T: Device<'a>> ConfigureOtp for Admin<'a, T>