summaryrefslogtreecommitdiff
path: root/src/device.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/device.rs b/src/device.rs
index 6c1a957..ce45a50 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -99,13 +99,33 @@ pub trait Device {
///
/// The time is used for TOTP generation (see [`get_totp_code`][]).
///
+ /// # Example
+ ///
+ /// ```ignore
+ /// extern crate chrono;
+ ///
+ /// use chrono::Utc;
+ /// use nitrokey::Device;
+ /// # use nitrokey::CommandError;
+ ///
+ /// # fn try_main() -> Result<(), CommandError> {
+ /// let device = nitrokey::connect()?;
+ /// let time = Utc::now().timestamp();
+ /// if time < 0 {
+ /// println!("Timestamps before 1970-01-01 are not supported!");
+ /// } else {
+ /// device.set_time(time as u64);
+ /// }
+ /// # Ok(())
+ /// # }
+ /// ```
+ ///
/// # Errors
///
/// - [`Timestamp`][] if the time could not be set
///
/// [`get_totp_code`]: trait.ProvideOtp.html#method.get_totp_code
/// [`Timestamp`]: enum.CommandError.html#variant.Timestamp
- // TODO: example
fn set_time(&self, time: u64) -> CommandStatus {
unsafe { CommandStatus::from(nitrokey_sys::NK_totp_set_time(time)) }
}