Class: PasswordSafe::Safe
- Inherits:
-
Object
- Object
- PasswordSafe::Safe
show all
- Includes:
- Encryptor
- Defined in:
- lib/passwordsafe/safe.rb
Instance Method Summary
collapse
Methods included from Encryptor
#decrypt, #encrypt, #hash
Constructor Details
#initialize(filename, masterpass) ⇒ Safe
Returns a new instance of Safe.
7
8
9
10
|
# File 'lib/passwordsafe/safe.rb', line 7
def initialize filename, masterpass
@safefile = File.expand_path(filename)
@mphash = hash(masterpass)
end
|
Instance Method Details
#access_safe ⇒ Object
12
13
14
15
16
17
|
# File 'lib/passwordsafe/safe.rb', line 12
def access_safe
unless File.file? @safefile
FileUtils.touch @safefile
write_safe
end
end
|
#read_safe ⇒ Object
24
25
26
27
|
# File 'lib/passwordsafe/safe.rb', line 24
def read_safe
access_safe
Marshal.load decrypt(File.read(@safefile), @mphash) || {}
end
|
#write_safe(data = {}) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/passwordsafe/safe.rb', line 18
def write_safe data = {}
dump = Marshal.dump(data)
access_safe
encrypted_data = encrypt(dump, @mphash)
File.open(@safefile, 'w') {|f| f.write encrypted_data}
end
|