Class: Keepassx::Database
- Inherits:
-
Object
- Object
- Keepassx::Database
- Defined in:
- lib/keepassx/database.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt_payload ⇒ Object
- #entry(title) ⇒ Object
-
#initialize(raw_db) ⇒ Database
constructor
A new instance of Database.
- #search(pattern) ⇒ Object
- #unlock(master_password) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
4 5 6 |
# File 'lib/keepassx/database.rb', line 4 def entries @entries end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
4 5 6 |
# File 'lib/keepassx/database.rb', line 4 def groups @groups end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/keepassx/database.rb', line 4 def header @header end |
Class Method Details
.open(path) ⇒ Object
6 7 8 9 |
# File 'lib/keepassx/database.rb', line 6 def self.open(path) content = File.respond_to?(:binread) ? File.binread(path) : File.read(path) self.new(content) end |
Instance Method Details
#decrypt_payload ⇒ Object
41 42 43 |
# File 'lib/keepassx/database.rb', line 41 def decrypt_payload @payload = AESCrypt.decrypt(@encrypted_payload, @final_key, header.encryption_iv, 'AES-256-CBC') end |
#entry(title) ⇒ Object
16 17 18 |
# File 'lib/keepassx/database.rb', line 16 def entry(title) @entries.detect { |e| e.title == title } end |
#search(pattern) ⇒ Object
31 32 33 34 35 |
# File 'lib/keepassx/database.rb', line 31 def search(pattern) backup = groups.detect { |g| g.name == "Backup" } backup_group_id = backup && backup.group_id entries.select { |e| e.group_id != backup_group_id && e.title =~ /#{pattern}/i } end |
#unlock(master_password) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/keepassx/database.rb', line 20 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
37 38 39 |
# File 'lib/keepassx/database.rb', line 37 def valid? @header.valid? end |