Sha256: bbc8e1867fbbb283996f15a9152e1f094e2ccc1336d05998ea609e199c47ebb5

Contents?: true

Size: 482 Bytes

Versions: 1

Compression:

Stored size: 482 Bytes

Contents

module ROTP
  class TOTP < OTP

    attr_reader :interval

    def initialize(s, options = {})
      @interval = options[:interval] || 30
      super
    end

    def at(time)
      unless time.class == Time
        time = Time.at(time.to_i)
      end
      generate_otp(timehash(time))
    end

    def now
      generate_otp(timehash(Time.now))
    end

    private

    def timehash(time)
      i = time.utc.to_i * 1000
      i = i / (interval * 1000)
      i
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rotp-1.0.0 lib/rotp/totp.rb