lib/rotp/hotp.rb in rotp-3.3.1 vs lib/rotp/hotp.rb in rotp-4.0.0
- old
+ new
@@ -1,35 +1,22 @@
module ROTP
class HOTP < OTP
# Generates the OTP for the given count
# @param [Integer] count counter
- # @option [Boolean] padding (false) Issue the number as a 0 padded string
# @returns [Integer] OTP
- def at(count, padding=true)
- generate_otp(count, padding)
+ def at(count)
+ generate_otp(count)
end
# Verifies the OTP passed in against the current time OTP
- # @param [String/Integer] otp the OTP to check against
- # @param [Integer] counter the counter of the OTP
- def verify(otp, counter)
- super(otp, self.at(counter))
- end
-
- # Verifies the OTP passed in against the current time OTP, with a given number of retries.
- # Returns the counter that was verified successfully
- # @param [String/Integer] otp the OTP to check against
- # @param [Integer] initial counter the counter of the OTP
- # @param [Integer] number of retries
- def verify_with_retries(otp, initial_count, retries = 1)
- return false if retries <= 0
-
- 1.upto(retries) do |counter|
- current_counter = initial_count + counter
- return current_counter if verify(otp, current_counter)
- end
-
- false
+ # @param otp [String/Integer] the OTP to check against
+ # @param counter [Integer] the counter of the OTP
+ # @param retries [Integer] number of counters to incrementally retry
+ def verify(otp, counter, retries: 0)
+ counters = (counter..counter+retries).to_a
+ counters.find { |c|
+ super(otp, self.at(c))
+ }
end
# Returns the provisioning URI for the OTP
# This can then be encoded in a QR Code and used
# to provision the Google Authenticator app