summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 471d481..117659f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -394,8 +394,8 @@ pub trait Device {
///
/// # Errors
///
+ /// - [`InvalidSlot`][] if there is no slot with the given number
/// - [`SlotNotProgrammed`][] if the given slot is not configured
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -413,8 +413,8 @@ pub trait Device {
/// # }
/// ```
///
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
fn get_hotp_slot_name(&self, slot: u8) -> Result<String, CommandError> {
unsafe { result_from_string(nitrokey_sys::NK_get_hotp_slot_name(slot)) }
}
@@ -423,8 +423,8 @@ pub trait Device {
///
/// # Errors
///
+ /// - [`InvalidSlot`][] if there is no slot with the given number
/// - [`SlotNotProgrammed`][] if the given slot is not configured
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -442,8 +442,8 @@ pub trait Device {
/// # }
/// ```
///
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
fn get_totp_slot_name(&self, slot: u8) -> Result<String, CommandError> {
unsafe { result_from_string(nitrokey_sys::NK_get_totp_slot_name(slot)) }
}
@@ -569,9 +569,9 @@ pub trait Device {
///
/// # Errors
///
+ /// - [`InvalidSlot`][] if there is no slot with the given number
/// - [`NotAuthorized`][] if OTP generation requires user authentication
/// - [`SlotNotProgrammed`][] if the given slot is not configured
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -588,9 +588,9 @@ pub trait Device {
/// ```
///
/// [`get_config`]: #method.get_config
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`NotAuthorized`]: enum.CommandError.html#variant.NotAuthorized
/// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
fn get_hotp_code(&self, slot: u8) -> Result<String, CommandError> {
unsafe {
return result_from_string(nitrokey_sys::NK_get_hotp_code(slot));
@@ -606,9 +606,9 @@ pub trait Device {
///
/// # Errors
///
+ /// - [`InvalidSlot`][] if there is no slot with the given number
/// - [`NotAuthorized`][] if OTP generation requires user authentication
/// - [`SlotNotProgrammed`][] if the given slot is not configured
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -626,9 +626,9 @@ pub trait Device {
///
/// [`set_time`]: #method.set_time
/// [`get_config`]: #method.get_config
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`NotAuthorized`]: enum.CommandError.html#variant.NotAuthorized
/// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
fn get_totp_code(&self, slot: u8) -> Result<String, CommandError> {
unsafe {
return result_from_string(nitrokey_sys::NK_get_totp_code(slot, 0, 0, 0));
@@ -746,6 +746,7 @@ impl From<c_int> for CommandError {
8 => CommandError::NotSupported,
9 => CommandError::UnknownCommand,
10 => CommandError::AesDecryptionFailed,
+ 201 => CommandError::InvalidSlot,
_ => CommandError::Unknown,
}
}
@@ -799,10 +800,11 @@ fn result_from_string(ptr: *const std::os::raw::c_char) -> Result<String, Comman
}
unsafe {
let s = owned_str_from_ptr(ptr);
- libc::free(ptr as *mut libc::c_void);
if s.is_empty() {
return Err(get_last_error());
}
+ // TODO: move up for newer libnitrokey versions
+ libc::free(ptr as *mut libc::c_void);
return Ok(s);
}
}
@@ -1214,9 +1216,9 @@ impl AdminAuthenticatedDevice {
///
/// # 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
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -1240,9 +1242,9 @@ impl AdminAuthenticatedDevice {
/// # }
/// ```
///
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`InvalidString`]: enum.CommandError.html#variant.InvalidString
/// [`NoName`]: enum.CommandError.html#variant.NoName
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
pub fn write_hotp_slot(&self, data: OtpSlotData, counter: u64) -> CommandStatus {
return self.write_otp_slot(data, |raw_data: RawOtpSlotData, temp_password_ptr| unsafe {
nitrokey_sys::NK_write_hotp_slot(
@@ -1264,9 +1266,9 @@ impl AdminAuthenticatedDevice {
///
/// # 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
- /// - [`WrongSlot`][] if there is no slot with the given number
///
/// # Example
///
@@ -1290,9 +1292,9 @@ impl AdminAuthenticatedDevice {
/// # }
/// ```
///
+ /// [`InvalidSlot`]: enum.CommandError.html#variant.InvalidSlot
/// [`InvalidString`]: enum.CommandError.html#variant.InvalidString
/// [`NoName`]: enum.CommandError.html#variant.NoName
- /// [`WrongSlot`]: enum.CommandError.html#variant.WrongSlot
pub fn write_totp_slot(&self, data: OtpSlotData, time_window: u16) -> CommandStatus {
return self.write_otp_slot(data, |raw_data: RawOtpSlotData, temp_password_ptr| unsafe {
nitrokey_sys::NK_write_totp_slot(