aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-23 04:36:57 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-23 05:38:30 +0100
commitb00bbaa5603504597729ed2ce0d1e8ff50ea078d (patch)
tree27af8fa4359afbe0f61a93982203657727a76623
parentd4663961c41a0fb6f81f4a54aefd0fedce49d350 (diff)
downloadnitrokey-rs-b00bbaa5603504597729ed2ce0d1e8ff50ea078d.tar.gz
nitrokey-rs-b00bbaa5603504597729ed2ce0d1e8ff50ea078d.tar.bz2
Implement From<(T: Device, Error)> for Error
Not all users of the authenticate methods want to use the device after an error, so implementing From<(T: Device, Error)> for Error makes it easier for them to discard the device.
-rw-r--r--CHANGELOG.md1
-rw-r--r--TODO.md1
-rw-r--r--src/error.rs8
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 70bd7cb..c28c228 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@
- Add `Error::Utf8Error` variant.
- Return `Result<Version>` instead of `Version` from `get_library_version`.
- Return `Error::Utf8Error` if libnitrokey returns an invalid UTF-8 string.
+- Implement `From<(T: Device, Error)>` for `Error`.
# v0.3.4 (2019-01-20)
- Fix authentication methods that assumed that `char` is signed.
diff --git a/TODO.md b/TODO.md
index 0467f1d..49e4e08 100644
--- a/TODO.md
+++ b/TODO.md
@@ -8,7 +8,6 @@
- Fix timing issues with the `totp_no_pin` and `totp_pin` test cases.
- Clear passwords from memory.
- Find a nicer syntax for the `write_config` test.
-- Consider implementing `Into<CommandError>` for `(Device, CommandError)`
- Lock password safe in `PasswordSafe::drop()` (see [nitrokey-storage-firmware
issue 65][]).
- Disable creation of multiple password safes at the same time.
diff --git a/src/error.rs b/src/error.rs
index 4b82c6e..551dd0f 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -4,6 +4,8 @@ use std::os::raw;
use std::result;
use std::str;
+use crate::device;
+
/// An error returned by the nitrokey crate.
#[derive(Debug)]
pub enum Error {
@@ -67,6 +69,12 @@ impl From<str::Utf8Error> for Error {
}
}
+impl<T: device::Device> From<(T, Error)> for Error {
+ fn from((_, err): (T, Error)) -> Self {
+ err
+ }
+}
+
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {