diff options
| author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-28 12:05:42 +0000 | 
|---|---|---|
| committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-02 10:21:25 +0000 | 
| commit | e97ccf213eec4e2d056c2f72079e4eeb7ac66f3f (patch) | |
| tree | 9653ef1c0032c0ee5c7177b1252f6504ec13065c | |
| parent | ad76653b3be57c0cfd31c8056a8d68537034324e (diff) | |
| download | nitrokey-rs-e97ccf213eec4e2d056c2f72079e4eeb7ac66f3f.tar.gz nitrokey-rs-e97ccf213eec4e2d056c2f72079e4eeb7ac66f3f.tar.bz2 | |
Implement DerefMut for User and Admin
As we want to change some methods to take a mutable reference to a
Device, we implement DerefMut for User<T> and Admin<T> so that users can
obtain a mutable reference to the wrapped device.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | src/auth.rs | 18 | 
2 files changed, 17 insertions, 3 deletions
| diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e3065..fcba0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ SPDX-License-Identifier: MIT  - Always return a `Result` in functions that communicate with a device.  - Combine `get_{major,minor}_firmware_version` into `get_firmware_version`.  - Add `set_encrypted_volume_mode` to `Storage`. +- Use mutability to represent changes to the device status: +  - Implement `DerefMut` for `User<T>` and `Admin<T>`.  # v0.3.4 (2019-01-20)  - Fix authentication methods that assumed that `char` is signed. diff --git a/src/auth.rs b/src/auth.rs index 8978f32..8cec49c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,7 +1,7 @@  // Copyright (C) 2018-2019 Robin Krahl <robin.krahl@ireas.org>  // SPDX-License-Identifier: MIT -use std::ops::Deref; +use std::ops;  use std::os::raw::c_char;  use std::os::raw::c_int; @@ -211,7 +211,7 @@ impl<T: Device> User<T> {      }  } -impl<T: Device> Deref for User<T> { +impl<T: Device> ops::Deref for User<T> {      type Target = T;      fn deref(&self) -> &Self::Target { @@ -219,6 +219,12 @@ impl<T: Device> Deref for User<T> {      }  } +impl<T: Device> ops::DerefMut for User<T> { +    fn deref_mut(&mut self) -> &mut T { +        &mut self.device +    } +} +  impl<T: Device> GenerateOtp for User<T> {      fn get_hotp_code(&self, slot: u8) -> Result<String, Error> {          result_from_string(unsafe { @@ -246,7 +252,7 @@ impl<T: Device> AuthenticatedDevice<T> for User<T> {      }  } -impl<T: Device> Deref for Admin<T> { +impl<T: Device> ops::Deref for Admin<T> {      type Target = T;      fn deref(&self) -> &Self::Target { @@ -254,6 +260,12 @@ impl<T: Device> Deref for Admin<T> {      }  } +impl<T: Device> ops::DerefMut for Admin<T> { +    fn deref_mut(&mut self) -> &mut T { +        &mut self.device +    } +} +  impl<T: Device> Admin<T> {      /// Forgets the user authentication and returns an unauthenticated device.  This method      /// consumes the authenticated device.  It does not perform any actual commands on the | 
