lib/tfa/totp_command.rb in tfa-0.0.8 vs lib/tfa/totp_command.rb in tfa-0.0.9
- old
+ new
@@ -2,33 +2,27 @@
class TotpCommand
def initialize(storage)
@storage = storage
end
- def run(arguments)
- return password_for(secret_for(arguments.first)) if valid?(arguments)
- all_passwords
+ def run(name)
+ secret = secret_for(name)
+ secret ? password_for(secret) : 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|
+ @storage.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
-
- def valid?(arguments)
- arguments.any? && secret_for(arguments.first)
end
end
end