aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/util.rs b/src/util.rs
index 5a56c55..1b52c3d 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -39,7 +39,9 @@ pub fn owned_str_from_ptr(ptr: *const c_char) -> Result<String, Error> {
pub fn result_from_string(ptr: *const c_char) -> Result<String, Error> {
if ptr.is_null() {
- return Err(Error::UnexpectedError);
+ return Err(Error::UnexpectedError(
+ "libnitrokey returned a null pointer".to_owned(),
+ ));
}
let s = owned_str_from_ptr(ptr)?;
unsafe { free(ptr as *mut c_void) };
@@ -69,10 +71,9 @@ pub fn get_last_result() -> Result<(), Error> {
}
pub fn get_last_error() -> Error {
- match get_last_result() {
- Ok(()) => Error::UnexpectedError,
- Err(err) => err,
- }
+ get_last_result().err().unwrap_or_else(|| {
+ Error::UnexpectedError("Expected an error, but command status is zero".to_owned())
+ })
}
pub fn generate_password(length: usize) -> Result<Vec<u8>, Error> {