Skip to content

Commit 5cb7652

Browse files
committed
Changing the name of some methods
1 parent 874dba8 commit 5cb7652

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

src/hotp.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl HOTP {
4343
}
4444
}
4545

46-
/// Creates a new HOTP instance from a utf8-encoded string secret and the number of digits.
46+
/// Creates a new HOTP instance from an utf8-encoded string secret and the number of digits.
4747
pub fn new_from_utf8(secret: &str, digits: u32) -> Self {
4848
HOTP::new(secret.as_bytes(), digits)
4949
}
@@ -57,16 +57,22 @@ impl HOTP {
5757
HOTP::new(&decoded, digits)
5858
}
5959

60-
/// Creates a new HOTP instance from a utf8-encoded string secret and a default number of 6 digits.
61-
pub fn from_utf8(secret: &str) -> Self {
60+
/// Creates a new HOTP instance from a byte-array representation of the secret and
61+
/// a default number of 6 digits.
62+
pub fn default_from_secret(secret: &[u8]) -> Self {
63+
HOTP::new(secret, 6)
64+
}
65+
66+
/// Creates a new HOTP instance from an utf8-encoded string secret and a default number of 6 digits.
67+
pub fn default_from_utf8(secret: &str) -> Self {
6268
HOTP::new_from_utf8(secret, 6)
6369
}
6470

6571
/// Creates a new HOTP instance from a base32-encoded string secret and a default number of 6 digits.
6672
///
6773
/// # Panics
6874
/// This method panics if the provided string is not correctly base32 encoded.
69-
pub fn from_base32(secret: &str) -> Self {
75+
pub fn default_from_base32(secret: &str) -> Self {
7076
HOTP::new_from_base32(secret, 6)
7177
}
7278
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! let secret = "secret";
1515
//! let counter = 0;
1616
//! // Get a HOTP instance with a '&str' secret
17-
//! let hotp_str = HOTP::from_utf8(secret);
17+
//! 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);
2020
//! println!("The otp from hotp_str: {}", otp_from_str);
@@ -41,7 +41,7 @@
4141
//! .expect("Error getting time")
4242
//! .as_secs();
4343
//! // Get a TOTP instance with an '&str' secret and default SHA1 Digest
44-
//! let totp_sha1_str = TOTP::from_utf8(secret);
44+
//! 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);
4747
//! println!("The otp from totp_sha1_str: {}", otp_sha1);
@@ -52,7 +52,7 @@
5252
//! secret.as_bytes(),
5353
//! MacDigest::SHA256, // SHA256 algorithm
5454
//! 8, // 8 digits
55-
//! 60 // 60 seconds interval
55+
//! 60 // 60-second interval
5656
//! );
5757
//! // Get an otp with the given counter, time and other custom params
5858
//! let otp_sha256 = totp_sha256_bytes.get_otp_with_custom_time_start(

src/totp.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct TOTP {
1919
/// The secret key used in the HMAC process.
2020
///
2121
/// Often given as a Base32 key, which can be conveniently initialized using
22-
/// [`TOTP::from_base32`] constructors.
22+
/// [`TOTP::default_from_base32`] constructors.
2323
secret: Vec<u8>,
2424

2525
/// The digest to use in the HMAC process.
@@ -71,31 +71,31 @@ impl TOTP {
7171
///
7272
/// Defaults to using [`MacDigest::SHA1`] as the digest for HMAC operations,
7373
/// 6 digits and a 30 seconds period.
74-
pub fn from_secret(secret: &[u8]) -> Self {
75-
TOTP::from_secret_with_digest(secret, MacDigest::SHA1)
74+
pub fn default_from_secret(secret: &[u8]) -> Self {
75+
TOTP::default_from_secret_with_digest(secret, MacDigest::SHA1)
7676
}
7777

7878
/// Creates a new TOTP instance with a byte-array representation of the secret and
7979
/// a digest algorithm.
8080
///
8181
/// Defaults to using 6 digits and a 30 seconds period.
82-
pub fn from_secret_with_digest(secret: &[u8], mac_digest: MacDigest) -> Self {
82+
pub fn default_from_secret_with_digest(secret: &[u8], mac_digest: MacDigest) -> Self {
8383
TOTP::new(secret, mac_digest, 6, 30)
8484
}
8585

8686
/// Creates a new TOTP instance with an utf8 representation of the secret.
8787
///
8888
/// Defaults to using [`MacDigest::SHA1`] as the digest for HMAC operations,
8989
/// 6 digits and a 30 seconds period.
90-
pub fn from_utf8(secret: &str) -> Self {
91-
TOTP::from_utf8_with_digest(secret, MacDigest::SHA1)
90+
pub fn default_from_utf8(secret: &str) -> Self {
91+
TOTP::default_from_utf8_with_digest(secret, MacDigest::SHA1)
9292
}
9393

9494
/// Creates a new TOTP instance with an utf8 representation of the secret and
9595
/// a digest algorithm.
9696
///
9797
/// Defaults to using 6 digits and a 30 seconds period.
98-
pub fn from_utf8_with_digest(secret: &str, mac_digest: MacDigest) -> Self {
98+
pub fn default_from_utf8_with_digest(secret: &str, mac_digest: MacDigest) -> Self {
9999
TOTP::new_from_utf8(secret, mac_digest, 6, 30)
100100
}
101101

@@ -106,8 +106,8 @@ impl TOTP {
106106
///
107107
/// # Panics
108108
/// This method panics if the provided string is not correctly base32 encoded.
109-
pub fn from_base32(secret: &str) -> Self {
110-
TOTP::from_base32_with_digest(secret, MacDigest::SHA1)
109+
pub fn default_from_base32(secret: &str) -> Self {
110+
TOTP::default_from_base32_with_digest(secret, MacDigest::SHA1)
111111
}
112112

113113
/// Creates a new TOTP instance with a base32 representation of the secret and
@@ -117,7 +117,7 @@ impl TOTP {
117117
///
118118
/// # Panics
119119
/// This method panics if the provided string is not correctly base32 encoded.
120-
pub fn from_base32_with_digest(secret: &str, mac_digest: MacDigest) -> Self {
120+
pub fn default_from_base32_with_digest(secret: &str, mac_digest: MacDigest) -> Self {
121121
TOTP::new_from_base32(secret, mac_digest, 6, 30)
122122
}
123123
}

tests/hotp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ fn run_rfc_test_bytes(count: u64) -> u32 {
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 {
17-
let hotp = HOTP::from_utf8(SECRET_UTF8);
17+
let hotp = HOTP::default_from_utf8(SECRET_UTF8);
1818
hotp.get_otp(count)
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 {
24-
let hotp = HOTP::from_base32(SECRET_BASE32);
24+
let hotp = HOTP::default_from_base32(SECRET_BASE32);
2525
hotp.get_otp(count)
2626
}
2727

0 commit comments

Comments
 (0)