From 9b6409e134488a4322df5e877b918b1df6480192 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 30 Jan 2020 21:02:25 +0800 Subject: [PATCH] add totp --- totp/Cargo.toml | 11 +++++++++++ totp/src/main.rs | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 totp/Cargo.toml create mode 100644 totp/src/main.rs diff --git a/totp/Cargo.toml b/totp/Cargo.toml new file mode 100644 index 0000000..df37d0a --- /dev/null +++ b/totp/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "totp" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +time = "0.1.42" +otpauth = "0.2.7" diff --git a/totp/src/main.rs b/totp/src/main.rs new file mode 100644 index 0000000..5eedef9 --- /dev/null +++ b/totp/src/main.rs @@ -0,0 +1,13 @@ +extern crate otpauth; +extern crate time; + +use otpauth::TOTP; + +fn main() { + let auth = TOTP::new("python"); + let timestamp1 = time::now().to_timespec().sec as usize; + let code = auth.generate(30, timestamp1); + let timestamp2 = time::now().to_timespec().sec as usize; + println!("code: {}", code); + assert_eq!(true, auth.verify(code, 30, timestamp2)); +} \ No newline at end of file