Class: SetecAstronomy::KeePass::Database
- Inherits:
-
Object
- Object
- SetecAstronomy::KeePass::Database
- Defined in:
- lib/setec_astronomy/kee_pass/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.
5 6 7 |
# File 'lib/setec_astronomy/kee_pass/database.rb', line 5 def entries @entries end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
5 6 7 |
# File 'lib/setec_astronomy/kee_pass/database.rb', line 5 def groups @groups end |
#header ⇒ Object (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_payload ⇒ Object
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
36 37 38 |
# File 'lib/setec_astronomy/kee_pass/database.rb', line 36 def valid? @header.valid? end |