diff options
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/util.rs b/src/util.rs index 364b0de..1608952 100644 --- a/src/util.rs +++ b/src/util.rs @@ -39,15 +39,6 @@ pub enum CommandError { RngError, } -/// Command execution status. -#[derive(Debug, PartialEq)] -pub enum CommandStatus { - /// The command was successful. - Success, - /// An error occured during command execution. - Error(CommandError), -} - /// Log level for libnitrokey. /// /// Setting the log level to a lower level enables all output from higher levels too. Currently, @@ -90,17 +81,22 @@ pub fn result_from_string(ptr: *const c_char) -> Result<String, CommandError> { } } -pub fn get_last_status() -> CommandStatus { - unsafe { - let status = nitrokey_sys::NK_get_last_command_status(); - return CommandStatus::from(status as c_int); +pub fn get_command_result(value: c_int) -> Result<(), CommandError> { + match value { + 0 => Ok(()), + other => Err(CommandError::from(other)), } } +pub fn get_last_result() -> Result<(), CommandError> { + let value = unsafe { nitrokey_sys::NK_get_last_command_status() } as c_int; + get_command_result(value) +} + pub fn get_last_error() -> CommandError { - return match get_last_status() { - CommandStatus::Success => CommandError::Unknown, - CommandStatus::Error(err) => err, + return match get_last_result() { + Ok(()) => CommandError::Unknown, + Err(err) => err, }; } @@ -133,15 +129,6 @@ impl From<c_int> for CommandError { } } -impl From<c_int> for CommandStatus { - fn from(value: c_int) -> Self { - match value { - 0 => CommandStatus::Success, - other => CommandStatus::Error(CommandError::from(other)), - } - } -} - impl Into<i32> for LogLevel { fn into(self) -> i32 { match self { |