aboutsummaryrefslogtreecommitdiff
path: root/src/device.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-27 17:44:59 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-08 21:27:11 +0000
commit54d23475aa3b712a539bad129fe37223173268f2 (patch)
tree8eb20132a8cd38b6cd56965de58a91437a08d991 /src/device.rs
parent588066f415e956fdcd2c6f6216c52b25911a3b1d (diff)
downloadnitrokey-rs-54d23475aa3b712a539bad129fe37223173268f2.tar.gz
nitrokey-rs-54d23475aa3b712a539bad129fe37223173268f2.tar.bz2
Move the connect function into Manager
As part of the connection refactoring, we replace the connect function with the Manager::connect method. To maintain compatibility with nitrokey-test, the connect function is not removed but marked as deprecated.
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/device.rs b/src/device.rs
index 51551c2..653c5d1 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -647,15 +647,9 @@ pub trait Device: Authenticate + GetPasswordSafe + GenerateOtp + fmt::Debug {
/// ```
///
/// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected
+#[deprecated(since = "0.4.0", note = "use `nitrokey::Manager::connect` instead")]
pub fn connect() -> Result<DeviceWrapper, Error> {
- if unsafe { nitrokey_sys::NK_login_auto() } == 1 {
- match get_connected_device() {
- Some(wrapper) => Ok(wrapper),
- None => Err(CommunicationError::NotConnected.into()),
- }
- } else {
- Err(CommunicationError::NotConnected.into())
- }
+ crate::take()?.connect().map_err(Into::into)
}
/// Connects to a Nitrokey device of the given model.
@@ -702,7 +696,7 @@ fn create_device_wrapper(model: Model) -> DeviceWrapper {
}
}
-fn get_connected_device() -> Option<DeviceWrapper> {
+pub(crate) fn get_connected_device() -> Option<DeviceWrapper> {
get_connected_model().map(create_device_wrapper)
}