[][src]Trait nitrokey::ConfigureOtp

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

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

Required methods

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

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

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

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

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

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

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

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),
}
Loading content...

Implementors

impl<T: Device> ConfigureOtp for Admin<T>[src]

Loading content...