aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-12-30 10:53:54 +0100
committerRobin Krahl <robin.krahl@ireas.org>2020-01-07 11:33:04 +0100
commitddb175bd963070e837aa9207c2dee32ffffc51f4 (patch)
tree699f93ff5d6bfd74bf3218b7a0d8dc725c54f7c7
parente0baabd1046087a9f545d9ef65539c23eb91e85f (diff)
downloadnitrokey-rs-ddb175bd963070e837aa9207c2dee32ffffc51f4.tar.gz
nitrokey-rs-ddb175bd963070e837aa9207c2dee32ffffc51f4.tar.bz2
Add the Error::UnsupportedModelError variant
This patch adds the UnsupportedModelError variant to the Error enum: When parsing the model returned by libnitrokey, we should provide a meaningful error message for unknown values.
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/error.rs4
2 files changed, 6 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71d2377..73bf782 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@ SPDX-License-Identifier: CC0-1.0
- `NK_enable_firmware_update_pro`
- `NK_list_devices_by_cpuID`
- `NK_send_startup`
+- Implement connection by path:
+ - Add the `Error::UnsupportedDeviceError` variant.
# v0.4.0 (2020-01-02)
- Remove the `test-pro` and `test-storage` features.
diff --git a/src/error.rs b/src/error.rs
index 9e6adc0..f9af594 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -28,6 +28,8 @@ pub enum Error {
UnexpectedError,
/// An unknown error returned by libnitrokey.
UnknownError(i64),
+ /// An error caused by a Nitrokey model that is not supported by this crate.
+ UnsupportedModelError,
/// An error occurred when interpreting a UTF-8 string.
Utf8Error(str::Utf8Error),
}
@@ -102,6 +104,7 @@ impl error::Error for Error {
Error::RandError(ref err) => Some(err.as_ref()),
Error::UnexpectedError => None,
Error::UnknownError(_) => None,
+ Error::UnsupportedModelError => None,
Error::Utf8Error(ref err) => Some(err),
}
}
@@ -118,6 +121,7 @@ impl fmt::Display for Error {
Error::RandError(ref err) => write!(f, "RNG error: {}", err),
Error::UnexpectedError => write!(f, "An unexpected error occurred"),
Error::UnknownError(ref err) => write!(f, "Unknown error: {}", err),
+ Error::UnsupportedModelError => write!(f, "Unsupported Nitrokey model"),
Error::Utf8Error(ref err) => write!(f, "UTF-8 error: {}", err),
}
}