aboutsummaryrefslogtreecommitdiff
path: root/src/otp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/otp.rs')
-rw-r--r--src/otp.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/otp.rs b/src/otp.rs
index b89d2bf..1094520 100644
--- a/src/otp.rs
+++ b/src/otp.rs
@@ -1,6 +1,6 @@
use nitrokey_sys;
use std::ffi::CString;
-use util::{result_from_string, CommandError, CommandStatus};
+use util::{get_command_result, result_from_string, CommandError};
/// Modes for one-time password generation.
#[derive(Debug, PartialEq)]
@@ -25,7 +25,7 @@ pub trait ConfigureOtp {
/// # Example
///
/// ```no_run
- /// use nitrokey::{Authenticate, CommandStatus, ConfigureOtp, OtpMode, OtpSlotData};
+ /// use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData};
/// # use nitrokey::CommandError;
///
/// # fn try_main() -> Result<(), (CommandError)> {
@@ -34,8 +34,8 @@ pub trait ConfigureOtp {
/// match device.authenticate_admin("12345678") {
/// Ok(admin) => {
/// match admin.write_hotp_slot(slot_data, 0) {
- /// CommandStatus::Success => println!("Successfully wrote slot."),
- /// CommandStatus::Error(err) => println!("Could not write slot: {:?}", err),
+ /// Ok(()) => println!("Successfully wrote slot."),
+ /// Err(err) => println!("Could not write slot: {:?}", err),
/// }
/// },
/// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err),
@@ -47,7 +47,7 @@ pub trait ConfigureOtp {
/// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`InvalidString`]: enum.CommandError.html#variant.InvalidString
/// [`NoName`]: enum.CommandError.html#variant.NoName
- fn write_hotp_slot(&self, data: OtpSlotData, counter: u64) -> CommandStatus;
+ fn write_hotp_slot(&self, data: OtpSlotData, counter: u64) -> Result<(), CommandError>;
/// Configure a TOTP slot with the given data and set the TOTP time window to the given value
/// (default 30).
@@ -61,7 +61,7 @@ pub trait ConfigureOtp {
/// # Example
///
/// ```no_run
- /// use nitrokey::{Authenticate, CommandStatus, ConfigureOtp, OtpMode, OtpSlotData};
+ /// use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData};
/// # use nitrokey::CommandError;
///
/// # fn try_main() -> Result<(), (CommandError)> {
@@ -70,8 +70,8 @@ pub trait ConfigureOtp {
/// match device.authenticate_admin("12345678") {
/// Ok(admin) => {
/// match admin.write_totp_slot(slot_data, 30) {
- /// CommandStatus::Success => println!("Successfully wrote slot."),
- /// CommandStatus::Error(err) => println!("Could not write slot: {:?}", err),
+ /// Ok(()) => println!("Successfully wrote slot."),
+ /// Err(err) => println!("Could not write slot: {:?}", err),
/// }
/// },
/// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err),
@@ -83,7 +83,7 @@ pub trait ConfigureOtp {
/// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`InvalidString`]: enum.CommandError.html#variant.InvalidString
/// [`NoName`]: enum.CommandError.html#variant.NoName
- fn write_totp_slot(&self, data: OtpSlotData, time_window: u16) -> CommandStatus;
+ fn write_totp_slot(&self, data: OtpSlotData, time_window: u16) -> Result<(), CommandError>;
/// Erases an HOTP slot.
///
@@ -94,7 +94,7 @@ pub trait ConfigureOtp {
/// # Example
///
/// ```no_run
- /// use nitrokey::{Authenticate, CommandStatus, ConfigureOtp};
+ /// use nitrokey::{Authenticate, ConfigureOtp};
/// # use nitrokey::CommandError;
///
/// # fn try_main() -> Result<(), (CommandError)> {
@@ -102,8 +102,8 @@ pub trait ConfigureOtp {
/// match device.authenticate_admin("12345678") {
/// Ok(admin) => {
/// match admin.erase_hotp_slot(1) {
- /// CommandStatus::Success => println!("Successfully erased slot."),
- /// CommandStatus::Error(err) => println!("Could not erase slot: {:?}", err),
+ /// Ok(()) => println!("Successfully erased slot."),
+ /// Err(err) => println!("Could not erase slot: {:?}", err),
/// }
/// },
/// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err),
@@ -113,7 +113,7 @@ pub trait ConfigureOtp {
/// ```
///
/// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
- fn erase_hotp_slot(&self, slot: u8) -> CommandStatus;
+ fn erase_hotp_slot(&self, slot: u8) -> Result<(), CommandError>;
/// Erases a TOTP slot.
///
@@ -124,7 +124,7 @@ pub trait ConfigureOtp {
/// # Example
///
/// ```no_run
- /// use nitrokey::{Authenticate, CommandStatus, ConfigureOtp};
+ /// use nitrokey::{Authenticate, ConfigureOtp};
/// # use nitrokey::CommandError;
///
/// # fn try_main() -> Result<(), (CommandError)> {
@@ -132,8 +132,8 @@ pub trait ConfigureOtp {
/// match device.authenticate_admin("12345678") {
/// Ok(admin) => {
/// match admin.erase_totp_slot(1) {
- /// CommandStatus::Success => println!("Successfully erased slot."),
- /// CommandStatus::Error(err) => println!("Could not erase slot: {:?}", err),
+ /// Ok(()) => println!("Successfully erased slot."),
+ /// Err(err) => println!("Could not erase slot: {:?}", err),
/// }
/// },
/// Err((_, err)) => println!("Could not authenticate as admin: {:?}", err),
@@ -143,7 +143,7 @@ pub trait ConfigureOtp {
/// ```
///
/// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
- fn erase_totp_slot(&self, slot: u8) -> CommandStatus;
+ fn erase_totp_slot(&self, slot: u8) -> Result<(), CommandError>;
}
/// Provides methods to generate OTP codes and to query OTP slots on a Nitrokey
@@ -181,8 +181,8 @@ pub trait GenerateOtp {
///
/// [`get_totp_code`]: #method.get_totp_code
/// [`Timestamp`]: enum.CommandError.html#variant.Timestamp
- fn set_time(&self, time: u64) -> CommandStatus {
- unsafe { CommandStatus::from(nitrokey_sys::NK_totp_set_time(time)) }
+ fn set_time(&self, time: u64) -> Result<(), CommandError> {
+ unsafe { get_command_result(nitrokey_sys::NK_totp_set_time(time)) }
}
/// Returns the name of the given HOTP slot.