Class: SetecAstronomy::KeePass::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/setec_astronomy/kee_pass/database.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_db) ⇒ Database

Returns a new instance of Database.



12
13
14
15
# File 'lib/setec_astronomy/kee_pass/database.rb', line 12

def initialize(raw_db)
  @header = Header.new(raw_db[0..124])
  @encrypted_payload = raw_db[124..-1]
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



5
6
7
# File 'lib/setec_astronomy/kee_pass/database.rb', line 5

def entries
  @entries
end

#groupsObject (readonly)

Returns the value of attribute groups.



5
6
7
# File 'lib/setec_astronomy/kee_pass/database.rb', line 5

def groups
  @groups
end

#headerObject (readonly)

Returns the value of attribute header.



5
6
7
# File 'lib/setec_astronomy/kee_pass/database.rb', line 5

def header
  @header
end

Class Method Details

.open(path) ⇒ Object



7
8
9
10
# File 'lib/setec_astronomy/kee_pass/database.rb', line 7

def self.open(path)
  content = File.respond_to?(:binread) ? File.binread(path) : File.read(path)
  self.new(content)
end

Instance Method Details

#decrypt_payloadObject



40
41
42
# File 'lib/setec_astronomy/kee_pass/database.rb', line 40

def decrypt_payload
  @payload = AESCrypt.decrypt(@encrypted_payload, @final_key, header.encryption_iv, 'AES-256-CBC')
end

#entry(title) ⇒ Object



17
18
19
# File 'lib/setec_astronomy/kee_pass/database.rb', line 17

def entry(title)
  @entries.detect { |e| e.title == title }
end

#search(pattern) ⇒ Object



32
33
34
# File 'lib/setec_astronomy/kee_pass/database.rb', line 32

def search(pattern)
  entries.select { |e| e.title =~ /#{pattern}/i }
end

#unlock(master_password) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/setec_astronomy/kee_pass/database.rb', line 21

def unlock(master_password)
  @final_key = header.final_key(master_password)
  decrypt_payload
  payload_io = StringIO.new(@payload)
  @groups = Group.extract_from_payload(header, payload_io)
  @entries = Entry.extract_from_payload(header, payload_io)
  true
rescue OpenSSL::Cipher::CipherError
  false
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/setec_astronomy/kee_pass/database.rb', line 36

def valid?
  @header.valid?
end