Module: PWS::Format::V0_9
- Defined in:
- lib/pws/format/0.9.rb
Overview
PWS file format reader for versions before 1.0.0
Class Method Summary collapse
- .decrypt(saved_data, options = {}) ⇒ Object
- .read(saved_data, options = {}) ⇒ Object
- .sha(plaintext) ⇒ Object
- .unmarshal(unencrypted_data, options = {}) ⇒ Object
- .write(_, _ = {}) ⇒ Object
Class Method Details
.decrypt(saved_data, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pws/format/0.9.rb', line 20 def decrypt(saved_data, = {}) iv, encrypted_data = saved_data.unpack('a16 a*') PWS::Encryptor.decrypt( encrypted_data, key: sha([:password])[0...32], iv: iv, ) end |
.read(saved_data, options = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/pws/format/0.9.rb', line 14 def read(saved_data, = {}) unmarshal(decrypt(saved_data, )) rescue fail NoAccess, %[Could not read the password safe!] end |
.sha(plaintext) ⇒ Object
35 36 37 |
# File 'lib/pws/format/0.9.rb', line 35 def sha(plaintext) OpenSSL::Digest::SHA512.new(plaintext).digest end |
.unmarshal(unencrypted_data, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/pws/format/0.9.rb', line 29 def unmarshal(unencrypted_data, = {}) raw_data = Marshal.load(unencrypted_data) application_data = raw_data[ raw_data[-1] ] # remove redundancy Hash[application_data.map{ |k,v| [k, { password: v}] }] # patch to new internal format end |
.write(_, _ = {}) ⇒ Object
10 11 12 |
# File 'lib/pws/format/0.9.rb', line 10 def write(_,_={}) raise NotImplementedError, 'Writing the legacy 0.9 format is not supported' end |