aboutsummaryrefslogtreecommitdiff
path: root/src/otp.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-22 09:11:27 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-05-22 11:12:12 +0200
commitea00d06fc614c632a4c7250ef0c769705ed8c1c3 (patch)
tree804332537c8749239b16072a21452d85eab8dcde /src/otp.rs
parent2c31912bd2f8731c146da6640e28896c9de6286a (diff)
downloadnitrokey-rs-ea00d06fc614c632a4c7250ef0c769705ed8c1c3.tar.gz
nitrokey-rs-ea00d06fc614c632a4c7250ef0c769705ed8c1c3.tar.bz2
Add an example for setting the current time
The example uses the chrono crate and can therefore not be executed, but at least it shows how to set the Nitrokey device to the current time.
Diffstat (limited to 'src/otp.rs')
-rw-r--r--src/otp.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/otp.rs b/src/otp.rs
index c951d5f..0451c5f 100644
--- a/src/otp.rs
+++ b/src/otp.rs
@@ -256,14 +256,22 @@ pub trait GenerateOtp {
///
/// # Example
///
- /// ```no_run
+ /// ```ignore
+ /// extern crate chrono;
+ ///
/// use nitrokey::GenerateOtp;
/// # use nitrokey::CommandError;
///
/// # fn try_main() -> Result<(), CommandError> {
/// let device = nitrokey::connect()?;
- /// let code = device.get_totp_code(1)?;
- /// println!("Generated TOTP code on slot 1: {:?}", code);
+ /// let time = Utc::now().timestamp();
+ /// if time < 0 {
+ /// println!("Timestamps before 1970-01-01 are not supported!");
+ /// } else {
+ /// device.set_time(time as u64);
+ /// let code = device.get_totp_code(1)?;
+ /// println!("Generated TOTP code on slot 1: {:?}", code);
+ /// }
/// # Ok(())
/// # }
/// ```