aboutsummaryrefslogtreecommitdiff
path: root/src/device.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/device.rs b/src/device.rs
index bc48cd2..df76e12 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -767,6 +767,44 @@ impl Storage {
}
}
+ /// Enables the firmware update mode.
+ ///
+ /// During firmware update mode, the Nitrokey can no longer be accessed using HID commands.
+ /// To resume normal operation, run `dfu-programmer at32uc3a3256s launch`. In order to enter
+ /// the firmware update mode, you need the update password that can be changed using the
+ /// [`change_update_pin`][] method.
+ ///
+ /// # Errors
+ ///
+ /// - [`InvalidString`][] if one of the provided passwords contains a null byte
+ /// - [`WrongPassword`][] if the current update password is wrong
+ ///
+ /// # Example
+ ///
+ /// ```no_run
+ /// # use nitrokey::CommandError;
+ ///
+ /// # fn try_main() -> Result<(), CommandError> {
+ /// let device = nitrokey::Storage::connect()?;
+ /// match device.enable_firmware_update("12345678") {
+ /// Ok(()) => println!("Nitrokey entered update mode."),
+ /// Err(err) => println!("Could not enter update mode: {}", err),
+ /// };
+ /// # Ok(())
+ /// # }
+ /// ```
+ ///
+ /// [`InvalidString`]: enum.CommandError.html#variant.InvalidString
+ /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword
+ pub fn enable_firmware_update(&self, update_pin: &str) -> Result<(), CommandError> {
+ let update_pin_string = get_cstring(update_pin)?;
+ unsafe {
+ get_command_result(nitrokey_sys::NK_enable_firmware_update(
+ update_pin_string.as_ptr(),
+ ))
+ }
+ }
+
/// Enables the encrypted storage volume.
///
/// Once the encrypted volume is enabled, it is presented to the operating system as a block