ruby_gpg2 0.1.0.pre.14 → 0.1.0.pre.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88a08063c06520ca410cd2f9c97cd630b9b3aa6bf6f8c85d9bf119b12776d2c7
4
- data.tar.gz: 6592f3a48800dad1f99e7ba1700abf3bb50ba143ef2901209a9fd06264cc240e
3
+ metadata.gz: 757eba52ef88c96af2b0c2be9199ca3365e7e90e1e49485f57fa5c417614df26
4
+ data.tar.gz: 6b8cea9b6c702051eea538d54adf389c1a50b62badbeb61a2c5f79da617f90e1
5
5
  SHA512:
6
- metadata.gz: f8bb60f31f214609daac36c04ede22f5c4d72ad2872a82023ab01271cae77e7da0ab06ed253d0b933c9915070d22aa638103df7cbb04dfb494a956727b674c88
7
- data.tar.gz: 6867a2278de034eedfd79f946593f7b04229f8f0c07d3cc3a6e63172367a78395a6cc3c173cb10d099956ebb224b8cf52fbb665fa716f3b5919e7c90e3fe1132
6
+ metadata.gz: 9e8cf2702299459f76054d7bba1e2cf6ae70771a02c33000d2e13e13e584bc35ab0e4f6129e902e8c925809bca072c36aee5393e56af68969dfc4e4bfd56ac06
7
+ data.tar.gz: c80831abc24ac65fbafd690393d07ebed189a9d10b32f4b1a2e3900f897007f8702fb8931bc2a80306d0e15e83de4ef212055e96dad505764df1eab59916c539
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_gpg2 (0.1.0.pre.14)
4
+ ruby_gpg2 (0.1.0.pre.15)
5
5
  lino (= 1.3.0)
6
6
 
7
7
  GEM
@@ -14,13 +14,15 @@ module RubyGPG2
14
14
  builder = instantiate_builder
15
15
 
16
16
  do_before(opts)
17
- builder = configure_command(builder, opts)
18
- builder
19
- .build
20
- .execute(
21
- stdin: stdin,
22
- stdout: stdout,
23
- stderr: stderr)
17
+ do_around(opts) do |updated_opts|
18
+ builder = configure_command(builder, updated_opts)
19
+ builder
20
+ .build
21
+ .execute(
22
+ stdin: stdin,
23
+ stdout: stdout,
24
+ stderr: stderr)
25
+ end
24
26
  do_after(opts)
25
27
  end
26
28
 
@@ -41,6 +43,10 @@ module RubyGPG2
41
43
  builder
42
44
  end
43
45
 
46
+ def do_around(opts)
47
+ yield opts
48
+ end
49
+
44
50
  def do_after(opts)
45
51
  end
46
52
  end
@@ -6,6 +6,8 @@ require_relative 'mixins/batch_config'
6
6
  require_relative 'mixins/passphrase_config'
7
7
  require_relative 'mixins/pinentry_config'
8
8
  require_relative 'mixins/status_config'
9
+ require_relative 'mixins/with_result'
10
+ require_relative 'mixins/with_captured_status'
9
11
  require_relative 'mixins/without_passphrase'
10
12
 
11
13
  module RubyGPG2
@@ -16,6 +18,8 @@ module RubyGPG2
16
18
  include Mixins::PassphraseConfig
17
19
  include Mixins::PinentryConfig
18
20
  include Mixins::StatusConfig
21
+ include Mixins::WithResult
22
+ include Mixins::WithCapturedStatus
19
23
  include Mixins::WithoutPassphrase
20
24
 
21
25
  def configure_command(builder, opts)
@@ -3,6 +3,7 @@ require 'lino'
3
3
  require_relative 'base'
4
4
  require_relative 'mixins/global_config'
5
5
  require_relative 'mixins/colon_config'
6
+ require_relative 'mixins/with_result'
6
7
  require_relative 'mixins/with_captured_output'
7
8
 
8
9
  module RubyGPG2
@@ -10,6 +11,7 @@ module RubyGPG2
10
11
  class ListPublicKeys < Base
11
12
  include Mixins::GlobalConfig
12
13
  include Mixins::ColonConfig
14
+ include Mixins::WithResult
13
15
  include Mixins::WithCapturedOutput
14
16
 
15
17
  def configure_command(builder, opts)
@@ -17,10 +19,6 @@ module RubyGPG2
17
19
  builder = super(builder, opts)
18
20
  builder
19
21
  end
20
-
21
- def do_after(opts)
22
- super(opts.merge(output_method: :public_keys))
23
- end
24
22
  end
25
23
  end
26
24
  end
@@ -3,6 +3,7 @@ require 'lino'
3
3
  require_relative 'base'
4
4
  require_relative 'mixins/global_config'
5
5
  require_relative 'mixins/colon_config'
6
+ require_relative 'mixins/with_result'
6
7
  require_relative 'mixins/with_captured_output'
7
8
 
8
9
  module RubyGPG2
@@ -10,6 +11,7 @@ module RubyGPG2
10
11
  class ListSecretKeys < Base
11
12
  include Mixins::GlobalConfig
12
13
  include Mixins::ColonConfig
14
+ include Mixins::WithResult
13
15
  include Mixins::WithCapturedOutput
14
16
 
15
17
  def configure_command(builder, opts)
@@ -17,10 +19,6 @@ module RubyGPG2
17
19
  builder = super(builder, opts)
18
20
  builder
19
21
  end
20
-
21
- def do_after(opts)
22
- super(opts.merge(output_method: :secret_keys))
23
- end
24
22
  end
25
23
  end
26
24
  end
@@ -12,11 +12,10 @@ module RubyGPG2
12
12
 
13
13
  def do_after(opts)
14
14
  parse_output = opts[:parse_output].nil? ? true : opts[:parse_output]
15
- output_method = opts[:output_method]
16
-
17
- parse_output ?
18
- ColonOutput.parse(stdout.string).send(output_method) :
19
- stdout.string
15
+ super(opts.merge(
16
+ output: parse_output ?
17
+ ColonOutput.parse(stdout.string) :
18
+ stdout.string))
20
19
  end
21
20
  end
22
21
  end
@@ -0,0 +1,31 @@
1
+ require 'tempfile'
2
+
3
+ require_relative '../../status_output'
4
+
5
+ module RubyGPG2
6
+ module Commands
7
+ module Mixins
8
+ module WithCapturedStatus
9
+ def do_around(opts)
10
+ if opts[:with_status]
11
+ Tempfile.create do |f|
12
+ yield opts.merge(status_file: f.path)
13
+ @status = File.read(f.path)
14
+ end
15
+ else
16
+ yield opts
17
+ end
18
+ end
19
+
20
+ def do_after(opts)
21
+ if opts[:with_status]
22
+ super(opts.merge(
23
+ status: StatusOutput.parse(@status)))
24
+ else
25
+ super(opts)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'stringio'
2
+
3
+ module RubyGPG2
4
+ module Commands
5
+ module Mixins
6
+ module WithResult
7
+ class Result < Struct.new(:output, :status)
8
+ end
9
+
10
+ def do_after(opts)
11
+ result = Result.new
12
+ result.output = opts[:output] if opts[:output]
13
+ result.status = opts[:status] if opts[:status]
14
+ result
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,140 @@
1
+ module RubyGPG2
2
+ class StatusLine
3
+ class KeyCreated
4
+ KEY_TYPES = {
5
+ 'B' => :primary_and_subkey,
6
+ 'P' => :primary,
7
+ 'S' => :subkey
8
+ }
9
+
10
+ def self.parse(line)
11
+ match = line.match(/^\[GNUPG:\] KEY_CREATED (.) (.*?)(?: (.*))?$/)
12
+ new(
13
+ raw: line,
14
+ key_type: KEY_TYPES[match[1]],
15
+ key_fingerprint: match[2],
16
+ handle: match[3])
17
+ end
18
+
19
+ attr_reader(
20
+ :raw,
21
+ :key_type,
22
+ :key_fingerprint,
23
+ :handle)
24
+
25
+ def initialize(opts)
26
+ @raw = opts[:raw]
27
+ @key_type = opts[:key_type]
28
+ @key_fingerprint = opts[:key_fingerprint]
29
+ @handle = opts[:handle]
30
+ end
31
+
32
+ def type
33
+ :key_created
34
+ end
35
+
36
+ def ==(other)
37
+ other.class == self.class && other.state == state
38
+ end
39
+
40
+ protected
41
+
42
+ def state
43
+ [
44
+ @raw,
45
+ @key_type,
46
+ @key_fingerprint
47
+ ]
48
+ end
49
+ end
50
+
51
+ class KeyConsidered
52
+ FLAGS = {
53
+ '0' => [],
54
+ '1' => [:key_not_selected],
55
+ '2' => [:all_subkeys_expired_or_revoked]
56
+ }
57
+
58
+ def self.parse(line)
59
+ match = line.match(/^\[GNUPG:\] KEY_CONSIDERED (.*) (.*)$/)
60
+ new(
61
+ raw: line,
62
+ key_fingerprint: match[1],
63
+ flags: FLAGS[match[2]])
64
+ end
65
+
66
+ attr_reader(
67
+ :raw,
68
+ :key_fingerprint,
69
+ :flags)
70
+
71
+ def initialize(opts)
72
+ @raw = opts[:raw]
73
+ @key_fingerprint = opts[:key_fingerprint]
74
+ @flags = opts[:flags]
75
+ end
76
+
77
+ def type
78
+ :key_considered
79
+ end
80
+
81
+ def ==(other)
82
+ other.class == self.class && other.state == state
83
+ end
84
+
85
+ protected
86
+
87
+ def state
88
+ [
89
+ @raw,
90
+ @key_fingerprint,
91
+ @flags
92
+ ]
93
+ end
94
+ end
95
+
96
+ class Unimplemented
97
+ def self.parse(line)
98
+ new(raw: line)
99
+ end
100
+
101
+ attr_reader(
102
+ :raw)
103
+
104
+ def initialize(opts)
105
+ @raw = opts[:raw]
106
+ end
107
+
108
+ def type
109
+ :unknown
110
+ end
111
+
112
+ def ==(other)
113
+ other.class == self.class && other.state == state
114
+ end
115
+
116
+ protected
117
+
118
+ def state
119
+ [
120
+ @raw
121
+ ]
122
+ end
123
+ end
124
+
125
+ TYPE_REGEX = /^\[GNUPG:\] (.*?)(\s|$)/
126
+
127
+ TYPES = {
128
+ "KEY_CREATED" => KeyCreated,
129
+ "KEY_CONSIDERED" => KeyConsidered
130
+ }
131
+
132
+ def self.parse(line)
133
+ TYPES
134
+ .fetch(
135
+ line.match(TYPE_REGEX)[1],
136
+ Unimplemented)
137
+ .parse(line)
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'status_line'
2
+
3
+ module RubyGPG2
4
+ class StatusOutput
5
+ def self.parse(lines)
6
+ new(lines
7
+ .strip
8
+ .split("\n")
9
+ .collect { |line| StatusLine.parse(line) })
10
+ end
11
+
12
+ def initialize(lines)
13
+ @lines = lines
14
+ end
15
+
16
+ def ==(other)
17
+ other.class == self.class && other.state == state
18
+ end
19
+
20
+ protected
21
+
22
+ def state
23
+ [@lines]
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyGPG2
2
- VERSION = '0.1.0.pre.14'
2
+ VERSION = '0.1.0.pre.15'
3
3
  end
data/lib/ruby_gpg2.rb CHANGED
@@ -2,6 +2,7 @@ require 'ruby_gpg2/version'
2
2
  require 'ruby_gpg2/commands'
3
3
  require 'ruby_gpg2/parameter_file_contents'
4
4
  require 'ruby_gpg2/colon_output'
5
+ require 'ruby_gpg2/status_output'
5
6
  require 'ruby_gpg2/key'
6
7
  require 'ruby_gpg2/user_id'
7
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_gpg2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.14
4
+ version: 0.1.0.pre.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-02 00:00:00.000000000 Z
11
+ date: 2020-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lino
@@ -173,9 +173,13 @@ files:
173
173
  - lib/ruby_gpg2/commands/mixins/pinentry_config.rb
174
174
  - lib/ruby_gpg2/commands/mixins/status_config.rb
175
175
  - lib/ruby_gpg2/commands/mixins/with_captured_output.rb
176
+ - lib/ruby_gpg2/commands/mixins/with_captured_status.rb
177
+ - lib/ruby_gpg2/commands/mixins/with_result.rb
176
178
  - lib/ruby_gpg2/commands/mixins/without_passphrase.rb
177
179
  - lib/ruby_gpg2/key.rb
178
180
  - lib/ruby_gpg2/parameter_file_contents.rb
181
+ - lib/ruby_gpg2/status_line.rb
182
+ - lib/ruby_gpg2/status_output.rb
179
183
  - lib/ruby_gpg2/user_id.rb
180
184
  - lib/ruby_gpg2/version.rb
181
185
  - ruby_gpg2.gemspec