aboutsummaryrefslogtreecommitdiff
path: root/src/device.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-27 18:21:08 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-08 21:33:13 +0000
commit379bc798477a1de7ffda923c5d10ca63aebae25f (patch)
tree1cd4dcbc9ddcbf23b9f546d097f3d5ef2f454992 /src/device.rs
parentbd7c7a5fdf0ae66a1ff2f00beb5ed4c2e6994ca1 (diff)
downloadnitrokey-rs-379bc798477a1de7ffda923c5d10ca63aebae25f.tar.gz
nitrokey-rs-379bc798477a1de7ffda923c5d10ca63aebae25f.tar.bz2
Move {Pro, Storage}::connect into Manager
As part of the connection refactoring, this patch moves the connect methods of the Pro and Storage structs into the Manager struct. To maintain compatibility with nitrokey-test, the old methods are not removed but marked as deprecated.
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/device.rs b/src/device.rs
index f28558d..758691d 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -9,7 +9,7 @@ use nitrokey_sys;
use crate::auth::Authenticate;
use crate::config::{Config, RawConfig};
-use crate::error::{CommunicationError, Error};
+use crate::error::Error;
use crate::otp::GenerateOtp;
use crate::pws::GetPasswordSafe;
use crate::util::{
@@ -755,16 +755,12 @@ impl Pro {
/// ```
///
/// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
+ #[deprecated(since = "0.4.0", note = "use `nitrokey::Manager::connect_pro` instead")]
pub fn connect() -> Result<Pro, Error> {
- // TODO: maybe Option instead of Result?
- if connect_enum(Model::Pro) {
- Ok(Pro::new())
- } else {
- Err(CommunicationError::NotConnected.into())
- }
+ crate::take()?.connect_pro().map_err(Into::into)
}
- fn new() -> Pro {
+ pub(crate) fn new() -> Pro {
Pro {
marker: marker::PhantomData,
}
@@ -808,16 +804,15 @@ impl Storage {
/// ```
///
/// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
+ #[deprecated(
+ since = "0.4.0",
+ note = "use `nitrokey::Manager::connect_storage` instead"
+ )]
pub fn connect() -> Result<Storage, Error> {
- // TODO: maybe Option instead of Result?
- if connect_enum(Model::Storage) {
- Ok(Storage::new())
- } else {
- Err(CommunicationError::NotConnected.into())
- }
+ crate::take()?.connect_storage().map_err(Into::into)
}
- fn new() -> Storage {
+ pub(crate) fn new() -> Storage {
Storage {
marker: marker::PhantomData,
}