ruby_gpg2 0.9.0.pre.4 → 0.9.0.pre.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +37 -2
  4. data/LICENSE.txt +1 -1
  5. data/Rakefile +83 -46
  6. data/bin/console +4 -3
  7. data/lib/ruby_gpg2/colon_output.rb +61 -42
  8. data/lib/ruby_gpg2/colon_record.rb +257 -222
  9. data/lib/ruby_gpg2/commands/base.rb +9 -13
  10. data/lib/ruby_gpg2/commands/decrypt.rb +3 -2
  11. data/lib/ruby_gpg2/commands/encrypt.rb +3 -2
  12. data/lib/ruby_gpg2/commands/export.rb +2 -0
  13. data/lib/ruby_gpg2/commands/export_secret_keys.rb +2 -0
  14. data/lib/ruby_gpg2/commands/generate_key.rb +5 -1
  15. data/lib/ruby_gpg2/commands/import.rb +2 -0
  16. data/lib/ruby_gpg2/commands/list_public_keys.rb +3 -2
  17. data/lib/ruby_gpg2/commands/list_secret_keys.rb +3 -2
  18. data/lib/ruby_gpg2/commands/mixins/armor_config.rb +2 -0
  19. data/lib/ruby_gpg2/commands/mixins/batch_config.rb +2 -0
  20. data/lib/ruby_gpg2/commands/mixins/colon_config.rb +2 -0
  21. data/lib/ruby_gpg2/commands/mixins/global_config.rb +7 -2
  22. data/lib/ruby_gpg2/commands/mixins/input_config.rb +2 -0
  23. data/lib/ruby_gpg2/commands/mixins/output_config.rb +7 -2
  24. data/lib/ruby_gpg2/commands/mixins/passphrase_config.rb +7 -2
  25. data/lib/ruby_gpg2/commands/mixins/pinentry_config.rb +7 -2
  26. data/lib/ruby_gpg2/commands/mixins/recipient_config.rb +7 -2
  27. data/lib/ruby_gpg2/commands/mixins/status_config.rb +7 -2
  28. data/lib/ruby_gpg2/commands/mixins/trust_mode_config.rb +7 -2
  29. data/lib/ruby_gpg2/commands/mixins/with_captured_output.rb +10 -5
  30. data/lib/ruby_gpg2/commands/mixins/with_captured_status.rb +11 -7
  31. data/lib/ruby_gpg2/commands/mixins/with_result.rb +2 -0
  32. data/lib/ruby_gpg2/commands/mixins/without_passphrase.rb +8 -3
  33. data/lib/ruby_gpg2/commands/result.rb +3 -3
  34. data/lib/ruby_gpg2/commands.rb +3 -2
  35. data/lib/ruby_gpg2/key.rb +34 -25
  36. data/lib/ruby_gpg2/parameter_file_contents.rb +101 -51
  37. data/lib/ruby_gpg2/status_line.rb +15 -12
  38. data/lib/ruby_gpg2/status_lines/import_ok.rb +29 -25
  39. data/lib/ruby_gpg2/status_lines/import_problem.rb +19 -15
  40. data/lib/ruby_gpg2/status_lines/imported.rb +13 -9
  41. data/lib/ruby_gpg2/status_lines/key_considered.rb +18 -14
  42. data/lib/ruby_gpg2/status_lines/key_created.rb +20 -16
  43. data/lib/ruby_gpg2/status_lines/unimplemented.rb +6 -3
  44. data/lib/ruby_gpg2/status_lines.rb +2 -1
  45. data/lib/ruby_gpg2/status_output.rb +2 -0
  46. data/lib/ruby_gpg2/user_id.rb +19 -16
  47. data/lib/ruby_gpg2/version.rb +3 -1
  48. data/lib/ruby_gpg2.rb +2 -0
  49. data/ruby_gpg2.gemspec +55 -0
  50. metadata +64 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1759342b199d0e3001c3350feb47c8df3c930f01eec4f4633688346a33f3921d
4
- data.tar.gz: 19b9fe9ce72f4bb9eaf88ebcaff279a1dac937c7fbd1fdacb8890d3eef8e6d7a
3
+ metadata.gz: 2531cddbc871f900657cd40fbc035ea101500582bea37de304c5bfd47ede4867
4
+ data.tar.gz: e6786466c2de24986cab0a5ea22c3d14de60b994398f5e3fd8cb9c9578c6d140
5
5
  SHA512:
6
- metadata.gz: bcaa1aca6ba8994e3f1a4a8e36f7732eba47b88cc24251e267350c84ffda0ecfa835e0bacdca451cf797dda0bd131d77890f55fea87d8c2df71621cc17aaf368
7
- data.tar.gz: 8ee8d3fcff5b066fc865789fa31853f93a70facd6576dc6137933f3e8f391fc39192a02de37b5cc1299a606bfb2e4084fa29eb8e369636a7043bbecb9e57900e
6
+ metadata.gz: 2cfb2c57af9082de8c5eb3a45c33c63da764ab77e4163819a58ae209c809030b5a61ad108d4ab33a7d14d2d7bda33d0ea67696c558f968f83f56fb2f323c3be7
7
+ data.tar.gz: 4897050c6975b5ba2944ef8df26ba9d4f2a25c8759f7a481d69af40c41bbf121ffbd1376a85f9dcb7534530de12d00665826b617bf7db20d7e89831ce61fd244
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.4)
4
+ ruby_gpg2 (0.9.0.pre.7)
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)
@@ -55,7 +57,11 @@ GEM
55
57
  faraday (>= 0.9)
56
58
  sawyer (~> 0.8.0, >= 0.5.3)
57
59
  open4 (1.3.4)
60
+ parallel (1.22.1)
61
+ parser (3.1.1.0)
62
+ ast (~> 2.4.1)
58
63
  public_suffix (4.0.6)
64
+ rainbow (3.1.1)
59
65
  rake (13.0.6)
60
66
  rake_circle_ci (0.9.0)
61
67
  colored2 (~> 3.1)
@@ -77,6 +83,8 @@ GEM
77
83
  colored2 (~> 3.1)
78
84
  rake_factory (~> 0.23)
79
85
  sshkey (~> 2.0)
86
+ regexp_parser (2.2.1)
87
+ rexml (3.2.5)
80
88
  rspec (3.11.0)
81
89
  rspec-core (~> 3.11.0)
82
90
  rspec-expectations (~> 3.11.0)
@@ -90,13 +98,36 @@ GEM
90
98
  diff-lcs (>= 1.2.0, < 2.0)
91
99
  rspec-support (~> 3.11.0)
92
100
  rspec-support (3.11.0)
101
+ rubocop (1.27.0)
102
+ parallel (~> 1.10)
103
+ parser (>= 3.1.0.0)
104
+ rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8, < 3.0)
106
+ rexml
107
+ rubocop-ast (>= 1.16.0, < 2.0)
108
+ ruby-progressbar (~> 1.7)
109
+ unicode-display_width (>= 1.4.0, < 3.0)
110
+ rubocop-ast (1.16.0)
111
+ parser (>= 3.1.1.0)
112
+ rubocop-rake (0.6.0)
113
+ rubocop (~> 1.0)
114
+ rubocop-rspec (2.9.0)
115
+ rubocop (~> 1.19)
116
+ ruby-progressbar (1.11.0)
93
117
  ruby2_keywords (0.0.5)
94
118
  sawyer (0.8.2)
95
119
  addressable (>= 2.3.5)
96
120
  faraday (> 0.8, < 2.0)
121
+ simplecov (0.21.2)
122
+ docile (~> 1.1)
123
+ simplecov-html (~> 0.11)
124
+ simplecov_json_formatter (~> 0.1)
125
+ simplecov-html (0.12.3)
126
+ simplecov_json_formatter (0.1.4)
97
127
  sshkey (2.0.0)
98
128
  tzinfo (2.0.4)
99
129
  concurrent-ruby (~> 1.0)
130
+ unicode-display_width (2.1.0)
100
131
 
101
132
  PLATFORMS
102
133
  ruby
@@ -112,7 +143,11 @@ DEPENDENCIES
112
143
  rake_gpg
113
144
  rake_ssh
114
145
  rspec
146
+ rubocop
147
+ rubocop-rake
148
+ rubocop-rspec
115
149
  ruby_gpg2!
150
+ simplecov
116
151
 
117
152
  BUNDLED WITH
118
- 2.3.9
153
+ 2.3.11
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 InfraBlocks
3
+ Copyright (c) 2022 InfraBlocks Maintainers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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