Add TOTP::new_steam as custom provider
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
diff --git a/src/custom_providers.rs b/src/custom_providers.rs
new file mode 100644
index 0000000..7da52e7
--- /dev/null
+++ b/src/custom_providers.rs
@@ -0,0 +1,45 @@
+#[cfg(feature = "steam")]
+use crate::{Algorithm, TOTP};
+
+#[cfg(feature = "steam")]
+impl TOTP {
+ #[cfg(feature = "otpauth")]
+ /// Will create a new instance of TOTP using the Steam algorithm with given parameters. See [the doc](struct.TOTP.html#fields) for reference as to how to choose those values
+ ///
+ /// # Description
+ /// * `secret`: expect a non-encoded value, to pass in base32 string use `Secret::Encoded(String)`
+ ///
+ /// ```rust
+ /// use totp_rs::{Secret, TOTP};
+ /// let secret = Secret::Encoded("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".to_string());
+ /// let totp = TOTP::new_steam(secret.to_bytes().unwrap(), Some("username".to_string()));
+ /// ```
+ pub fn new_steam(secret: Vec<u8>, account_name: Option<String>) -> TOTP {
+ Self::new_unchecked(
+ Algorithm::Steam,
+ 5,
+ 1,
+ 30,
+ secret,
+ Some("Steam".into()),
+ account_name
+ .map(|n| format!("Steam:{}", n))
+ .unwrap_or_else(|| "".into()),
+ )
+ }
+
+ #[cfg(not(feature = "otpauth"))]
+ /// Will create a new instance of TOTP using the Steam algorithm with given parameters. See [the doc](struct.TOTP.html#fields) for reference as to how to choose those values
+ ///
+ /// # Description
+ /// * `secret`: expect a non-encoded value, to pass in base32 string use `Secret::Encoded(String)`
+ ///
+ /// ```rust
+ /// use totp_rs::{Secret, TOTP};
+ /// let secret = Secret::Encoded("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".to_string());
+ /// let totp = TOTP::new_steam(secret.to_bytes().unwrap());
+ /// ```
+ pub fn new_steam(secret: Vec<u8>) -> TOTP {
+ Self::new_unchecked(Algorithm::Steam, 5, 1, 30, secret)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index fe368f4..82cecca 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,6 +47,7 @@
//! # }
//! ```
+mod custom_providers;
mod rfc;
mod secret;
mod url_error;