diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-27 23:23:00 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-27 23:23:00 +0000 |
commit | c30cbd35ba187cd6e5055d3beb8420b11fb030ec (patch) | |
tree | 60522f8d7c2230e7f04e3ec7f1f295d779a4a855 /src/util.rs | |
parent | d433189caefe6bd6c88da7fbb1d6e9304353eb83 (diff) | |
download | nitrokey-rs-c30cbd35ba187cd6e5055d3beb8420b11fb030ec.tar.gz nitrokey-rs-c30cbd35ba187cd6e5055d3beb8420b11fb030ec.tar.bz2 |
Always return a Result when communicating with a device
Previously, we sometimes returned a value without wrapping it in a
result if the API method did not indicate errors in the return value.
But we can detect errors using the NK_get_last_command_status function.
This patch changes the return types of these methods to Result<_, Error>
and adds error checks.
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs index b7e8cd3..fdb73c3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -53,6 +53,10 @@ pub fn result_from_string(ptr: *const c_char) -> Result<String, Error> { } } +pub fn result_or_error<T>(value: T) -> Result<T, Error> { + get_last_result().and(Ok(value)) +} + pub fn get_command_result(value: c_int) -> Result<(), Error> { if value == 0 { Ok(()) |