diff --git a/README.md b/README.md index bf7d2ce..a9a91b1 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ git = "https://github.com/TimDumol/rust-otp" ```rust // first argument is the secret, second argument is the counter -assert_eq!(make_hotp("base32secret3232".to_ascii(), 0), Some(260182)); +assert_eq!(make_hotp("base32secret3232".to_ascii_uppercase().ok(), 0), Some(260182)); // first argument is the secret, followed by the time step in seconds (Google // Authenticator uses a time step of 30), and then the skew in seconds // (often used when calculating HOTPs for a sequence of consecutive // time intervals, to deal with potential latency and desynchronization). -assert_eq!(make_totp("base32secret3232".to_ascii(), 30, 0), Some(260182)); // true on Unix epoch +assert_eq!(make_totp("base32secret3232".to_ascii_uppercase(), 30, 0).ok(), Some(260182)); // true on Unix epoch ``` diff --git a/src/lib.rs b/src/lib.rs index 0d7445c..28d39be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ pub fn make_totp(secret: &str, time_step: u64, skew: i64) -> Result #[cfg(test)] mod tests { - use super::{make_hotp, make_totp_helper}; + use super::{make_hotp, make_totp, make_totp_helper, Error}; #[test] fn hotp() { @@ -86,5 +86,11 @@ mod tests { assert_eq!(make_totp_helper("BASE32SECRET3232", 3600, 0, 7).unwrap(), 260182); assert_eq!(make_totp_helper("BASE32SECRET3232", 30, 0, 35).unwrap(), 55283); assert_eq!(make_totp_helper("BASE32SECRET3232", 1, -2, 1403).unwrap(), 316439); + assert!( + matches!( + make_totp("base32secret3232", 30, 0).unwrap_err(), + Error::InvalidSecret{..} + ) + ); } }