chore(FLOW-2123): Add examples Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
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 <cleo.rebert@gmail.com>"]
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]