aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-17 13:53:15 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-20 21:08:52 +0000
commit70e886d3ca487c306b8eced9f0e067a67ba9c1bb (patch)
tree2131bece64043051c5dd7921dbe329e22b13e195 /src
parentc191e875492ff8aeab1b4493b87486cd265f0edc (diff)
downloadnitrokey-rs-70e886d3ca487c306b8eced9f0e067a67ba9c1bb.tar.gz
nitrokey-rs-70e886d3ca487c306b8eced9f0e067a67ba9c1bb.tar.bz2
Return CommunicationError::NotConnected from connect functions
Previously, we returned a CommandError::Undefined if a connect function failed. A CommunicationError::NotConnected is a more specific and better fitting choice. Once the Try trait has been stabilized, we should return an Option<_> instead of a Result<_, Error> from the connect functions.
Diffstat (limited to 'src')
-rw-r--r--src/device.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/device.rs b/src/device.rs
index 5c4014b..1cf9da9 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -5,7 +5,7 @@ use nitrokey_sys;
use crate::auth::Authenticate;
use crate::config::{Config, RawConfig};
-use crate::error::{CommandError, Error};
+use crate::error::{CommunicationError, Error};
use crate::otp::GenerateOtp;
use crate::pws::GetPasswordSafe;
use crate::util::{get_command_result, get_cstring, get_last_error, result_from_string};
@@ -644,7 +644,7 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp {
///
/// # Errors
///
-/// - [`Undefined`][] if no Nitrokey device is connected
+/// - [`NotConnected`][] if no Nitrokey device is connected
///
/// # Example
///
@@ -659,15 +659,15 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp {
/// }
/// ```
///
-/// [`Undefined`]: enum.CommandError.html#variant.Undefined
+/// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
pub fn connect() -> Result<DeviceWrapper, Error> {
unsafe {
match nitrokey_sys::NK_login_auto() {
1 => match get_connected_device() {
Some(wrapper) => Ok(wrapper),
- None => Err(CommandError::Undefined.into()),
+ None => Err(CommunicationError::NotConnected.into()),
},
- _ => Err(CommandError::Undefined.into()),
+ _ => Err(CommunicationError::NotConnected.into()),
}
}
}
@@ -676,7 +676,7 @@ pub fn connect() -> Result<DeviceWrapper, Error> {
///
/// # Errors
///
-/// - [`Undefined`][] if no Nitrokey device of the given model is connected
+/// - [`NotConnected`][] if no Nitrokey device of the given model is connected
///
/// # Example
///
@@ -692,12 +692,12 @@ pub fn connect() -> Result<DeviceWrapper, Error> {
/// }
/// ```
///
-/// [`Undefined`]: enum.CommandError.html#variant.Undefined
+/// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
pub fn connect_model(model: Model) -> Result<DeviceWrapper, Error> {
if connect_enum(model) {
Ok(create_device_wrapper(model))
} else {
- Err(CommandError::Undefined.into())
+ Err(CommunicationError::NotConnected.into())
}
}
@@ -771,7 +771,7 @@ impl Pro {
///
/// # Errors
///
- /// - [`Undefined`][] if no Nitrokey device of the given model is connected
+ /// - [`NotConnected`][] if no Nitrokey device of the given model is connected
///
/// # Example
///
@@ -786,12 +786,12 @@ impl Pro {
/// }
/// ```
///
- /// [`Undefined`]: enum.CommandError.html#variant.Undefined
+ /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
pub fn connect() -> Result<Pro, Error> {
// TODO: maybe Option instead of Result?
match connect_enum(Model::Pro) {
true => Ok(Pro {}),
- false => Err(CommandError::Undefined.into()),
+ false => Err(CommunicationError::NotConnected.into()),
}
}
}
@@ -817,7 +817,7 @@ impl Storage {
///
/// # Errors
///
- /// - [`Undefined`][] if no Nitrokey device of the given model is connected
+ /// - [`NotConnected`][] if no Nitrokey device of the given model is connected
///
/// # Example
///
@@ -832,12 +832,12 @@ impl Storage {
/// }
/// ```
///
- /// [`Undefined`]: enum.CommandError.html#variant.Undefined
+ /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
pub fn connect() -> Result<Storage, Error> {
// TODO: maybe Option instead of Result?
match connect_enum(Model::Storage) {
true => Ok(Storage {}),
- false => Err(CommandError::Undefined.into()),
+ false => Err(CommunicationError::NotConnected.into()),
}
}