Class: Gtk2PasswordApp::Accounts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dumpfile, password = nil) ⇒ Accounts

Returns a new instance of Accounts.



9
10
11
12
13
# File 'lib/gtk2passwordapp/accounts.rb', line 9

def initialize(dumpfile, password=nil)
  reset(password) if password # sets @yzb
  @dumpfile = dumpfile
  @data = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/gtk2passwordapp/accounts.rb', line 8

def data
  @data
end

Instance Method Details

#add(account) ⇒ Object



48
49
50
51
# File 'lib/gtk2passwordapp/accounts.rb', line 48

def add()
  raise CONFIG[:AccountHit] if @data.has_key?()
  Account.new(, @data)
end

#delete(account) ⇒ Object



38
39
40
41
# File 'lib/gtk2passwordapp/accounts.rb', line 38

def delete()
  raise CONFIG[:AccountMiss] unless @data.has_key?()
  @data.delete()
end

#exist?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/gtk2passwordapp/accounts.rb', line 15

def exist?
  File.exist? @dumpfile
end

#get(account) ⇒ Object



43
44
45
46
# File 'lib/gtk2passwordapp/accounts.rb', line 43

def get()
  raise CONFIG[:AccountMiss] unless @data.has_key?()
  Account.new(, @data)
end

#load(password = nil) ⇒ Object

will raise an exception on failed decryption



20
21
22
23
24
25
26
# File 'lib/gtk2passwordapp/accounts.rb', line 20

def load(password=nil)
  reset(password) if password
  data = @yzb.load(@dumpfile)
  # Sanity check... load will raise CipherError on decription error.
  raise CONFIG[:CipherError] unless data.class == Hash
  @data = data
end

#namesObject



34
35
36
# File 'lib/gtk2passwordapp/accounts.rb', line 34

def names
  @data.keys
end

#reset(password) ⇒ Object



4
5
6
# File 'lib/gtk2passwordapp/accounts.rb', line 4

def reset(password)
  @yzb =  YamlZlibBlowfish.new(password)
end

#save(password = nil) ⇒ Object



28
29
30
31
32
# File 'lib/gtk2passwordapp/accounts.rb', line 28

def save(password=nil)
  reset(password) if password
  @yzb.dump(@dumpfile, @data)
  File.chmod(0600, @dumpfile)
end