aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-20 20:58:18 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 21:08:20 +0000
commit94390aadc8a3997d379bf5e4c0bc00c2a9669a34 (patch)
treea22cb82e8d6450ad034230d77e2db6605e54df8b /src/error.rs
parentdb198936be1a80f1735731d9e95eb6f4c48a5329 (diff)
downloadnitrokey-rs-94390aadc8a3997d379bf5e4c0bc00c2a9669a34.tar.gz
nitrokey-rs-94390aadc8a3997d379bf5e4c0bc00c2a9669a34.tar.bz2
Return Error instead of CommandError
This patch changes all public functions to return the Error enum instead of the CommandError enum. This breaks the tests which will be fixed with the next patch. This patch also adds a placeholder variant Error::CommandError and a placeholder enum CommandError to make the transition to a new nitrokey-test version easier.
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 89c4c82..3f60af2 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -9,6 +9,8 @@ use std::result;
pub enum Error {
/// An error reported by the Nitrokey device in the response packet.
CommandError(CommandError),
+ /// Placeholder for testing.
+ CommunicationError(CommunicationError),
}
impl From<CommandError> for Error {
@@ -21,6 +23,7 @@ impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Error::CommandError(ref err) => Some(err),
+ Error::CommunicationError(_) => None,
}
}
}
@@ -29,6 +32,7 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Error::CommandError(ref err) => write!(f, "Command error: {}", err),
+ Error::CommunicationError(_) => write!(f, "Placeholder"),
}
}
}
@@ -78,6 +82,13 @@ pub enum CommandError {
RngError,
}
+/// Placeholder for testing.
+#[derive(Debug)]
+pub enum CommunicationError {
+ /// Placeholder for testing.
+ NotConnected,
+}
+
impl CommandError {
fn as_str(&self) -> borrow::Cow<'static, str> {
match *self {