Sha256: 6e2973e70405ce4f5b4153541b2ee69ad2dda598e36944ae43e01cc40fb1bff0

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 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

1 entries across 1 versions & 1 rubygems

Version Path
tfa-0.0.12 lib/tfa/totp_command.rb