This commit is contained in:
2020-01-30 21:02:25 +08:00
parent 7dac915696
commit 9b6409e134
2 changed files with 24 additions and 0 deletions

11
totp/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "totp"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
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"

13
totp/src/main.rs Normal file
View File

@@ -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));
}