ruby-keepassx 0.2.0beta11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- metadata.gz: 23df857ea8fd01dacd6b60497d8f95075c0f827767835eca41258166fb98504198eefe9c3bb75cf67f42ec1abdff0410b2f9a38aaad314b6fe8e9feaf871abaa
4
- data.tar.gz: 078c8430644ba977faf74ee6646adb1c039355819d975ff4e584ad4ac84d0dd3f897ce31b861a2e2bac3dfdf9cfb9b4d56b05d183c47bc680632f730b1b915c9
5
- SHA1:
6
- metadata.gz: a3fa2dedf5c4ad9d9ee9c742d4daff03044a6ed2
7
- data.tar.gz: d9e4c27365a9772e81486e23b9da7f4f602a48d3
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35f2f1221b72c8c74d1fa5a93850c16344d45545
4
+ data.tar.gz: c0ab67fd645312df9583a7d98304f19c7f287cce
5
+ SHA512:
6
+ metadata.gz: 1f09e9cdd21f2e08a544f02c868877c05f3e3dcb8e30b1e850d6dc3e0f977a305a868064a0abfd2dcd2aab49b9bbf065535503b29ee7252c00f97e579facefb7
7
+ data.tar.gz: 4307be70d609093891f1bdf59f2e5cfd263a5ee9febcfec84cf8e29ae4f7dff984a2a0e634758460ada410b8bb01127acb9d57bc90c61d216d3fff94d469f46e
@@ -5,25 +5,6 @@ require 'digest/sha2'
5
5
  require 'securerandom'
6
6
  require 'rexml/document'
7
7
 
8
- # Add backward compatibility stuff
9
- if RUBY_VERSION =~ /1\.8/
10
- require 'backports/tools'
11
- require 'backports/1.9.1/symbol/empty'
12
- require 'backports/1.9.3/io/write'
13
- require 'time' # Get Time.parse
14
-
15
- unless SecureRandom.method_defined? :uuid
16
- module SecureRandom
17
- # Based on this post https://www.ruby-forum.com/topic/3171049#1035902
18
- def self.uuid
19
- s = hex 16
20
- [s[0..7], s[8..11], s[12..15], s[16..19], s[20..-1]].join '-'
21
- end
22
- end
23
- end
24
- end
25
-
26
-
27
8
  require 'keepassx/exceptions'
28
9
  require 'keepassx/header'
29
10
  require 'keepassx/utilities'
@@ -39,6 +20,14 @@ require 'keepassx/aes_crypt'
39
20
  module Keepassx
40
21
 
41
22
  class << self
23
+
24
+
25
+ # Create Keepassx database
26
+ #
27
+ # @param opts [Hash] Keepassx database options.
28
+ # @yield [opts]
29
+ # @yieldreturn [Fixnum]
30
+ # @return [Keepassx::Database]
42
31
  def new opts
43
32
  db = Database.new opts
44
33
  return db unless block_given?
@@ -46,6 +35,12 @@ module Keepassx
46
35
  end
47
36
 
48
37
 
38
+ # Read Keepassx database from file storage.
39
+ #
40
+ # @param opts [Hash] Keepassx database options.
41
+ # @yield [opts]
42
+ # @yieldreturn [Fixnum]
43
+ # @return [Keepassx::Database]
49
44
  def open opts
50
45
  db = Database.open opts
51
46
  return db unless block_given?
@@ -50,6 +50,11 @@ module Keepassx
50
50
  end
51
51
 
52
52
 
53
+ # Get raw encoded database.
54
+ #
55
+ # @param password [String] Password the database will be encoded with.
56
+ # @param key_file [String] Path to key file.
57
+ # @return [String]
53
58
  def dump password = nil, key_file = nil
54
59
  # FIXME: Figure out what this is needed for
55
60
  # my $e = ($self->find_entries({title => 'Meta-Info', username => 'SYSTEM', comment => 'KPX_GROUP_TREE_STATE', url => '$'}))[0] || $self->add_entry({
@@ -73,8 +78,13 @@ module Keepassx
73
78
  end
74
79
 
75
80
 
76
- # TODO: Switch to rails style, i.e. save(:password => 'pass')
81
+ # Save database to file storage
82
+ #
83
+ # @param password [String] Password the database will be encoded with.
84
+ # @param key_file [String] Path to key file.
85
+ # @return [Fixnum]
77
86
  def save password = nil, key_file = nil
87
+ # TODO: Switch to rails style, i.e. save(:password => 'pass')
78
88
  fail TypeError, 'File path is not set' if path.nil?
79
89
  File.write path, dump(password, key_file)
80
90
 
@@ -89,6 +99,10 @@ module Keepassx
89
99
 
90
100
 
91
101
  # Search for items, using AND statement for the search conditions
102
+ #
103
+ # @param item_type [Symbol] Can be :entry or :group.
104
+ # @param opts [Hash] Search options.
105
+ # @return [Keepassx::Group, Keepassx::Entry]
92
106
  def get item_type, opts = {}
93
107
 
94
108
  case item_type
@@ -110,7 +124,7 @@ module Keepassx
110
124
  match_number = opts.length
111
125
  items = []
112
126
  opts.each do |k, v|
113
- items += Array(item_list.select { |e| e.send(k).eql?(v) })
127
+ items += Array item_list.select { |e| e.send(k).eql?(v) }
114
128
  end
115
129
 
116
130
  buffer = Hash.new 0
@@ -138,7 +152,9 @@ module Keepassx
138
152
  end
139
153
 
140
154
 
141
- # Get first matching entry
155
+ # Get first matching entry.
156
+ #
157
+ # @return [Keepassx::Entry]
142
158
  def entry opts = {}
143
159
  entries = get :entry, opts
144
160
  if entries.empty?
@@ -150,13 +166,17 @@ module Keepassx
150
166
  end
151
167
 
152
168
 
153
- # Get all matching entries
169
+ # Get all matching entries.
170
+ #
171
+ # @return [Array<Keepassx::Entry>]
154
172
  def entries opts = {}
155
173
  get :entry, opts
156
174
  end
157
175
 
158
176
 
159
- # Get first matching group
177
+ # Get first matching group.
178
+ #
179
+ # @return [Keepassx::Group]
160
180
  def group opts = {}
161
181
  groups = get :group, opts
162
182
  if groups.empty?
@@ -168,12 +188,19 @@ module Keepassx
168
188
  end
169
189
 
170
190
 
171
- # Get all matching groups
191
+ # Get all matching groups.
192
+ #
193
+ # @param opts [Hash]
194
+ # @return [Array<Keepassx::Group>]
172
195
  def groups opts = {}
173
196
  get :group, opts
174
197
  end
175
198
 
176
199
 
200
+ # Add new item to database.
201
+ #
202
+ # @param item [Symbol, Keepassx::Group, Keepassx::Entry] New item.
203
+ # @return [Keepassx::Group, Keepassx::Entry]
177
204
  def add item, opts = {}
178
205
  if item.is_a? Symbol
179
206
 
@@ -197,6 +224,10 @@ module Keepassx
197
224
  end
198
225
 
199
226
 
227
+ # Add new group to database.
228
+ #
229
+ # @param opts [Hash] Options that will be passed to Keepassx::Group#new.
230
+ # @return [Keepassx::Group]
200
231
  def add_group opts
201
232
 
202
233
  if opts.is_a? Hash
@@ -232,7 +263,12 @@ module Keepassx
232
263
  end
233
264
 
234
265
 
266
+ # Add new entry to database.
267
+ #
268
+ # @param opts [Hash] Options that will be passed to Keepassx::Entry#new.
269
+ # @return [Keepassx::Entry]
235
270
  def add_entry opts
271
+ # FIXME: Add warnings and detailed description
236
272
  if opts.is_a? Hash
237
273
  opts = deep_copy opts
238
274
 
@@ -258,11 +294,11 @@ module Keepassx
258
294
  end
259
295
 
260
296
 
261
- # Delete item from database
297
+ # Delete item from database.
262
298
  #
263
- # @param [Keepassx::Group, Keepassx::Entry, Symbol] item Item to delete.
264
- # @param [Hash] opts If first parameter is a Symbol, then this is used to
265
- # determine which item to delete.
299
+ # @param item [Keepassx::Group, Keepassx::Entry, Symbol] Item to delete.
300
+ # @param opts [Hash] If first parameter is a Symbol, then this will be
301
+ # used to determine which item to delete.
266
302
  def delete item, opts = {}
267
303
  if item.is_a? Keepassx::Group
268
304
  delete_group item
@@ -285,11 +321,11 @@ module Keepassx
285
321
  end
286
322
 
287
323
 
288
- # Unlock database
324
+ # Unlock database.
289
325
  #
290
- # @param [String] password Datbase password
291
- # @param [String] key_file Key file path
292
- # @return [Boolean] Whether or not password validation successfull
326
+ # @param password [String] Datbase password.
327
+ # @param key_file [String] Key file path.
328
+ # @return [Boolean] Whether or not password validation successfull.
293
329
  def unlock password, key_file = nil
294
330
 
295
331
  return true unless locked?
@@ -310,12 +346,13 @@ module Keepassx
310
346
  end
311
347
 
312
348
 
313
- # FIXME: Seqrch by any atribute by pattern
314
- # Searn entry by title
349
+
350
+ # Search entry by title.
315
351
  #
316
- # @param [String] pattern Entry's title to search for
352
+ # @param pattern [String] Entry's title to search for.
317
353
  # @return [Keepassx::Entry]
318
354
  def search pattern
355
+ # FIXME: Seqrch by any atribute by pattern
319
356
  backup = group 'Backup'
320
357
 
321
358
  entries.select do |e|
@@ -324,7 +361,7 @@ module Keepassx
324
361
  end
325
362
 
326
363
 
327
- # Check database validity
364
+ # Check database validity.
328
365
  #
329
366
  # @return [Boolean]
330
367
  def valid?
@@ -340,9 +377,9 @@ module Keepassx
340
377
  end
341
378
 
342
379
 
343
- # Get Group/Entry index in storage
380
+ # Get Group/Entry index in storage.
344
381
  #
345
- # @return [Integer]
382
+ # @return [Fixnum]
346
383
  def index v
347
384
  if v.is_a? Keepassx::Group
348
385
  groups.find_index v
@@ -357,9 +394,9 @@ module Keepassx
357
394
  end
358
395
 
359
396
 
360
- # Get Enries and Groups total number
397
+ # Get Enries and Groups total number.
361
398
  #
362
- # @return [Integer]
399
+ # @return [Fixnum]
363
400
  def length
364
401
  length = 0
365
402
  [@groups, @entries].each do |items|
@@ -372,7 +409,7 @@ module Keepassx
372
409
  end
373
410
 
374
411
 
375
- # Get actual payload checksum
412
+ # Get actual payload checksum.
376
413
  #
377
414
  # @return [String]
378
415
  def checksum
@@ -380,9 +417,9 @@ module Keepassx
380
417
  end
381
418
 
382
419
 
383
- # Get next group ID number
420
+ # Get next group ID number.
384
421
  #
385
- # @return [Integer]
422
+ # @return [Fixnum]
386
423
  def next_group_id
387
424
  if groups.empty?
388
425
  # Start each time from 1 to make sure groups get the same id's for the
@@ -51,6 +51,12 @@ module Keepassx
51
51
  }
52
52
 
53
53
 
54
+ # Create entries from raw data.
55
+ #
56
+ # @param header [Keepassx::Header] Keepassx database header.
57
+ # @param groups [Array<Keepassx::Group>] Group list, the entry will bind to.
58
+ # @param payload [StringIO] Raw data.
59
+ # @return [Array<Keepassx::Entry>]
54
60
  def self.extract_from_payload(header, groups, payload)
55
61
  items = []
56
62
  header.entry_number.times do
@@ -62,6 +68,9 @@ module Keepassx
62
68
  end
63
69
 
64
70
 
71
+ # Get list of supported entry fields.
72
+ #
73
+ # @return [Array<Symbol>]
65
74
  def self.fields
66
75
  FIELD_MAPPING.keys
67
76
  end
@@ -78,8 +87,8 @@ module Keepassx
78
87
  fail "'group' is required" if payload[:group].nil?
79
88
  self.group = payload[:group]
80
89
 
81
- fields = self.class.fields
82
- data = payload.reject { |k, _| !fields.include? k }
90
+ field_list = FIELD_MAPPING.keys
91
+ data = payload.select { |k| field_list.include? k }
83
92
  data[:group_id] = group.id
84
93
 
85
94
  @fields = []
@@ -97,6 +106,10 @@ module Keepassx
97
106
  attr_reader :group
98
107
 
99
108
 
109
+ # Set parent group.
110
+ #
111
+ # @param v [Keepassx::Group] Parent group.
112
+ # @return [Keepassx::Group]
100
113
  def group= v
101
114
  if v.is_a? Keepassx::Group
102
115
  self.group_id = v.id
@@ -53,7 +53,9 @@ module Keepassx
53
53
  end
54
54
 
55
55
 
56
- # Return raw data length
56
+ # Get raw data length
57
+ #
58
+ # @return [Integer]
57
59
  def length
58
60
  TYPE_CODE_FIELD_SIZE + DATA_LENGTH_FIELD_SIZE + size
59
61
  end
@@ -167,6 +169,7 @@ module Keepassx
167
169
 
168
170
 
169
171
  def ascii= value
172
+ # TODO: Add spec
170
173
  @data = [value].pack('H*')
171
174
  end
172
175
 
@@ -164,7 +164,7 @@ module Keepassx
164
164
  end
165
165
 
166
166
  key = Digest::SHA2.new.update(key).digest
167
- key = Digest::SHA2.new.update(master_seed + key).digest
167
+ Digest::SHA2.new.update(master_seed + key).digest
168
168
 
169
169
  end
170
170
 
@@ -22,12 +22,6 @@ module Keepassx
22
22
  end
23
23
 
24
24
 
25
- # TODO: Remove debug method
26
- def dump
27
- @fields
28
- end
29
-
30
-
31
25
  def to_hash
32
26
  result = {}
33
27
  self.class.fields.each do |field|
@@ -92,7 +92,7 @@ module Keepassx
92
92
 
93
93
  # Set parents for groups
94
94
  #
95
- # @param [Array] list Array of groups.
95
+ # @param list [Array] Array of groups.
96
96
  # @return [Array] Updated array of groups.
97
97
  def initialize_groups list
98
98
 
@@ -109,9 +109,9 @@ module Keepassx
109
109
  if previous_group.nil? or group.level.eql? 0
110
110
  group.parent = nil
111
111
 
112
- # If group has level greater than parent's level by one,
113
- # it gets parent set to the first previous group with level less
114
- # than group's level by one
112
+ # If group has level greater than parent's level by one,
113
+ # it gets parent set to the first previous group with level less
114
+ # than group's level by one
115
115
  elsif group.level == previous_group.level + 1 or
116
116
  group.level == previous_group.level
117
117
 
@@ -153,7 +153,7 @@ module Keepassx
153
153
 
154
154
  # Retrieves last sibling index
155
155
  #
156
- # @param [Keepassx::Group] parent Last sibling group.
156
+ # @param parent [Keepassx::Group] Last sibling group.
157
157
  # @return [Integer] index Group index.
158
158
  def last_sibling_index parent
159
159
 
@@ -187,7 +187,7 @@ module Keepassx
187
187
  # Remove groups and entries from options, so new group could be
188
188
  # initialized from incoming Hash
189
189
  fields = Keepassx::Group.fields
190
- group_opts = opts.reject { |k, _| !fields.include? k }
190
+ group_opts = opts.select { |k, _| fields.include? k }
191
191
  group = add_group group_opts
192
192
 
193
193
  entries.each do |e|
@@ -197,6 +197,7 @@ module Keepassx
197
197
 
198
198
  # Recursively proceed each child group
199
199
  groups.each { |g| parse_data_array g } unless groups.nil?
200
+
200
201
  end
201
202
 
202
203
 
@@ -3,20 +3,15 @@ Gem::Specification.new do |s|
3
3
  s.summary = 'Ruby API access for KeePassX databases'
4
4
  s.description = 'This is fork of Tony Pitluga\'s ' \
5
5
  'Ruby API for keepassx with read-write support.'
6
- s.version = '0.2.0beta11'
6
+ s.version = '0.2.0'
7
7
  s.authors = ['Tony Pitluga', 'Paul Hinze', 'Tio Teath']
8
8
  s.email = ['tony.pitluga@gmail.com', 'paul.t.hinze@gmail.com',
9
- 'tio.teath@gmail.com']
9
+ 'tioteath@gmail.com']
10
10
  s.homepage = 'https://github.com/tioteath/ruby-keepassx.git'
11
11
  s.files = `git ls-files`.split "\n"
12
12
 
13
- # TODO: This won't work, figure out why.
14
- if RUBY_VERSION =~ /1\.8/
15
- s.add_dependency 'backports', '~> 3.6.0'
16
- end
17
-
18
13
  s.add_development_dependency 'rspec', '~> 3.0'
19
- s.add_development_dependency 'pry', '~> 0.9.12'
14
+ s.add_development_dependency 'pry', '~> 0'
20
15
  s.add_development_dependency 'rake', '~> 0.8', '>= 0.8.7'
21
16
  # s.add_development_dependency 'respect', '~> 0.1.1'
22
17
  # s.add_development_dependency 'rspec-prof', '~> 0'
@@ -16,8 +16,9 @@ describe Keepassx::Database do
16
16
  subject { Keepassx }
17
17
  let(:db1) { subject.new data_array }
18
18
  let(:db2) { subject.new data_array }
19
-
20
19
  it 'has the same checksum for the same data' do
20
+ # warn "db1: #{File.write '/tmp/db1', db1.entries.inspect}>><<"
21
+ # warn "db2: #{File.write '/tmp/db2', db2.entries.inspect}>><<"
21
22
  expect(db1.checksum).to eq db2.checksum
22
23
  end
23
24
  end
metadata CHANGED
@@ -1,77 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-keepassx
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0beta11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Tony Pitluga
8
8
  - Paul Hinze
9
9
  - Tio Teath
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2014-09-18 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: backports
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 3.6.0
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
13
+ date: 2014-09-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
27
16
  name: rspec
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: "3.0"
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
34
22
  type: :development
35
- version_requirements: *id002
36
- - !ruby/object:Gem::Dependency
37
- name: pry
38
23
  prerelease: false
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 0.9.12
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '3.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: pry
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
44
36
  type: :development
45
- version_requirements: *id003
46
- - !ruby/object:Gem::Dependency
47
- name: rake
48
37
  prerelease: false
49
- requirement: &id004 !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: "0.8"
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.8'
54
50
  - - ">="
55
- - !ruby/object:Gem::Version
51
+ - !ruby/object:Gem::Version
56
52
  version: 0.8.7
57
53
  type: :development
58
- version_requirements: *id004
59
- description: This is fork of Tony Pitluga's Ruby API for keepassx with read-write support.
60
- email:
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.8'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.8.7
63
+ description: This is fork of Tony Pitluga's Ruby API for keepassx with read-write
64
+ support.
65
+ email:
61
66
  - tony.pitluga@gmail.com
62
67
  - paul.t.hinze@gmail.com
63
- - tio.teath@gmail.com
68
+ - tioteath@gmail.com
64
69
  executables: []
65
-
66
70
  extensions: []
67
-
68
71
  extra_rdoc_files: []
69
-
70
- files:
71
- - .coveralls.yml
72
- - .gitignore
73
- - .rvmrc
74
- - .travis.yml
72
+ files:
73
+ - ".coveralls.yml"
74
+ - ".gitignore"
75
+ - ".travis.yml"
75
76
  - Gemfile
76
77
  - README.md
77
78
  - Rakefile
@@ -97,30 +98,26 @@ files:
97
98
  - spec/spec_helper.rb
98
99
  homepage: https://github.com/tioteath/ruby-keepassx.git
99
100
  licenses: []
100
-
101
101
  metadata: {}
102
-
103
102
  post_install_message:
104
103
  rdoc_options: []
105
-
106
- require_paths:
104
+ require_paths:
107
105
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
109
- requirements:
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
110
113
  - - ">="
111
- - !ruby/object:Gem::Version
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">"
116
- - !ruby/object:Gem::Version
117
- version: 1.3.1
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
118
116
  requirements: []
119
-
120
117
  rubyforge_project:
121
- rubygems_version: 2.0.14
118
+ rubygems_version: 2.2.2
122
119
  signing_key:
123
120
  specification_version: 4
124
121
  summary: Ruby API access for KeePassX databases
125
122
  test_files: []
126
-
123
+ has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm ruby-1.8.7@keepassx --create