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§
Sourcefn write_hotp_slot(
&mut self,
data: OtpSlotData,
counter: u64,
) -> Result<(), Error>
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
InvalidSlotif there is no slot with the given numberInvalidStringif the provided token ID contains a null byteNoNameif 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),
}Sourcefn write_totp_slot(
&mut self,
data: OtpSlotData,
time_window: u16,
) -> Result<(), Error>
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
InvalidSlotif there is no slot with the given numberInvalidStringif the provided token ID contains a null byteNoNameif 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),
}Sourcefn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error>
fn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error>
Erases an HOTP slot.
§Errors
InvalidSlotif 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),
}Sourcefn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error>
fn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error>
Erases a TOTP slot.
§Errors
InvalidSlotif 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),
}