Class: OTP::TOTP

Inherits:
Base
  • Object
show all
Defined in:
lib/otp/totp.rb

Constant Summary collapse

DEFAULT_PERIOD =
30

Constants inherited from Base

Base::DEFAULT_ALGORITHM, Base::DEFAULT_DIGITS

Instance Attribute Summary collapse

Attributes inherited from Base

#accountname, #algorithm, #digits, #issuer, #secret

Instance Method Summary collapse

Methods inherited from Base

#new_secret, #password, #raw_secret, #raw_secret=, #to_uri, #verify

Constructor Details

#initialize(*args) ⇒ TOTP


9
10
11
12
13
# File 'lib/otp/totp.rb', line 9

def initialize(*args)
  super
  self.period = DEFAULT_PERIOD
  self.time = nil
end

Instance Attribute Details

#periodObject

Returns the value of attribute period


5
6
7
# File 'lib/otp/totp.rb', line 5

def period
  @period
end

#timeObject

Returns the value of attribute time


5
6
7
# File 'lib/otp/totp.rb', line 5

def time
  @time
end

Instance Method Details

#extract_uri_params(params) ⇒ Object


25
26
27
28
# File 'lib/otp/totp.rb', line 25

def extract_uri_params(params)
  super
  self.period = (params["period"] || period).to_i
end

#moving_factorObject


15
16
17
# File 'lib/otp/totp.rb', line 15

def moving_factor
  return (time || Time.now).to_i / period
end

#uri_paramsObject


19
20
21
22
23
# File 'lib/otp/totp.rb', line 19

def uri_params
  params = super
  params["period"] = period if period != DEFAULT_PERIOD
  return params
end