diff --git a/Cargo.toml b/Cargo.toml index 605bebf..377f53d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "totp-rs" -version = "4.0.0" +version = "4.1.0" authors = ["Cleo Rebert "] rust-version = "1.59" edition = "2021" diff --git a/README.md b/README.md index ab8663f..dcccbe0 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Add support for Steam TOTP tokens. 4. [Enable otpauth url support](#with-otpauth-url-support) 5. [Enable gen_secret support](#with-gensecret) 6. [With RFC-6238 compliant default](#with-rfc-6238-compliant-default) +7. [New TOTP from steam secret](#new-totp-from-steam-secret) ### Understanding Secret --- @@ -216,3 +217,24 @@ fn main() { println!("code: {}", code); } ``` + +### New TOTP from steam secret +--- +Add it to your `Cargo.toml`: +```toml +[dependencies.totp-rs] +version = "^4.1" +features = ["qr"] +``` +You can then do something like: +```Rust +use totp_rs::{TOTP, Secret}; + +fn main() { + let totp = TOTP::new_steam( + Secret::Encoded("KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ".to_string()).to_bytes().unwrap(), + ).unwrap(); + let code = totp.get_qr()?; + println!("{}", code); +} +``` \ No newline at end of file diff --git a/examples/steam.rs b/examples/steam.rs new file mode 100644 index 0000000..45536b6 --- /dev/null +++ b/examples/steam.rs @@ -0,0 +1,46 @@ +#[cfg(feature = "steam")] +use totp_rs::{Secret, TOTP}; + +#[cfg(feature = "steam")] +#[cfg(feature = "otpauth")] +fn main() { + // create TOTP from base32 secret + let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG")); + let totp_b32 = TOTP::new_steam( + secret_b32.to_bytes().unwrap(), + "user-account".to_string(), + ); + + println!( + "base32 {} ; raw {}", + secret_b32, + secret_b32.to_raw().unwrap() + ); + println!( + "code from base32:\t{}", + totp_b32.generate_current().unwrap() + ); +} + +#[cfg(feature = "steam")] +#[cfg(not(feature = "otpauth"))] +fn main() { + // create TOTP from base32 secret + let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG")); + let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap()); + + println!( + "base32 {} ; raw {}", + secret_b32, + secret_b32.to_raw().unwrap() + ); + println!( + "code from base32:\t{}", + totp_b32.generate_current().unwrap() + ); +} + +#[cfg(not(feature = "steam"))] +fn main() { + +} \ No newline at end of file diff --git a/src/custom_providers.rs b/src/custom_providers.rs index 780699d..1e88a0c 100644 --- a/src/custom_providers.rs +++ b/src/custom_providers.rs @@ -44,6 +44,7 @@ impl TOTP { #[cfg(all(test, feature = "steam"))] mod test { + #[cfg(feature = "otpauth")] use super::*; #[test]