Sha256: 9c0767b2aacc632c0c37e527c293f2eaca39eab3c98d23b88e396b001112201c

Contents?: true

Size: 571 Bytes

Versions: 2

Compression:

Stored size: 571 Bytes

Contents

module TFA
  class TotpCommand
    def initialize(storage)
      @storage = storage
    end

    def run(arguments)
      return password_for(secret_for(arguments.first)) if arguments.any?
      all_passwords
    end

    private

    def password_for(secret)
      ::ROTP::TOTP.new(secret).now
    end

    def all_passwords
      secrets = @storage.all_secrets
      secrets.each do |hash|
        hash[hash.keys.first] = password_for(hash[hash.keys.first])
      end
      secrets
    end

    def secret_for(key)
      @storage.secret_for(key)     
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tfa-0.0.5 lib/tfa/totp_command.rb
tfa-0.0.4 lib/tfa/totp_command.rb