diff --git a/Cargo.toml b/Cargo.toml index c22368c..f8fad4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "totp-rs" -version = "0.2.1" +version = "0.2.2" authors = ["Cleo Rebert "] edition = "2018" readme = "README.md" diff --git a/README.md b/README.md index ec71a50..425f459 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,16 @@ Add it to your `Cargo.toml`: [dependencies] totp-rs = "~0.2" ``` +You can then do something like: +```Rust +use totp_rs::{TOTP, Algorithm}; +use std::time::SystemTime; + +let username = "example".to_string(); +let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "supersecret".to_string().into_bytes()); +let time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?.as_secs(); +let url = totp.get_url(format!("account:{}", username), "my-org.com".to_string()); +println!("{}", url); +let token = totp.generate(time); +println!("{}", token); +``` diff --git a/src/lib.rs b/src/lib.rs index b331f19..039ee93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,19 @@ //! This library permits the creation of 2FA authentification tokens per TOTP, the verification of said tokens, with configurable time skew, validity time of each token, algorithm and number of digits! +//! +//! # Examples +//! +//! ``` +//! use totp_rs::{TOTP, Algorithm}; +//! use std::time::SystemTime; +//! +//! let username = "example".to_string(); +//! let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "supersecret".to_string().into_bytes()); +//! let time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?.as_secs(); +//! let url = totp.get_url(format!("account:{}", username), "my-org.com".to_string()); +//! println!("{}", url); +//! let token = totp.generate(time); +//! println!("{}", token); +//! ``` use base32; use byteorder::{BigEndian, ReadBytesExt}; @@ -113,6 +128,12 @@ impl TOTP { } /// Will return a qrcode to automatically add a TOTP as a base64 string + /// + /// # Errors + /// + /// This will return an error in case the URL gets too long to encode into a QR code + /// + /// It will also return an error in case it can't encode the qr into a png. This shouldn't happen unless either the qrcode library returns malformed data, or the image library doesn't encode the data correctly pub fn get_qr( &self, label: String,