Class: KeyChain

Inherits:
Object
  • Object
show all
Defined in:
lib/keychain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ KeyChain

Returns a new instance of KeyChain.



13
14
15
# File 'lib/keychain.rb', line 13

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/keychain.rb', line 11

def key
  @key
end

Instance Method Details

#accountObject



18
19
20
21
22
23
# File 'lib/keychain.rb', line 18

def 
  radiko = Pit.get(key)
  if radiko.has_key? :account and radiko.has_key? :password
    [ radiko[:account], Base64.decode64(radiko[:password]) ]
  end
end

#query(prompt, account) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/keychain.rb', line 32

def query(prompt, )
  , old_password = ()
  puts prompt
  print '  password : '
  STDOUT.flush
  new_password = STDIN.noecho(&:gets).chomp
  puts
  case
  when new_password.empty?
    raise "空のパスワードは無効です (何も変更されません)"
  when new_password == old_password
    raise "旧パスワードと同じパスワードです"
  end
  new_password
end

#set(account, password) ⇒ Object



26
27
28
29
# File 'lib/keychain.rb', line 26

def set(, password)
  Pit.set(key, data: { account: , password: Base64.encode64(password)})
  [, password]
end