chore(FLOW-2123): Add examples
Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>
This commit is contained in:
parent
cc1474a7d8
commit
d54bd9e447
|
@ -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"
|
||||
|
|
22
README.md
22
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);
|
||||
}
|
||||
```
|
|
@ -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() {
|
||||
|
||||
}
|
|
@ -44,6 +44,7 @@ impl TOTP {
|
|||
|
||||
#[cfg(all(test, feature = "steam"))]
|
||||
mod test {
|
||||
#[cfg(feature = "otpauth")]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue