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

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, options = {})
  iv, encrypted_data = saved_data.unpack('a16 a*')
  PWS::Encryptor.decrypt(
    encrypted_data,
    key: sha(options[: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, options = {})
  unmarshal(decrypt(saved_data, options))
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, options = {})
  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

Raises:

  • (NotImplementedError)


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