Class: ROTP::HOTP

Inherits:
OTP
  • Object
show all
Defined in:
lib/rotp/hotp.rb

Constant Summary

Constants inherited from OTP

OTP::DEFAULT_DIGITS

Instance Attribute Summary

Attributes inherited from OTP

#digest, #digits, #secret

Instance Method Summary collapse

Methods inherited from OTP

#generate_otp, #initialize

Constructor Details

This class inherits a constructor from ROTP::OTP

Instance Method Details

#at(count) ⇒ Object

Generates the OTP for the given count

Parameters:

  • count (Integer)

    counter


6
7
8
# File 'lib/rotp/hotp.rb', line 6

def at(count)
  generate_otp(count)
end

#provisioning_uri(name, initial_count = 0) ⇒ String

Returns the provisioning URI for the OTP This can then be encoded in a QR Code and used to provision the Google Authenticator app

Parameters:

  • name (String)

    of the account

  • initial_count (Integer) (defaults to: 0)

    starting counter value, defaults to 0

Returns:

  • (String)

    provisioning uri


27
28
29
# File 'lib/rotp/hotp.rb', line 27

def provisioning_uri(name, initial_count = 0)
  OTP::URI.new(self, account_name: name, counter: initial_count).to_s
end

#verify(otp, counter, retries: 0) ⇒ Object

Verifies the OTP passed in against the current time OTP

Parameters:

  • otp (String/Integer)

    the OTP to check against

  • counter (Integer)

    the counter of the OTP

  • retries (Integer) (defaults to: 0)

    number of counters to incrementally retry


14
15
16
17
18
19
# File 'lib/rotp/hotp.rb', line 14

def verify(otp, counter, retries: 0)
  counters = (counter..counter + retries).to_a
  counters.find do |c|
    super(otp, at(c))
  end
end