fix otp tests

This commit is contained in:
Bilal Elmoussaoui 2021-01-22 21:51:33 +01:00
parent fac2ae8ad5
commit 5181f5c2d1
2 changed files with 10 additions and 10 deletions

View File

@ -285,7 +285,7 @@ impl Account {
OTPMethod::Steam => 1,
};
let label = match otp::generate_hotp(
let label = match otp::hotp(
&self.token(),
counter,
provider.algorithm().into(),

View File

@ -35,7 +35,7 @@ fn encode_digest(digest: &[u8], digits: u32) -> Result<u32> {
/// Performs the [HMAC-based One-time Password Algorithm](http://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm)
/// (HOTP) given an RFC4648 base32 encoded secret, and an integer counter.
pub(crate) fn generate_hotp(
pub(crate) fn hotp(
secret: &str,
counter: u64,
algorithm: hmac::Algorithm,
@ -59,29 +59,29 @@ pub(crate) fn format(code: u32, digits: usize) -> String {
#[cfg(test)]
mod tests {
use super::{format, generate_hotp};
use super::{format, hmac, hotp};
#[test]
fn hotp() {
fn test_htop() {
let algorithm = hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY;
let digits: u32 = 6;
assert_eq!(
generate_hotp("BASE32SECRET3232", 0, algorithm, digits).unwrap(),
hotp("BASE32SECRET3232", 0, algorithm, digits).unwrap(),
260182
);
assert_eq!(
generate_hotp("BASE32SECRET3232", 1, algorithm, digits).unwrap(),
hotp("BASE32SECRET3232", 1, algorithm, digits).unwrap(),
55283
);
assert_eq!(
generate_hotp("BASE32SECRET3232", 1401, algorithm, digits).unwrap(),
hotp("BASE32SECRET3232", 1401, algorithm, digits).unwrap(),
316439
);
}
#[test]
fn hotp() {
assert_eq!(format(012345, 6).unwrap(), "012 345");
assert_eq!(format(01234, 5).unwrap(), "01234");
fn test_otp_format() {
assert_eq!(format(012345, 6), "012 345");
assert_eq!(format(01234, 5), "01234");
}
}