From 5181f5c2d1bcc949d1cc2b75f1b1a31e97958186 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 22 Jan 2021 21:51:33 +0100 Subject: [PATCH] fix otp tests --- src/models/account.rs | 2 +- src/models/otp.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/models/account.rs b/src/models/account.rs index cd3e09d..8c27a31 100644 --- a/src/models/account.rs +++ b/src/models/account.rs @@ -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(), diff --git a/src/models/otp.rs b/src/models/otp.rs index 58b5f9c..ebe4531 100644 --- a/src/models/otp.rs +++ b/src/models/otp.rs @@ -35,7 +35,7 @@ fn encode_digest(digest: &[u8], digits: u32) -> Result { /// 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"); } }