aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-31 11:07:50 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-31 12:10:38 +0100
commitad76653b3be57c0cfd31c8056a8d68537034324e (patch)
tree32302d740faa9403426cc38e993402ff84edd498 /src
parent9a38dd456804035f88aa7c4042066e4cde67c04c (diff)
downloadnitrokey-rs-ad76653b3be57c0cfd31c8056a8d68537034324e.tar.gz
nitrokey-rs-ad76653b3be57c0cfd31c8056a8d68537034324e.tar.bz2
Add set_encrypted_volume_mode method to Storage
Previously, we considered this command as unsupported as it only was available with firmware version 0.49. But as discussed in nitrocli issue 80 [0], it will probably be re-enabled in future firmware versions. Therefore this patch adds the set_encrypted_volume_mode to Storage. [0] https://github.com/d-e-s-o/nitrocli/issues/80
Diffstat (limited to 'src')
-rw-r--r--src/device.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/device.rs b/src/device.rs
index d199d9a..c985802 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -1142,7 +1142,7 @@ impl Storage {
///
/// # fn try_main() -> Result<(), Error> {
/// let device = nitrokey::Storage::connect()?;
- /// match device.set_unencrypted_volume_mode("123456", VolumeMode::ReadWrite) {
+ /// match device.set_unencrypted_volume_mode("12345678", VolumeMode::ReadWrite) {
/// Ok(()) => println!("Set the unencrypted volume to read-write mode."),
/// Err(err) => eprintln!("Could not set the unencrypted volume to read-write mode: {}", err),
/// };
@@ -1169,6 +1169,51 @@ impl Storage {
get_command_result(result)
}
+ /// Sets the access mode of the encrypted volume.
+ ///
+ /// This command will reconnect the encrypted volume so buffers should be flushed before
+ /// calling it. It is only available in firmware version 0.49.
+ ///
+ /// # Errors
+ ///
+ /// - [`InvalidString`][] if the provided password contains a null byte
+ /// - [`WrongPassword`][] if the provided admin password is wrong
+ ///
+ /// # Example
+ ///
+ /// ```no_run
+ /// # use nitrokey::Error;
+ /// use nitrokey::VolumeMode;
+ ///
+ /// # fn try_main() -> Result<(), Error> {
+ /// let device = nitrokey::Storage::connect()?;
+ /// match device.set_encrypted_volume_mode("12345678", VolumeMode::ReadWrite) {
+ /// Ok(()) => println!("Set the encrypted volume to read-write mode."),
+ /// Err(err) => eprintln!("Could not set the encrypted volume to read-write mode: {}", err),
+ /// };
+ /// # Ok(())
+ /// # }
+ /// ```
+ ///
+ /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString
+ /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword
+ pub fn set_encrypted_volume_mode(
+ &self,
+ admin_pin: &str,
+ mode: VolumeMode,
+ ) -> Result<(), Error> {
+ let admin_pin = get_cstring(admin_pin)?;
+ let result = match mode {
+ VolumeMode::ReadOnly => unsafe {
+ nitrokey_sys::NK_set_encrypted_read_only(admin_pin.as_ptr())
+ },
+ VolumeMode::ReadWrite => unsafe {
+ nitrokey_sys::NK_set_encrypted_read_write(admin_pin.as_ptr())
+ },
+ };
+ get_command_result(result)
+ }
+
/// Returns the status of the connected storage device.
///
/// # Example