Better doc with examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
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 <cleo.rebert@gmail.com>"]
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,