2023-01-03 12:49:47 -05:00
#[ cfg(feature = " steam " ) ]
2023-04-29 13:39:17 -04:00
use crate ::{ Algorithm , TOTP , LabeledTOTP } ;
2023-01-03 12:49:47 -05:00
#[ cfg(feature = " steam " ) ]
2023-04-29 13:39:17 -04:00
impl LabeledTOTP {
2023-01-03 12:49:47 -05:00
/// 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
2023-04-29 13:39:17 -04:00
/// use totp_rs::{Secret, LabeledTOTP};
2023-01-06 05:30:24 -05:00
/// let secret = Secret::Encoded("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".into());
2023-04-29 13:39:17 -04:00
/// let totp = LabeledTOTP::new_steam(secret.to_bytes().unwrap(), "username".into());
2023-01-03 12:49:47 -05:00
/// ```
2023-04-29 13:39:17 -04:00
pub fn new_steam ( secret : Vec < u8 > , account_name : String ) -> Self {
2023-01-03 12:49:47 -05:00
Self ::new_unchecked (
2023-04-29 13:39:17 -04:00
TOTP ::new_unchecked (
Algorithm ::Steam ,
5 ,
1 ,
30 ,
secret ,
) ,
" Steam " . to_owned ( ) ,
2023-01-05 11:14:06 -05:00
account_name ,
2023-01-03 12:49:47 -05:00
)
}
}
2023-01-06 05:30:24 -05:00
#[ cfg(all(test, feature = " steam " )) ]
mod test {
2023-01-06 08:35:18 -05:00
#[ cfg(feature = " otpauth " ) ]
2023-01-06 05:30:24 -05:00
use super ::* ;
#[ test ]
#[ cfg(feature = " otpauth " ) ]
fn get_url_steam ( ) {
2023-04-29 13:39:17 -04:00
let totp = LabeledTOTP ::new_steam ( " TestSecretSuperSecret " . into ( ) , " constantoine " . into ( ) ) ;
2023-01-06 05:30:24 -05:00
let url = totp . get_url ( ) ;
2023-01-12 08:22:12 -05:00
assert_eq! ( url . as_str ( ) , " otpauth://steam/Steam:constantoine?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=5&algorithm=SHA1&issuer=Steam " ) ;
2023-01-06 05:30:24 -05:00
}
2023-01-12 08:22:12 -05:00
}