Sha256: 5b2d14752495797de082e85efd86a1a390a0fae54040271c98c2f0f9e83d7d54

Contents?: true

Size: 557 Bytes

Versions: 6

Compression:

Stored size: 557 Bytes

Contents

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

    def run(name, secret = secret_for(name))
      secret ? password_for(secret) : all_passwords
    end

    private

    def password_for(secret)
      ::ROTP::TOTP.new(secret).now
    rescue ROTP::Base32::Base32Error
      "INVALID SECRET"
    end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tfa-0.0.17 lib/tfa/totp_command.rb
tfa-0.1.0 lib/tfa/totp_command.rb
tfa-0.0.16 lib/tfa/totp_command.rb
tfa-0.0.15 lib/tfa/totp_command.rb
tfa-0.0.14 lib/tfa/totp_command.rb
tfa-0.0.13 lib/tfa/totp_command.rb