ruby_gpg2 0.9.0.pre.6 → 0.9.0.pre.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +50 -13
  4. data/Rakefile +83 -46
  5. data/bin/console +4 -3
  6. data/lib/ruby_gpg2/colon_output.rb +61 -42
  7. data/lib/ruby_gpg2/colon_record.rb +257 -222
  8. data/lib/ruby_gpg2/commands/base.rb +9 -13
  9. data/lib/ruby_gpg2/commands/decrypt.rb +3 -2
  10. data/lib/ruby_gpg2/commands/encrypt.rb +3 -2
  11. data/lib/ruby_gpg2/commands/export.rb +2 -0
  12. data/lib/ruby_gpg2/commands/export_secret_keys.rb +2 -0
  13. data/lib/ruby_gpg2/commands/generate_key.rb +5 -1
  14. data/lib/ruby_gpg2/commands/import.rb +2 -0
  15. data/lib/ruby_gpg2/commands/list_public_keys.rb +3 -2
  16. data/lib/ruby_gpg2/commands/list_secret_keys.rb +3 -2
  17. data/lib/ruby_gpg2/commands/mixins/armor_config.rb +2 -0
  18. data/lib/ruby_gpg2/commands/mixins/batch_config.rb +2 -0
  19. data/lib/ruby_gpg2/commands/mixins/colon_config.rb +2 -0
  20. data/lib/ruby_gpg2/commands/mixins/global_config.rb +7 -2
  21. data/lib/ruby_gpg2/commands/mixins/input_config.rb +2 -0
  22. data/lib/ruby_gpg2/commands/mixins/output_config.rb +7 -2
  23. data/lib/ruby_gpg2/commands/mixins/passphrase_config.rb +7 -2
  24. data/lib/ruby_gpg2/commands/mixins/pinentry_config.rb +7 -2
  25. data/lib/ruby_gpg2/commands/mixins/recipient_config.rb +7 -2
  26. data/lib/ruby_gpg2/commands/mixins/status_config.rb +7 -2
  27. data/lib/ruby_gpg2/commands/mixins/trust_mode_config.rb +7 -2
  28. data/lib/ruby_gpg2/commands/mixins/with_captured_output.rb +10 -5
  29. data/lib/ruby_gpg2/commands/mixins/with_captured_status.rb +11 -7
  30. data/lib/ruby_gpg2/commands/mixins/with_result.rb +2 -0
  31. data/lib/ruby_gpg2/commands/mixins/without_passphrase.rb +8 -3
  32. data/lib/ruby_gpg2/commands/result.rb +3 -3
  33. data/lib/ruby_gpg2/commands.rb +3 -2
  34. data/lib/ruby_gpg2/key.rb +34 -25
  35. data/lib/ruby_gpg2/parameter_file_contents.rb +101 -51
  36. data/lib/ruby_gpg2/status_line.rb +15 -12
  37. data/lib/ruby_gpg2/status_lines/import_ok.rb +29 -25
  38. data/lib/ruby_gpg2/status_lines/import_problem.rb +19 -15
  39. data/lib/ruby_gpg2/status_lines/imported.rb +13 -9
  40. data/lib/ruby_gpg2/status_lines/key_considered.rb +18 -14
  41. data/lib/ruby_gpg2/status_lines/key_created.rb +20 -16
  42. data/lib/ruby_gpg2/status_lines/unimplemented.rb +6 -3
  43. data/lib/ruby_gpg2/status_lines.rb +2 -1
  44. data/lib/ruby_gpg2/status_output.rb +2 -0
  45. data/lib/ruby_gpg2/user_id.rb +19 -16
  46. data/lib/ruby_gpg2/version.rb +3 -1
  47. data/lib/ruby_gpg2.rb +2 -0
  48. data/ruby_gpg2.gemspec +55 -0
  49. metadata +64 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9e9aa65d09e0c2ff96293d9c4e471d6b27f6ae7ac685983d0f32b13834e25dd
4
- data.tar.gz: 78a4f4b96f5d3f4e60b5207d18ffc2043f6e294b745c1bd92f285a2e5e3b20b9
3
+ metadata.gz: 86180f572ec3516241ca3936a4582e273d8266a468b079f2314a6e1347f50b31
4
+ data.tar.gz: 0270a66ce88048a7fa9310e8bc52e135d714480d6d4b2ea54e6d6565b772d762
5
5
  SHA512:
6
- metadata.gz: c9a4148ea696ae8c76a54cb74793853d2cfc311901b91f1dffb867f39759013d0720e408ca64d3dfacab9009a1cf075ef39ce01765f16c8a04f2ae2cdd5e804d
7
- data.tar.gz: 89b9119e28d20df5c3718211c0bf2a237d14e7250026b42a6f6da4a85e3716a1567ff5975484e2f5a4b1b5649336e8ce7625b104bc729ca48486868b9aab636a
6
+ metadata.gz: 55e913960b488d2312f5c83565bbaf38a50ae2ea365f14f165c78da2a69cac351313cb1dff4c29690549ceb015ee42861aa679a6d7acfc830296c179f377c9ae
7
+ data.tar.gz: 5d7c2f9230a54d0df003c5771fa849a0ae6becdc7df9dbf881d6b1b60e7ac3035575990caddb61140bf37def0eef70b1fc0e9bb046b741e6f038e1b9bfafe919
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in ruby_fly.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_gpg2 (0.9.0.pre.6)
4
+ ruby_gpg2 (0.9.0.pre.8)
5
5
  lino (~> 3.0)
6
6
 
7
7
  GEM
@@ -14,9 +14,11 @@ GEM
14
14
  tzinfo (~> 2.0)
15
15
  addressable (2.8.0)
16
16
  public_suffix (>= 2.0.2, < 5.0)
17
+ ast (2.4.2)
17
18
  colored2 (3.1.2)
18
19
  concurrent-ruby (1.1.9)
19
20
  diff-lcs (1.5.0)
21
+ docile (1.4.0)
20
22
  excon (0.92.0)
21
23
  faraday (1.10.0)
22
24
  faraday-em_http (~> 1.0)
@@ -46,6 +48,7 @@ GEM
46
48
  concurrent-ruby (~> 1.0)
47
49
  i18n (1.10.0)
48
50
  concurrent-ruby (~> 1.0)
51
+ json (2.6.2)
49
52
  lino (3.0.0)
50
53
  hamster (~> 3.0)
51
54
  open4 (~> 1.3)
@@ -55,7 +58,11 @@ GEM
55
58
  faraday (>= 0.9)
56
59
  sawyer (~> 0.8.0, >= 0.5.3)
57
60
  open4 (1.3.4)
61
+ parallel (1.22.1)
62
+ parser (3.1.2.1)
63
+ ast (~> 2.4.1)
58
64
  public_suffix (4.0.6)
65
+ rainbow (3.1.1)
59
66
  rake (13.0.6)
60
67
  rake_circle_ci (0.9.0)
61
68
  colored2 (~> 3.1)
@@ -77,26 +84,52 @@ GEM
77
84
  colored2 (~> 3.1)
78
85
  rake_factory (~> 0.23)
79
86
  sshkey (~> 2.0)
80
- rspec (3.11.0)
81
- rspec-core (~> 3.11.0)
82
- rspec-expectations (~> 3.11.0)
83
- rspec-mocks (~> 3.11.0)
84
- rspec-core (3.11.0)
85
- rspec-support (~> 3.11.0)
86
- rspec-expectations (3.11.0)
87
+ regexp_parser (2.6.0)
88
+ rexml (3.2.5)
89
+ rspec (3.12.0)
90
+ rspec-core (~> 3.12.0)
91
+ rspec-expectations (~> 3.12.0)
92
+ rspec-mocks (~> 3.12.0)
93
+ rspec-core (3.12.0)
94
+ rspec-support (~> 3.12.0)
95
+ rspec-expectations (3.12.0)
87
96
  diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.11.0)
89
- rspec-mocks (3.11.0)
97
+ rspec-support (~> 3.12.0)
98
+ rspec-mocks (3.12.0)
90
99
  diff-lcs (>= 1.2.0, < 2.0)
91
- rspec-support (~> 3.11.0)
92
- rspec-support (3.11.0)
100
+ rspec-support (~> 3.12.0)
101
+ rspec-support (3.12.0)
102
+ rubocop (1.37.1)
103
+ json (~> 2.3)
104
+ parallel (~> 1.10)
105
+ parser (>= 3.1.2.1)
106
+ rainbow (>= 2.2.2, < 4.0)
107
+ regexp_parser (>= 1.8, < 3.0)
108
+ rexml (>= 3.2.5, < 4.0)
109
+ rubocop-ast (>= 1.23.0, < 2.0)
110
+ ruby-progressbar (~> 1.7)
111
+ unicode-display_width (>= 1.4.0, < 3.0)
112
+ rubocop-ast (1.23.0)
113
+ parser (>= 3.1.1.0)
114
+ rubocop-rake (0.6.0)
115
+ rubocop (~> 1.0)
116
+ rubocop-rspec (2.14.2)
117
+ rubocop (~> 1.33)
118
+ ruby-progressbar (1.11.0)
93
119
  ruby2_keywords (0.0.5)
94
120
  sawyer (0.8.2)
95
121
  addressable (>= 2.3.5)
96
122
  faraday (> 0.8, < 2.0)
123
+ simplecov (0.21.2)
124
+ docile (~> 1.1)
125
+ simplecov-html (~> 0.11)
126
+ simplecov_json_formatter (~> 0.1)
127
+ simplecov-html (0.12.3)
128
+ simplecov_json_formatter (0.1.4)
97
129
  sshkey (2.0.0)
98
130
  tzinfo (2.0.4)
99
131
  concurrent-ruby (~> 1.0)
132
+ unicode-display_width (2.3.0)
100
133
 
101
134
  PLATFORMS
102
135
  ruby
@@ -112,7 +145,11 @@ DEPENDENCIES
112
145
  rake_gpg
113
146
  rake_ssh
114
147
  rspec
148
+ rubocop
149
+ rubocop-rake
150
+ rubocop-rspec
115
151
  ruby_gpg2!
152
+ simplecov
116
153
 
117
154
  BUNDLED WITH
118
- 2.3.9
155
+ 2.3.24
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'rake_circle_ci'
3
5
  require 'rake_github'
@@ -5,17 +7,26 @@ require 'rake_ssh'
5
7
  require 'rake_gpg'
6
8
  require 'securerandom'
7
9
  require 'rspec/core/rake_task'
10
+ require 'rubocop/rake_task'
8
11
 
9
- task :default => :spec
10
-
11
- RSpec::Core::RakeTask.new(:spec)
12
+ task default: %i[
13
+ library:fix
14
+ test:unit
15
+ ]
12
16
 
13
17
  namespace :encryption do
18
+ namespace :directory do
19
+ desc 'Ensure CI secrets directory exists.'
20
+ task :ensure do
21
+ FileUtils.mkdir_p('config/secrets/ci')
22
+ end
23
+ end
24
+
14
25
  namespace :passphrase do
15
- task :generate do
16
- File.open('config/secrets/ci/encryption.passphrase', 'w') do |f|
17
- f.write(SecureRandom.base64(36))
18
- end
26
+ desc 'Generate encryption passphrase used by CI.'
27
+ task generate: ['directory:ensure'] do
28
+ File.write('config/secrets/ci/encryption.passphrase',
29
+ SecureRandom.base64(36))
19
30
  end
20
31
  end
21
32
  end
@@ -23,85 +34,111 @@ end
23
34
  namespace :keys do
24
35
  namespace :deploy do
25
36
  RakeSSH.define_key_tasks(
26
- path: 'config/secrets/ci/',
27
- comment: 'maintainers@infrablocks.io')
37
+ path: 'config/secrets/ci/',
38
+ comment: 'maintainers@infrablocks.io'
39
+ )
28
40
  end
29
41
 
30
42
  namespace :gpg do
31
43
  RakeGPG.define_generate_key_task(
32
- output_directory: 'config/secrets/ci',
33
- name_prefix: 'gpg',
34
- owner_name: 'InfraBlocks Maintainers',
35
- owner_email: 'maintainers@infrablocks.io',
36
- owner_comment: 'ruby_gpg2 CI Key')
44
+ output_directory: 'config/secrets/ci',
45
+ name_prefix: 'gpg',
46
+ owner_name: 'InfraBlocks Maintainers',
47
+ owner_email: 'maintainers@infrablocks.io',
48
+ owner_comment: 'ruby_gpg2 CI Key'
49
+ )
37
50
  end
38
51
  end
39
52
 
53
+ namespace :secrets do
54
+ desc 'Regenerate all generatable secrets.'
55
+ task regenerate: %w[
56
+ encryption:passphrase:generate
57
+ keys:deploy:generate
58
+ keys:gpg:generate
59
+ ]
60
+ end
61
+
62
+ RuboCop::RakeTask.new
63
+
64
+ namespace :library do
65
+ desc 'Run all checks of the library'
66
+ task check: [:rubocop]
67
+
68
+ desc 'Attempt to automatically fix issues with the library'
69
+ task fix: [:'rubocop:auto_correct']
70
+ end
71
+
72
+ namespace :test do
73
+ RSpec::Core::RakeTask.new(:unit)
74
+ end
75
+
40
76
  RakeCircleCI.define_project_tasks(
41
- namespace: :circle_ci,
42
- project_slug: 'github/infrablocks/ruby_gpg2'
77
+ namespace: :circle_ci,
78
+ project_slug: 'github/infrablocks/ruby_gpg2'
43
79
  ) do |t|
44
80
  circle_ci_config =
45
- YAML.load_file('config/secrets/circle_ci/config.yaml')
81
+ YAML.load_file('config/secrets/circle_ci/config.yaml')
46
82
 
47
- t.api_token = circle_ci_config["circle_ci_api_token"]
83
+ t.api_token = circle_ci_config['circle_ci_api_token']
48
84
  t.environment_variables = {
49
- ENCRYPTION_PASSPHRASE:
50
- File.read('config/secrets/ci/encryption.passphrase')
51
- .chomp
85
+ ENCRYPTION_PASSPHRASE:
86
+ File.read('config/secrets/ci/encryption.passphrase')
87
+ .chomp
52
88
  }
53
89
  t.checkout_keys = []
54
90
  t.ssh_keys = [
55
- {
56
- hostname: "github.com",
57
- private_key: File.read('config/secrets/ci/ssh.private')
58
- }
91
+ {
92
+ hostname: 'github.com',
93
+ private_key: File.read('config/secrets/ci/ssh.private')
94
+ }
59
95
  ]
60
96
  end
61
97
 
62
98
  RakeGithub.define_repository_tasks(
63
- namespace: :github,
64
- repository: 'infrablocks/ruby_gpg2',
99
+ namespace: :github,
100
+ repository: 'infrablocks/ruby_gpg2'
65
101
  ) do |t, args|
66
102
  github_config =
67
- YAML.load_file('config/secrets/github/config.yaml')
103
+ YAML.load_file('config/secrets/github/config.yaml')
68
104
 
69
- t.access_token = github_config["github_personal_access_token"]
105
+ t.access_token = github_config['github_personal_access_token']
70
106
  t.deploy_keys = [
71
- {
72
- title: 'CircleCI',
73
- public_key: File.read('config/secrets/ci/ssh.public')
74
- }
107
+ {
108
+ title: 'CircleCI',
109
+ public_key: File.read('config/secrets/ci/ssh.public')
110
+ }
75
111
  ]
76
112
  t.branch_name = args.branch_name
77
113
  t.commit_message = args.commit_message
78
114
  end
79
115
 
80
116
  namespace :pipeline do
81
- task :prepare => [
82
- :'circle_ci:project:follow',
83
- :'circle_ci:env_vars:ensure',
84
- :'circle_ci:checkout_keys:ensure',
85
- :'circle_ci:ssh_keys:ensure',
86
- :'github:deploy_keys:ensure'
117
+ desc 'Prepare CircleCI Pipeline'
118
+ task prepare: %i[
119
+ circle_ci:project:follow
120
+ circle_ci:env_vars:ensure
121
+ circle_ci:checkout_keys:ensure
122
+ circle_ci:ssh_keys:ensure
123
+ github:deploy_keys:ensure
87
124
  ]
88
125
  end
89
126
 
90
127
  namespace :version do
91
- desc "Bump version for specified type (pre, major, minor, patch)"
128
+ desc 'Bump version for specified type (pre, major, minor, patch)'
92
129
  task :bump, [:type] do |_, args|
93
130
  bump_version_for(args.type)
94
131
  end
95
132
  end
96
133
 
97
- desc "Release gem"
134
+ desc 'Release gem'
98
135
  task :release do
99
- sh "gem release --tag --push"
136
+ sh 'gem release --tag --push'
100
137
  end
101
138
 
102
139
  def bump_version_for(version_type)
103
- sh "gem bump --version #{version_type} " +
104
- "&& bundle install " +
105
- "&& export LAST_MESSAGE=\"$(git log -1 --pretty=%B)\" " +
106
- "&& git commit -a --amend -m \"${LAST_MESSAGE} [ci skip]\""
140
+ sh "gem bump --version #{version_type} " \
141
+ '&& bundle install ' \
142
+ '&& export LAST_MESSAGE="$(git log -1 --pretty=%B)" ' \
143
+ '&& git commit -a --amend -m "${LAST_MESSAGE} [ci skip]"'
107
144
  end
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "ruby_gpg2"
4
+ require 'bundler/setup'
5
+ require 'ruby_gpg2'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "ruby_gpg2"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './colon_record'
2
4
  require_relative './key'
3
5
 
@@ -5,9 +7,9 @@ module RubyGPG2
5
7
  class ColonOutput
6
8
  def self.parse(records)
7
9
  new(records
8
- .strip
9
- .split("\n")
10
- .collect { |record| ColonRecord.parse(record) })
10
+ .strip
11
+ .split("\n")
12
+ .collect { |record| ColonRecord.parse(record) })
11
13
  end
12
14
 
13
15
  def initialize(records)
@@ -16,12 +18,12 @@ module RubyGPG2
16
18
 
17
19
  def secret_keys
18
20
  group_by_type(:secret_key)
19
- .map { |record_group| extract_key(:secret, record_group) }
21
+ .map { |record_group| extract_key(:secret, record_group) }
20
22
  end
21
23
 
22
24
  def public_keys
23
25
  group_by_type(:public_key)
24
- .map { |record_group| extract_key(:public, record_group) }
26
+ .map { |record_group| extract_key(:public, record_group) }
25
27
  end
26
28
 
27
29
  def ==(other)
@@ -38,9 +40,9 @@ module RubyGPG2
38
40
 
39
41
  def indices_by_type(type)
40
42
  @records
41
- .each_with_index
42
- .collect { |record, index| record.type == type ? index : nil }
43
- .compact
43
+ .each_with_index
44
+ .collect { |record, index| record.type == type ? index : nil }
45
+ .compact
44
46
  end
45
47
 
46
48
  def group_by_type(type)
@@ -55,44 +57,61 @@ module RubyGPG2
55
57
  end
56
58
 
57
59
  def extract_key(type, record_group)
58
- records_in_group = record_group.count
59
60
  key_record = record_group[0]
61
+ fingerprint = extract_fingerprint(record_group)
62
+ user_ids = extract_user_ids(record_group)
63
+
64
+ make_key(type, key_record, fingerprint, user_ids)
65
+ end
66
+
67
+ def extract_user_ids(record_group)
68
+ user_id_records =
69
+ record_group
70
+ .drop_while { |r| !r.user_id_record? }
71
+ .take_while(&:user_id_record?)
72
+ user_id_records.map(&method(:make_user_id))
73
+ end
60
74
 
75
+ def extract_fingerprint(record_group)
76
+ records_in_group = record_group.count
61
77
  fingerprint_record =
62
- (records_in_group > 1 && record_group[1].fingerprint_record?) ?
63
- record_group[1] :
64
- nil
65
- fingerprint = fingerprint_record&.fingerprint
66
-
67
- user_id_records = record_group
68
- .drop_while { |r| !r.user_id_record? }
69
- .take_while { |r| r.user_id_record? }
70
- user_ids = user_id_records.map do |record|
71
- UserID.new(
72
- name: record.user_name,
73
- comment: record.user_comment,
74
- email: record.user_email,
75
- validity: record.validity,
76
- creation_date: record.creation_date,
77
- expiration_date: record.expiration_date,
78
- hash: record.user_id_hash,
79
- origin: record.origin)
80
- end
78
+ if records_in_group > 1 && record_group[1].fingerprint_record?
79
+ record_group[1]
80
+ end
81
+ fingerprint_record&.fingerprint
82
+ end
83
+
84
+ def make_user_id(record)
85
+ UserID.new(
86
+ name: record.user_name,
87
+ comment: record.user_comment,
88
+ email: record.user_email,
89
+ validity: record.validity,
90
+ creation_date: record.creation_date,
91
+ expiration_date: record.expiration_date,
92
+ hash: record.user_id_hash,
93
+ origin: record.origin
94
+ )
95
+ end
81
96
 
97
+ # rubocop:disable Metrics/MethodLength
98
+ def make_key(type, key_record, fingerprint, user_ids)
82
99
  Key.new(
83
- type: type,
84
- validity: key_record.validity,
85
- length: key_record.key_length,
86
- algorithm: key_record.key_algorithm,
87
- id: key_record.key_id,
88
- creation_date: key_record.creation_date,
89
- owner_trust: key_record.owner_trust,
90
- capabilities: key_record.key_capabilities,
91
- serial_number: key_record.serial_number,
92
- compliance_modes: key_record.compliance_modes,
93
- origin: key_record.origin,
94
- fingerprint: fingerprint,
95
- user_ids: user_ids)
100
+ type: type,
101
+ validity: key_record.validity,
102
+ length: key_record.key_length,
103
+ algorithm: key_record.key_algorithm,
104
+ id: key_record.key_id,
105
+ creation_date: key_record.creation_date,
106
+ owner_trust: key_record.owner_trust,
107
+ capabilities: key_record.key_capabilities,
108
+ serial_number: key_record.serial_number,
109
+ compliance_modes: key_record.compliance_modes,
110
+ origin: key_record.origin,
111
+ fingerprint: fingerprint,
112
+ user_ids: user_ids
113
+ )
96
114
  end
115
+ # rubocop:enable Metrics/MethodLength
97
116
  end
98
- end
117
+ end