File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,28 @@ impl TOTP {
149149 }
150150}
151151
152+ /// All helper methods for totp generation
153+ impl TOTP {
154+
155+ /// Returns the time in seconds until an OTP refresh is needed.
156+ ///
157+ /// Just like the corresponding [`TOTP::get_otp`] method, this method
158+ /// takes the current system time in seconds.
159+ pub fn time_until_refresh ( & self , time : u64 ) -> u64 {
160+ self . time_until_refresh_with_start ( time, 0 )
161+ }
162+
163+ /// Returns the time in seconds until an OTP refresh is needed.
164+ ///
165+ /// Just like the corresponding [`TOTP::get_otp_with_custom_time_start`]
166+ /// method, this method takes the current time in seconds along with a
167+ /// specified start time in case an offset is desired. Both values must be
168+ /// in seconds.
169+ pub fn time_until_refresh_with_start ( & self , time : u64 , time_start : u64 ) -> u64 {
170+ ( time - time_start) % period
171+ }
172+ }
173+
152174/// All otp generation methods for the [`TOTP`] struct.
153175impl TOTP {
154176 /// Generates and returns the TOTP value for the specified time.
You can’t perform that action at this time.
0 commit comments