Skip to content

Commit 17fd3c1

Browse files
committed
make all tests passing (still need to add string tests for the new struct)
1 parent 56bd72e commit 17fd3c1

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
//! let hotp_str = HOTP::default_from_utf8(secret);
1818
//! // Get an otp with the given counter
1919
//! let otp_from_str = hotp_str.get_otp(counter);
20-
//! println!("The otp from hotp_str: {}", otp_from_str);
20+
//! println!("The otp from hotp_str: {}", otp_from_str.as_string());
2121
//!
2222
//! // Alternatively, get a HOTP instance with a '&[u8]' secret
2323
//! let hotp_bytes = HOTP::new(secret.as_bytes(), 6);
2424
//! // Get an otp with the given counter
2525
//! let otp_from_bytes = hotp_bytes.get_otp(counter);
26-
//! println!("The otp from hotp_bytes: {}", otp_from_bytes);
26+
//! println!("The otp from hotp_bytes: {}", otp_from_bytes.as_string());
2727
//! }
2828
//! ```
2929
//!
@@ -44,7 +44,7 @@
4444
//! let totp_sha1_str = TOTP::default_from_utf8(secret);
4545
//! // Get an otp with the given counter and elapsed seconds
4646
//! let otp_sha1 = totp_sha1_str.get_otp(elapsed_seconds);
47-
//! println!("The otp from totp_sha1_str: {}", otp_sha1);
47+
//! println!("The otp from totp_sha1_str: {}", otp_sha1.as_string());
4848
//!
4949
//! // Alternatively get a TOTP instance with an '&[u8]' secret
5050
//! // and different digest (Sha256 or Sha512)
@@ -59,7 +59,7 @@
5959
//! elapsed_seconds,
6060
//! 0, // Start time at unix epoch
6161
//! );
62-
//! println!("The otp from totp_sha256_bytes: {}", otp_sha256);
62+
//! println!("The otp from totp_sha256_bytes: {}", otp_sha256.as_string());
6363
//! }
6464
//! ```
6565
//!

tests/hotp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ static SECRET_BASE32: &str = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ";
88
/// the Secret Key as a byte array
99
fn run_rfc_test_bytes(count: u64) -> u32 {
1010
let hotp = HOTP::new(SECRET_BYTES, 6);
11-
hotp.get_otp(count)
11+
hotp.get_otp(count).as_u32()
1212
}
1313

1414
/// Generic test method to get the HOTP code with
1515
/// the Secret Key as a string literal
1616
fn run_rfc_test_utf8(count: u64) -> u32 {
1717
let hotp = HOTP::default_from_utf8(SECRET_UTF8);
18-
hotp.get_otp(count)
18+
hotp.get_otp(count).as_u32()
1919
}
2020

2121
/// Generic test method to get the HOTP code with
2222
/// the Secret Key as a base32-encoded string
2323
fn run_rfc_test_base32(count: u64) -> u32 {
2424
let hotp = HOTP::default_from_base32(SECRET_BASE32);
25-
hotp.get_otp(count)
25+
hotp.get_otp(count).as_u32()
2626
}
2727

2828
// All RFC4226 Test Cases (All SHA1)

tests/totp.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static SECRET_BASE32_SHA512: &str = "GEZDGNBVGY3TQOJQGEZ\
2525
/// the SHA1 Secret Key as a byte array
2626
fn run_rfc_test_bytes(time: u64) -> u32 {
2727
let totp = TOTP::new(SECRET_BYTES_SHA1, MacDigest::SHA1, 8, 30);
28-
totp.get_otp(time)
28+
totp.get_otp(time).as_u32()
2929
}
3030

3131
/// Generic test method to get the TOTP code with
@@ -37,14 +37,14 @@ fn run_rfc_test_bytes_with_digest(time: u64, digest: MacDigest) -> u32 {
3737
SECRET_BYTES_SHA512
3838
};
3939
let totp = TOTP::new(secret, digest, 8, 30);
40-
totp.get_otp(time)
40+
totp.get_otp(time).as_u32()
4141
}
4242

4343
/// Generic test method to get the TOTP code with
4444
/// the SHA1 Secret Key as a string literal
4545
fn run_rfc_test_utf8(time: u64) -> u32 {
4646
let totp = TOTP::new_from_utf8(SECRET_UTF8_SHA1, MacDigest::SHA1, 8, 30);
47-
totp.get_otp(time)
47+
totp.get_otp(time).as_u32()
4848
}
4949

5050
/// Generic test method to get the TOTP code with
@@ -56,14 +56,14 @@ fn run_rfc_test_utf8_with_digest(time: u64, digest: MacDigest) -> u32 {
5656
SECRET_UTF8_SHA512
5757
};
5858
let totp = TOTP::new_from_utf8(secret, digest, 8, 30);
59-
totp.get_otp(time)
59+
totp.get_otp(time).as_u32()
6060
}
6161

6262
/// Generic test method to get the TOTP code with
6363
/// the SHA1 Secret Key as a base32-encoded string
6464
fn run_rfc_test_base32(time: u64) -> u32 {
6565
let totp = TOTP::new_from_base32(SECRET_BASE32_SHA1, MacDigest::SHA1, 8, 30);
66-
totp.get_otp(time)
66+
totp.get_otp(time).as_u32()
6767
}
6868

6969
/// Generic test method to get the TOTP code with
@@ -75,7 +75,7 @@ fn run_rfc_test_base32_with_digest(time: u64, digest: MacDigest) -> u32 {
7575
SECRET_BASE32_SHA512
7676
};
7777
let totp = TOTP::new_from_base32(secret, digest, 8, 30);
78-
totp.get_otp(time)
78+
totp.get_otp(time).as_u32()
7979
}
8080

8181
// All SHA-1 Tests for TOTP from rfc6238

0 commit comments

Comments
 (0)