class TOTP::CLI::Token

Attributes

id[RW]
label[RW]
secret[RW]

Public Class Methods

all() click to toggle source
# File lib/totp/cli/token.rb, line 8
def all
  store.read_all
end
create(label, secret) click to toggle source
# File lib/totp/cli/token.rb, line 28
def create(label, secret)
  store.save(label, secret)

  find_by_label(label)
end
find_by_id(id) click to toggle source
# File lib/totp/cli/token.rb, line 12
def find_by_id(id)
  all.each do |token|
    return token if token.id == id
  end

  nil
end
find_by_label(label) click to toggle source
# File lib/totp/cli/token.rb, line 20
def find_by_label(label)
  all.each do |token|
    return token if token.label == label
  end

  nil
end
new(options = {}) click to toggle source
# File lib/totp/cli/token.rb, line 42
def initialize(options = {})
  @id     = options[:id]
  @label  = options[:label]
  @secret = options[:secret]
end
store() click to toggle source
# File lib/totp/cli/token.rb, line 34
def store
  filepath = File.join(Etc.getpwuid.dir, ".totp-cli")
  Store.new(filepath)
end

Public Instance Methods

delete!() click to toggle source
# File lib/totp/cli/token.rb, line 58
def delete!
  self.class.store.remove(label)
end
now() click to toggle source
# File lib/totp/cli/token.rb, line 48
def now
  otp = totp.now.to_s

  while otp.length < 6
    otp = "0" + otp
  end

  otp
end

Private Instance Methods

totp() click to toggle source
# File lib/totp/cli/token.rb, line 64
def totp
  @totp ||= ROTP::TOTP.new(secret)
end