@@ -40,6 +40,8 @@ pub struct TOTP {
4040
4141// All initializer implementations for the [`TOTP`] struct
4242impl TOTP {
43+ /// Generates a new TOTP instance from a byte array representation of the secret,
44+ /// a digest algorithm, a number of digits and a period in seconds.
4345 pub fn new ( secret : & [ u8 ] , mac_digest : MacDigest , digits : u32 , period : u64 ) -> Self {
4446 TOTP {
4547 secret : secret. to_vec ( ) ,
@@ -49,64 +51,69 @@ impl TOTP {
4951 }
5052 }
5153
54+ /// Generates a new TOTP instance from an utf8 representation of the secret,
55+ /// a digest algorithm, a number of digits and a period in seconds.
5256 pub fn new_from_utf8 ( secret : & str , mac_digest : MacDigest , digits : u32 , period : u64 ) -> Self {
5357 TOTP :: new ( secret. as_bytes ( ) , mac_digest, digits, period)
5458 }
5559
60+ /// Generates a new TOTP instance from a base32 representation of the secret,
61+ /// a digest algorithm, a number of digits and a period in seconds.
62+ ///
63+ /// # Panics
64+ /// This method panics if the provided string is not correctly base32 encoded.
5665 pub fn new_from_base32 ( secret : & str , mac_digest : MacDigest , digits : u32 , period : u64 ) -> Self {
5766 let decoded = base32_decode ( secret) . expect ( "Failed to decode base32 string" ) ;
5867 TOTP :: new ( & decoded, mac_digest, digits, period)
5968 }
6069
61- /// Creates a new TOTP instance with a byte-array representation
62- /// of the secret
70+ /// Creates a new TOTP instance with a byte-array representation of the secret.
6371 ///
64- /// Defaults to using [`MacDigest::SHA1`] as the digest for HMAC
65- /// operations .
72+ /// Defaults to using [`MacDigest::SHA1`] as the digest for HMAC operations,
73+ /// 6 digits and a 30 seconds period .
6674 pub fn from_secret ( secret : & [ u8 ] ) -> Self {
6775 TOTP :: from_secret_with_digest ( secret, MacDigest :: SHA1 )
6876 }
6977
70- /// Creates a new TOTP instance with a byte-array representation
71- /// of the secret and a specific digest for HMAC operations
78+ /// Creates a new TOTP instance with a byte-array representation of the secret and
79+ /// a digest algorithm.
7280 ///
73- /// Allows for non-SHA1 algorithms to be used with TOTP generation
81+ /// Defaults to using 6 digits and a 30 seconds period.
7482 pub fn from_secret_with_digest ( secret : & [ u8 ] , mac_digest : MacDigest ) -> Self {
7583 TOTP :: new ( secret, mac_digest, 6 , 30 )
7684 }
7785
78- /// Creates a new TOTP instance from a utf8-encoded string secret
86+ /// Creates a new TOTP instance with an utf8 representation of the secret.
7987 ///
80- /// Like [`TOTP::new`], this method also defaults to using [`MacDigest::SHA1`]
81- /// for HMAC operations .
88+ /// Defaults to using [`MacDigest::SHA1`] as the digest for HMAC operations,
89+ /// 6 digits and a 30 seconds period .
8290 pub fn from_utf8 ( secret : & str ) -> Self {
8391 TOTP :: from_utf8_with_digest ( secret, MacDigest :: SHA1 )
8492 }
8593
86- /// Creates a new TOTP instance from a utf8-encoded string secret
94+ /// Creates a new TOTP instance with an utf8 representation of the secret and
95+ /// a digest algorithm.
8796 ///
88- /// Like [`TOTP::new_with_digest`], this method allows a digest to be specified
89- /// instead of the default SHA1 being used.
97+ /// Defaults to using 6 digits and a 30 seconds period.
9098 pub fn from_utf8_with_digest ( secret : & str , mac_digest : MacDigest ) -> Self {
9199 TOTP :: new_from_utf8 ( secret, mac_digest, 6 , 30 )
92100 }
93101
94- /// Creates a new TOTP instance from a base32-encoded string secret
102+ /// Creates a new TOTP instance with a base32 representation of the secret.
95103 ///
96- /// Like [`TOTP::new`] and [`TOTP::from_utf8 `] this method also defaults
97- /// to using [`MacDigest::SHA1`] for HMAC operations .
104+ /// Defaults to using [`MacDigest::SHA1 `] as the digest for HMAC operations,
105+ /// 6 digits and a 30 seconds period .
98106 ///
99107 /// # Panics
100- /// This method panics if the [`TOTP::from_base32_with_digest`] does,
101- /// which happens when the provided string is not correctly base32 encoded.
108+ /// This method panics if the provided string is not correctly base32 encoded.
102109 pub fn from_base32 ( secret : & str ) -> Self {
103110 TOTP :: from_base32_with_digest ( secret, MacDigest :: SHA1 )
104111 }
105112
106- /// Creates a new TOTP instance from a base32-encoded string secret
113+ /// Creates a new TOTP instance with a base32 representation of the secret and
114+ /// a digest algorithm.
107115 ///
108- /// Like [`TOTP::new_with_digest`] and [`TOTP::from_utf8_with_digest`] this
109- /// method allows a digest to be specified instead of the default SHA1.
116+ /// Defaults to using 6 digits and a 30 seconds period.
110117 ///
111118 /// # Panics
112119 /// This method panics if the provided string is not correctly base32 encoded.
@@ -135,30 +142,22 @@ impl TOTP {
135142
136143// All otp generation methods for the [`TOTP`] struct.
137144impl TOTP {
138- /// Generates and returns the TOTP value for the time with the
139- /// specified digits.
140- ///
141- /// The time must be specified in seconds to calculate the correct
142- /// one-time password.
145+ /// Generates and returns the TOTP value for the specified time.
143146 ///
144- /// As this method doesn't specify time steps or a starting time,
145- /// the starting time is assumed to be 0 and the time step is set
146- /// to the default of 30 seconds.
147+ /// The time must be specified in seconds to calculate the correct one-time password.
147148 ///
148149 /// # Panics
149- /// This method panics if the called [`TOTP::get_otp_with_custom `] method
150+ /// This method panics if the called [`TOTP::get_otp_with_custom_time_start `] method
150151 /// does, which would happen if the hash's secret is incorrectly given.
151152 pub fn get_otp ( & self , time : u64 ) -> u32 {
152153 self . get_otp_with_custom_time_start ( time, 0 )
153154 }
154155
155- /// Generates and returns the TOTP value for the time with a provided step,
156- /// start time, and digit count
156+ /// Generates and returns the TOTP value for the specified time.
157157 ///
158- /// Like with the [`TOTP::get_otp`] method, the time should be provided in
159- /// seconds for proper calculation
158+ /// The time must be specified in seconds to calculate the correct one-time password.
160159 ///
161- /// This method allows custom start times and time steps to be provided.
160+ /// This method allows a custom start time to be provided.
162161 ///
163162 /// # Panics
164163 /// This method panics if the hash's secret is incorrectly given.
0 commit comments