Class: Gtk2PasswordApp::Accounts
- Inherits:
-
Object
- Object
- Gtk2PasswordApp::Accounts
- Defined in:
- lib/gtk2passwordapp/accounts.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(account) ⇒ Object
- #delete(account) ⇒ Object
- #exist? ⇒ Boolean
- #get(account) ⇒ Object
-
#initialize(dumpfile, password = nil) ⇒ Accounts
constructor
A new instance of Accounts.
-
#load(password = nil) ⇒ Object
will raise an exception on failed decryption.
- #names ⇒ Object
- #reset(password) ⇒ Object
- #save(password = nil) ⇒ Object
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
#data ⇒ Object (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(account) raise CONFIG[:AccountHit] if @data.has_key?(account) Account.new(account, @data) end |
#delete(account) ⇒ Object
38 39 40 41 |
# File 'lib/gtk2passwordapp/accounts.rb', line 38 def delete(account) raise CONFIG[:AccountMiss] unless @data.has_key?(account) @data.delete(account) end |
#exist? ⇒ 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(account) raise CONFIG[:AccountMiss] unless @data.has_key?(account) Account.new(account, @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 |
#names ⇒ Object
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 |