Class: PasswordVault::Vault
- Inherits:
-
Object
- Object
- PasswordVault::Vault
- Defined in:
- lib/password_vault/vault.rb
Instance Method Summary collapse
- #delete_password(name) ⇒ Object
- #dump ⇒ Object
- #get_password(name) ⇒ Object
-
#initialize(key) ⇒ Vault
constructor
A new instance of Vault.
- #lock ⇒ Object
- #passwords ⇒ Object
- #read ⇒ Object
- #unlock(data) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(key) ⇒ Vault
Returns a new instance of Vault.
6 7 8 |
# File 'lib/password_vault/vault.rb', line 6 def initialize(key) @key = Digest::SHA512.digest(key) end |
Instance Method Details
#delete_password(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/password_vault/vault.rb', line 19 def delete_password(name) if p = get_password(name) @passwords -= [p] end end |
#dump ⇒ Object
42 43 44 |
# File 'lib/password_vault/vault.rb', line 42 def dump Marshal.dump(passwords) end |
#get_password(name) ⇒ Object
14 15 16 17 |
# File 'lib/password_vault/vault.rb', line 14 def get_password(name) found = @passwords.select {|p| p.name == name } found.first end |
#lock ⇒ Object
33 34 35 |
# File 'lib/password_vault/vault.rb', line 33 def lock crypt(:encrypt, dump) end |
#passwords ⇒ Object
10 11 12 |
# File 'lib/password_vault/vault.rb', line 10 def passwords @passwords ||= [] end |
#read ⇒ Object
29 30 31 |
# File 'lib/password_vault/vault.rb', line 29 def read unlock File.read(PasswordVault::VaultFile) end |
#unlock(data) ⇒ Object
37 38 39 40 |
# File 'lib/password_vault/vault.rb', line 37 def unlock(data) dump = crypt(:decrypt, data) @passwords = Marshal.load(dump) end |
#write ⇒ Object
25 26 27 |
# File 'lib/password_vault/vault.rb', line 25 def write File.open(PasswordVault::VaultFile, 'w') {|f| f.write(lock) } end |