diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-23 04:02:51 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-23 04:02:51 +0000 |
commit | 425010284341fcc745072dcd39b9fa398ae8db69 (patch) | |
tree | 2113f1f26302d8558905dff689f0756d5ba332f6 | |
parent | 5540ca5e76ffe5efe27d8819efb9e62066a10219 (diff) | |
download | nitrokey-rs-425010284341fcc745072dcd39b9fa398ae8db69.tar.gz nitrokey-rs-425010284341fcc745072dcd39b9fa398ae8db69.tar.bz2 |
Add Pro::new and Storage::new functions
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/device.rs | 20 |
2 files changed, 15 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 365b864..92a4dac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ instantiation impossible. - Refactor and clean up internal code: - Prefer using the `Into` trait over numeric casting. + - Add `Pro::new` and `Storage::new` functions. # v0.3.4 (2019-01-20) - Fix authentication methods that assumed that `char` is signed. diff --git a/src/device.rs b/src/device.rs index 287268b..2abf801 100644 --- a/src/device.rs +++ b/src/device.rs @@ -788,12 +788,16 @@ impl Pro { pub fn connect() -> Result<Pro, Error> { // TODO: maybe Option instead of Result? match connect_enum(Model::Pro) { - true => Ok(Pro { - marker: marker::PhantomData, - }), + true => Ok(Pro::new()), false => Err(CommunicationError::NotConnected.into()), } } + + fn new() -> Pro { + Pro { + marker: marker::PhantomData, + } + } } impl Drop for Pro { @@ -836,13 +840,17 @@ impl Storage { pub fn connect() -> Result<Storage, Error> { // TODO: maybe Option instead of Result? match connect_enum(Model::Storage) { - true => Ok(Storage { - marker: marker::PhantomData, - }), + true => Ok(Storage::new()), false => Err(CommunicationError::NotConnected.into()), } } + fn new() -> Storage { + Storage { + marker: marker::PhantomData, + } + } + /// Changes the update PIN. /// /// The update PIN is used to enable firmware updates. Unlike the user and the admin PIN, the |