gpg_status_parser 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.asc +11 -0
- data/LICENSE +31 -0
- data/Rakefile +8 -0
- data/lib/gpg_status_parser.rb +20 -0
- data/lib/gpg_status_parser/arguments.rb +152 -0
- data/lib/gpg_status_parser/status_codes.rb +81 -0
- data/lib/gpg_status_parser/status_message.rb +29 -0
- data/test/test_arguments.rb +15 -0
- data/test/test_main_api.rb +70 -0
- data/test/test_status_message.rb +132 -0
- metadata +58 -0
- metadata.gz.asc +11 -0
data.tar.gz.asc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
-----BEGIN PGP SIGNATURE-----
|
2
|
+
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
|
3
|
+
|
4
|
+
iQEcBAABCgAGBQJRICf6AAoJEP5F5V2hilTWNMkIALMlt98b/n67s6jlOA4P00ws
|
5
|
+
pyEII0ZznGMN8zIfFn+QpcLJ4N475Nd+ZdNza0M+ObbUXEGDASbsoEkFtjU3ycmz
|
6
|
+
1LyfujQcE41gJ2Od7x+LsqAMYP6IIiSEJlC7G4yUre2J7vYKw1manA2KarOR8J9U
|
7
|
+
BqE24DwLvRjYi4i3KXj4uS3AAymDvDrlKP6V1J59T3ZvfGwVMvWh0kdOJ320ZqNU
|
8
|
+
telIvyYn1zkGAZg3TC4Quoj619leFgdYAfLygGWmQePVAAxs+5dkl99+i3sF6nbl
|
9
|
+
bvKN4z5PK7gtLS4alIOpaF5IHY/NQUv4Fg+FP8gpyR47CoSbQeP7xSYrPROfPd4=
|
10
|
+
=jz+e
|
11
|
+
-----END PGP SIGNATURE-----
|
data/LICENSE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Copyright (c) 2013 Grant T. Olson
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the following
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
14
|
+
with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of the Grant T. Olson nor the names of
|
17
|
+
additional contributors may be used to endorse or promote
|
18
|
+
products derived from this software without specific prior
|
19
|
+
written permission.
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
27
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
29
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
30
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'gpg_status_parser/status_message'
|
2
|
+
|
3
|
+
module GPGStatusParser
|
4
|
+
|
5
|
+
# Parse a single line
|
6
|
+
def self.parse_line(line)
|
7
|
+
GPGStatusParser::StatusMessage.new(line.strip)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Takes a file or string and optional block and either yields or
|
11
|
+
# returns a list of status messages
|
12
|
+
def self.parse(file_or_string, &block)
|
13
|
+
if block
|
14
|
+
file_or_string.each_line { |line| yield parse_line(line)}
|
15
|
+
else
|
16
|
+
file_or_string.each_line.map{ |line| parse_line(line)}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module GPGStatusParser::Arguments
|
2
|
+
|
3
|
+
# Regexps to extract arguments should have two matchers, the actual
|
4
|
+
# argument value and the rest minus whitespace
|
5
|
+
NO_WHITESPACE = /([^\s]+)(.*)?/
|
6
|
+
USERNAME = /(.+)()$/
|
7
|
+
HEX = /([A-Z0-9]+)(.*)?/
|
8
|
+
NUMBER = /(\d+)(.*)?/
|
9
|
+
DATE = /(\d\d\d\d-\d\d-\d\d)(.*)?/
|
10
|
+
|
11
|
+
ARGUMENTS = {
|
12
|
+
:long_keyid_or_fpr => NO_WHITESPACE,
|
13
|
+
:username => USERNAME,
|
14
|
+
:keyid => NO_WHITESPACE,
|
15
|
+
:pkalgo => NO_WHITESPACE,
|
16
|
+
:hashalgo => NO_WHITESPACE,
|
17
|
+
:sig_class => NO_WHITESPACE,
|
18
|
+
:time => NO_WHITESPACE,
|
19
|
+
:rc => NO_WHITESPACE,
|
20
|
+
:args => NO_WHITESPACE,
|
21
|
+
:radix64_string => NO_WHITESPACE,
|
22
|
+
:sig_creation_date => DATE,
|
23
|
+
:sig_version => NUMBER,
|
24
|
+
:sig_timestamp => NUMBER,
|
25
|
+
:long_keyid => NO_WHITESPACE,
|
26
|
+
:keytype => NO_WHITESPACE,
|
27
|
+
:keylength => NO_WHITESPACE,
|
28
|
+
:mdc_method => NO_WHITESPACE,
|
29
|
+
:sym_algo => NO_WHITESPACE,
|
30
|
+
:algo => NO_WHITESPACE,
|
31
|
+
:hexdigits => NO_WHITESPACE,
|
32
|
+
:what => NO_WHITESPACE,
|
33
|
+
:filename => NO_WHITESPACE,
|
34
|
+
:long_keyid => NO_WHITESPACE,
|
35
|
+
:type => NO_WHITESPACE,
|
36
|
+
:pk_algo => NO_WHITESPACE,
|
37
|
+
:hash_algo => NUMBER,
|
38
|
+
:class => NO_WHITESPACE,
|
39
|
+
:timestamp => NO_WHITESPACE,
|
40
|
+
:keyfpr => NO_WHITESPACE,
|
41
|
+
:name => NO_WHITESPACE,
|
42
|
+
:string => NO_WHITESPACE,
|
43
|
+
:format => NO_WHITESPACE,
|
44
|
+
:length => NO_WHITESPACE,
|
45
|
+
:arguments => NO_WHITESPACE,
|
46
|
+
:flags => NO_WHITESPACE,
|
47
|
+
:len => NO_WHITESPACE,
|
48
|
+
:pubkey_algo => NUMBER,
|
49
|
+
:data => NO_WHITESPACE,
|
50
|
+
:reserved => NUMBER,
|
51
|
+
:expire_timestamp => NUMBER,
|
52
|
+
:long_keyid => HEX,
|
53
|
+
:fingerprint => HEX,
|
54
|
+
:primary_key_fpr => HEX,
|
55
|
+
:fingerprint_in_hex => HEX,
|
56
|
+
:handle => NO_WHITESPACE,
|
57
|
+
:error_token => NO_WHITESPACE,
|
58
|
+
:zero => /(0)(.*)/,
|
59
|
+
:validation_model => NO_WHITESPACE,
|
60
|
+
:mailbox => NO_WHITESPACE,
|
61
|
+
:long_main_keyid => NO_WHITESPACE,
|
62
|
+
:cipher_algo => NO_WHITESPACE,
|
63
|
+
:s2k_mode => NO_WHITESPACE,
|
64
|
+
:s2k_hash => NO_WHITESPACE,
|
65
|
+
:card_type => NO_WHITESPACE,
|
66
|
+
:chvno => NO_WHITESPACE,
|
67
|
+
:serialno => NO_WHITESPACE,
|
68
|
+
:user_ID => NO_WHITESPACE,
|
69
|
+
:reason => NO_WHITESPACE,
|
70
|
+
:code => NO_WHITESPACE,
|
71
|
+
:maxno => NO_WHITESPACE,
|
72
|
+
:error_location => NO_WHITESPACE,
|
73
|
+
:error_code => NO_WHITESPACE,
|
74
|
+
:more => NO_WHITESPACE,
|
75
|
+
:location => NO_WHITESPACE,
|
76
|
+
:reason_code => NO_WHITESPACE,
|
77
|
+
:char => NO_WHITESPACE,
|
78
|
+
:cur => NO_WHITESPACE,
|
79
|
+
:total => NO_WHITESPACE,
|
80
|
+
:fname => NO_WHITESPACE,
|
81
|
+
:pid => NO_WHITESPACE}
|
82
|
+
|
83
|
+
def self.extract_expected_argument argument_string
|
84
|
+
argument_string = argument_string.strip
|
85
|
+
|
86
|
+
return [nil, nil] if argument_string.empty?
|
87
|
+
|
88
|
+
optional = false
|
89
|
+
if argument_string[0] == "["
|
90
|
+
optional = true
|
91
|
+
argument_string = /[ ]*\[(.*)[ ]*\][ ]*$/.match(argument_string)[1]
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
matches = /<([^>]+)>(.*)/.match(argument_string)
|
96
|
+
|
97
|
+
# make ruby-friendly symbols
|
98
|
+
arg = matches[1].gsub(/[ -]/,"_")
|
99
|
+
arg = arg.intern
|
100
|
+
|
101
|
+
rest = matches[2]
|
102
|
+
|
103
|
+
result = [arg, rest]
|
104
|
+
result << :optional if optional
|
105
|
+
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.extract_expected_arguments argument_string
|
110
|
+
args = []
|
111
|
+
first, rest = extract_expected_argument(argument_string)
|
112
|
+
|
113
|
+
while (first || rest)
|
114
|
+
args << first
|
115
|
+
first, rest = extract_expected_argument(rest)
|
116
|
+
end
|
117
|
+
|
118
|
+
args
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.extract_argument_values expected_args, argument_value_string
|
122
|
+
return {} if expected_args.empty?
|
123
|
+
|
124
|
+
results = []
|
125
|
+
first, rest = expected_args[0], expected_args[1..-1]
|
126
|
+
|
127
|
+
while first
|
128
|
+
extract_re = ARGUMENTS[first]
|
129
|
+
match = extract_re.match(argument_value_string)
|
130
|
+
|
131
|
+
if match.nil?
|
132
|
+
results << ""
|
133
|
+
argument_value_string = ""
|
134
|
+
first = nil
|
135
|
+
rest = nil
|
136
|
+
else
|
137
|
+
results << match[1]
|
138
|
+
argument_value_string = match[2]
|
139
|
+
first, rest = rest[0], rest[1..-1]
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# raise "Acutal args didnt match expected" if expected_args.length != results.length
|
145
|
+
raise "Acutal args didnt match expected" if argument_value_string && argument_value_string.length > 0
|
146
|
+
|
147
|
+
# Delete unspecified optional args
|
148
|
+
args = Hash[expected_args.zip(results)]
|
149
|
+
args.delete_if {|key,val| val.nil? || val.empty?}
|
150
|
+
args
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module GPGStatusParser
|
2
|
+
STATUS_CODES = {
|
3
|
+
:NEWSIG => "",
|
4
|
+
:GOODSIG => "<long_keyid_or_fpr> <username>",
|
5
|
+
:EXPSIG => "<long_keyid_or_fpr> <username>",
|
6
|
+
:EXPKEYSIG => "<long_keyid_or_fpr> <username>",
|
7
|
+
:REVKEYSIG => "<long_keyid_or_fpr> <username>",
|
8
|
+
:BADSIG => "<long_keyid_or_fpr> <username>",
|
9
|
+
:ERRSIG => "<keyid> <pkalgo> <hashalgo> <sig_class> <time> <rc>",
|
10
|
+
:VALIDSIG => "<fingerprint_in_hex> <sig_creation_date> <sig-timestamp> <expire-timestamp> <sig-version> <reserved> <pubkey-algo> <hash-algo> <sig-class> [ <primary-key-fpr> ]",
|
11
|
+
:SIG_ID => "<radix64_string> <sig_creation_date> <sig-timestamp>",
|
12
|
+
:ENC_TO => "<long_keyid> <keytype> <keylength>",
|
13
|
+
:BEGIN_DECRYPTION => "",
|
14
|
+
:END_DECRYPTION => "",
|
15
|
+
:DECRYPTION_INFO => "<mdc_method> <sym_algo>",
|
16
|
+
:DECRYPTION_FAILED => "",
|
17
|
+
:DECRYPTION_OKAY => "",
|
18
|
+
:SESSION_KEY => "<algo>:<hexdigits>",
|
19
|
+
:BEGIN_ENCRYPTION => "<mdc_method> <sym_algo>",
|
20
|
+
:END_ENCRYPTION => "",
|
21
|
+
:FILE_START => "<what> <filename>",
|
22
|
+
:FILE_DONE => "",
|
23
|
+
:BEGIN_SIGNING => "",
|
24
|
+
:ALREADY_SIGNED => "<long-keyid>",
|
25
|
+
:SIG_CREATED => "<type> <pk_algo> <hash_algo> <class> <timestamp> <keyfpr>",
|
26
|
+
:NOTATION_NAME => "<name>",
|
27
|
+
:NOTATION_DATA => "<string>",
|
28
|
+
:POLICY_URL => "<string>",
|
29
|
+
:PLAINTEXT => "<format> <timestamp> <filename>",
|
30
|
+
:PLAINTEXT_LENGTH => "<length>",
|
31
|
+
:ATTRIBUTE => "<arguments>",
|
32
|
+
:SIG_SUBPACKET => "<type> <flags> <len> <data>",
|
33
|
+
:INV_RECP => "",
|
34
|
+
:INV_SGNR => "",
|
35
|
+
:NO_RECP => "<reserved>",
|
36
|
+
:NO_SGNR => "<reserved>",
|
37
|
+
:KEYEXPIRED => "<expire-timestamp>",
|
38
|
+
:KEYREVOKED => "",
|
39
|
+
:NO_PUBKEY => "<long keyid>",
|
40
|
+
:NO_SECKEY => "<long keyid>",
|
41
|
+
:KEY_CREATED => "<type> <fingerprint> [<handle>]",
|
42
|
+
:KEY_NOT_CREATED => "[<handle>]",
|
43
|
+
:TRUST_UNDEFINED => "<error_token>",
|
44
|
+
:TRUST_NEVER => "<error_token>",
|
45
|
+
:TRUST_MARGINAL => "[<zero> [<validation_model>]]",
|
46
|
+
:TRUST_FULLY => "[<zero> [<validation_model>]]",
|
47
|
+
:TRUST_ULTIMATE => "[<zero> [<validation_model>]]",
|
48
|
+
:PKA_TRUST_GOOD => "<mailbox>",
|
49
|
+
:PKA_TRUST_BAD => "<mailbox>",
|
50
|
+
:GET_BOOL => "",
|
51
|
+
:GET_LINE => "",
|
52
|
+
:GET_HIDDEN => "",
|
53
|
+
:GOT_IT => "",
|
54
|
+
:USERID_HINT => "<long main keyid> <string>",
|
55
|
+
:NEED_PASSPHRASE => "<long keyid> <long main keyid> <keytype> <keylength>",
|
56
|
+
:NEED_PASSPHRASE_SYM => "<cipher_algo> <s2k_mode> <s2k_hash>",
|
57
|
+
:NEED_PASSPHRASE_PIN => "<card_type> <chvno> [<serialno>]",
|
58
|
+
:MISSING_PASSPHRASE => "",
|
59
|
+
:BAD_PASSPHRASE => "<long keyid>",
|
60
|
+
:GOOD_PASSPHRASE => "",
|
61
|
+
:IMPORT_CHECK => "<long keyid> <fingerprint> <user ID>",
|
62
|
+
:IMPORTED => "<long keyid> <username>",
|
63
|
+
:IMPORT_OK => "<reason> [<fingerprint>]",
|
64
|
+
:IMPORT_PROBLEM => "<reason> [<fingerprint>]",
|
65
|
+
:IMPORT_RES => "<args>",
|
66
|
+
:CARDCTRL => "<what> [<serialno>]",
|
67
|
+
:SC_OP_FAILURE => "[<code>]",
|
68
|
+
:SC_OP_SUCCESS => "",
|
69
|
+
:NODATA => "<what>",
|
70
|
+
:UNEXPECTED => "<what>",
|
71
|
+
:TRUNCATED => "<maxno>",
|
72
|
+
:ERROR => "<error location> <error code> [<more>]",
|
73
|
+
:SUCCESS => "[<location>]",
|
74
|
+
:BADARMOR => "",
|
75
|
+
:DELETE_PROBLEM => "<reason_code>",
|
76
|
+
:PROGRESS => "<what> <char> <cur> <total>",
|
77
|
+
:BACKUP_KEY_CREATED => "<fingerprint> <fname>",
|
78
|
+
:MOUNTPOINT => "<name>",
|
79
|
+
:PINENTRY_LAUNCHED => "<pid>"
|
80
|
+
}
|
81
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'gpg_status_parser/status_codes'
|
2
|
+
require 'gpg_status_parser/arguments'
|
3
|
+
|
4
|
+
module GPGStatusParser
|
5
|
+
|
6
|
+
class NotGPGStatus < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class InvalidStatus < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class StatusMessage
|
13
|
+
COMMAND_REGEXP = /^\[GNUPG:\] ([^ ]+)(?: (.*))?$/
|
14
|
+
|
15
|
+
attr_reader :status, :args
|
16
|
+
|
17
|
+
def initialize status_string
|
18
|
+
match = COMMAND_REGEXP.match(status_string)
|
19
|
+
raise NotGPGStatus if match.nil?
|
20
|
+
|
21
|
+
@status = match[1].intern
|
22
|
+
raise InvalidStatus if !STATUS_CODES.keys.include?(@status)
|
23
|
+
|
24
|
+
expected_arg_string = GPGStatusParser::STATUS_CODES[@status]
|
25
|
+
expected_args = GPGStatusParser::Arguments.extract_expected_arguments(expected_arg_string)
|
26
|
+
@args = GPGStatusParser::Arguments.extract_argument_values(expected_args, match[2])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'gpg_status_parser'
|
3
|
+
require 'gpg_status_parser/arguments'
|
4
|
+
|
5
|
+
class ArgumentsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_expected_argument_extraction
|
8
|
+
GPGStatusParser::STATUS_CODES.each_pair do |key, val|
|
9
|
+
assert_nothing_raised do
|
10
|
+
GPGStatusParser::Arguments.extract_expected_arguments(val)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class MainApiTest < Test::Unit::TestCase
|
5
|
+
def test_parse_line
|
6
|
+
sig_id_msg = "[GNUPG:] SIG_ID jRWzDyjdbbGjvn9nNJJxF7HA7MA 2013-02-10 1360499004"
|
7
|
+
msg = GPGStatusParser::parse_line(sig_id_msg)
|
8
|
+
|
9
|
+
assert (msg.status == :SIG_ID), "extracted status should be SIG_ID"
|
10
|
+
|
11
|
+
args = {
|
12
|
+
:radix64_string=>"jRWzDyjdbbGjvn9nNJJxF7HA7MA",
|
13
|
+
:sig_creation_date=>"2013-02-10",
|
14
|
+
:sig_timestamp=>"1360499004"
|
15
|
+
}
|
16
|
+
assert (msg.args == args), "Args didn't match"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_parse_line_not_status_line
|
20
|
+
assert_raise GPGStatusParser::NotGPGStatus do
|
21
|
+
GPGStatusParser.parse_line("sfdsdfdsaf")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_line_invalid_status
|
26
|
+
assert_raise GPGStatusParser::InvalidStatus do
|
27
|
+
GPGStatusParser.parse_line("[GNUPG:] X509SIG_ID jRWzDyjdbbGjvn9nNJJxF7HA7MA 2013-02-10 1360499004")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
STATUS_TEXT = <<STATUS
|
32
|
+
[GNUPG:] PLAINTEXT 74 0
|
33
|
+
[GNUPG:] SIG_ID jRWzDyjdbbGjvn9nNJJxF7HA7MA 2013-02-10 1360499004
|
34
|
+
[GNUPG:] GOODSIG 703B0C0E25D38721 Test User <test@example.org>
|
35
|
+
[GNUPG:] VALIDSIG B2AE14D84135BA08C0FC27C7703B0C0E25D38721 2013-02-10 1360499004 0 4 0 1 2 01 B2AE14D84135BA08C0FC27C7703B0C0E25D38721
|
36
|
+
[GNUPG:] TRUST_ULTIMATE
|
37
|
+
STATUS
|
38
|
+
|
39
|
+
def test_parse_no_block
|
40
|
+
status_file = StringIO.new(STATUS_TEXT)
|
41
|
+
res = GPGStatusParser.parse(status_file).map{|msg| msg.status}
|
42
|
+
good_res = [:PLAINTEXT, :SIG_ID, :GOODSIG, :VALIDSIG, :TRUST_ULTIMATE]
|
43
|
+
assert (res == good_res), "Results didn't match expected"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_parse_block
|
47
|
+
good_res = [:PLAINTEXT, :SIG_ID, :GOODSIG, :VALIDSIG, :TRUST_ULTIMATE].reverse
|
48
|
+
|
49
|
+
status_file = StringIO.new(STATUS_TEXT)
|
50
|
+
res = GPGStatusParser.parse(status_file) do |msg|
|
51
|
+
assert (msg.status == good_res.pop), "Didn't match expected status"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_parse_string_no_block
|
56
|
+
res = GPGStatusParser.parse(STATUS_TEXT).map{|msg| msg.status}
|
57
|
+
good_res = [:PLAINTEXT, :SIG_ID, :GOODSIG, :VALIDSIG, :TRUST_ULTIMATE]
|
58
|
+
assert (res == good_res), "Results didn't match expected"
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_parse_string_block
|
62
|
+
good_res = [:PLAINTEXT, :SIG_ID, :GOODSIG, :VALIDSIG, :TRUST_ULTIMATE].reverse
|
63
|
+
|
64
|
+
res = GPGStatusParser.parse(STATUS_TEXT) do |msg|
|
65
|
+
assert (msg.status == good_res.pop), "Didn't match expected status"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'gpg_status_parser'
|
3
|
+
|
4
|
+
class StatusMessageTest < Test::Unit::TestCase
|
5
|
+
def test_sig_id
|
6
|
+
sig_id_msg = "[GNUPG:] SIG_ID jRWzDyjdbbGjvn9nNJJxF7HA7MA 2013-02-10 1360499004"
|
7
|
+
msg = GPGStatusParser::StatusMessage.new(sig_id_msg)
|
8
|
+
|
9
|
+
assert (msg.status == :SIG_ID), "extracted status should be SIG_ID"
|
10
|
+
|
11
|
+
args = {
|
12
|
+
:radix64_string=>"jRWzDyjdbbGjvn9nNJJxF7HA7MA",
|
13
|
+
:sig_creation_date=>"2013-02-10",
|
14
|
+
:sig_timestamp=>"1360499004"
|
15
|
+
}
|
16
|
+
assert (msg.args == args), "Args didn't match"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_goodsig
|
20
|
+
goodsig_msg = "[GNUPG:] GOODSIG 703B0C0E25D38721 Test User <test@example.org>"
|
21
|
+
msg = GPGStatusParser::StatusMessage.new(goodsig_msg)
|
22
|
+
|
23
|
+
assert (msg.status == :GOODSIG), "status should be :GOODSIG"
|
24
|
+
|
25
|
+
args = {
|
26
|
+
:long_keyid_or_fpr=>"703B0C0E25D38721",
|
27
|
+
:username=>" Test User <test@example.org>"
|
28
|
+
}
|
29
|
+
assert (msg.args == args), "Wrong args"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_validsig
|
33
|
+
unparsed_msg = "[GNUPG:] VALIDSIG B2AE14D84135BA08C0FC27C7703B0C0E25D38721 2013-02-10 1360499004 0 4 0 1 2 01 B2AE14D84135BA08C0FC27C7703B0C0E25D38721"
|
34
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
35
|
+
|
36
|
+
assert (msg.status == :VALIDSIG), ""
|
37
|
+
|
38
|
+
args = {
|
39
|
+
:fingerprint_in_hex=>"B2AE14D84135BA08C0FC27C7703B0C0E25D38721",
|
40
|
+
:sig_creation_date=>"2013-02-10", :sig_timestamp=>"1360499004",
|
41
|
+
:expire_timestamp=>"0", :sig_version=>"4", :reserved=>"0",
|
42
|
+
:pubkey_algo=>"1", :hash_algo=>"2", :sig_class=>"01",
|
43
|
+
:primary_key_fpr=>"B2AE14D84135BA08C0FC27C7703B0C0E25D38721"
|
44
|
+
}
|
45
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_trust_ultimate
|
49
|
+
unparsed_msg = "[GNUPG:] TRUST_ULTIMATE"
|
50
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
51
|
+
|
52
|
+
assert (msg.status == :TRUST_ULTIMATE), "expected :TRUST_ULTIMATE"
|
53
|
+
|
54
|
+
args = {}
|
55
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_trust_ultimate_optional_args
|
59
|
+
unparsed_msg = "[GNUPG:] TRUST_ULTIMATE 0 foo"
|
60
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
61
|
+
|
62
|
+
assert (msg.status == :TRUST_ULTIMATE), "expected :TRUST_ULTIMATE"
|
63
|
+
|
64
|
+
args = {:zero => "0", :validation_model => "foo"}
|
65
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_sig_id_2
|
69
|
+
unparsed_msg = "[GNUPG:] SIG_ID kEOcXvBQzVQilo+AYc+Ws8Mutok 2011-05-28 1306618646"
|
70
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
71
|
+
|
72
|
+
assert (msg.status == :SIG_ID), "expected :SIG_ID"
|
73
|
+
|
74
|
+
args = {
|
75
|
+
:radix64_string=>"kEOcXvBQzVQilo+AYc+Ws8Mutok",
|
76
|
+
:sig_creation_date=>"2011-05-28",
|
77
|
+
:sig_timestamp=>"1306618646"
|
78
|
+
}
|
79
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_goodsig_2
|
83
|
+
unparsed_msg = "[GNUPG:] GOODSIG FE45E55DA18A54D6 Grant T. Olson (Personal email) <kgo@grant-olson.net>"
|
84
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
85
|
+
|
86
|
+
assert (msg.status == :GOODSIG), "Expected :GOODSIG"
|
87
|
+
|
88
|
+
args = {
|
89
|
+
:long_keyid_or_fpr=>"FE45E55DA18A54D6",
|
90
|
+
:username=>" Grant T. Olson (Personal email) <kgo@grant-olson.net>"
|
91
|
+
}
|
92
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_valid_sig_2
|
96
|
+
unparsed_msg = "[GNUPG:] VALIDSIG F64DB95B20F8BA9B68B34346FE45E55DA18A54D6 2011-05-28 1306618646 0 4 0 1 3 00 A530C31CD7620D26E2BAC384B6F6FFD0E3B5806F"
|
97
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
98
|
+
|
99
|
+
assert (msg.status == :VALIDSIG), "expected :VALIDSIG"
|
100
|
+
|
101
|
+
args = {
|
102
|
+
:fingerprint_in_hex=>"F64DB95B20F8BA9B68B34346FE45E55DA18A54D6",
|
103
|
+
:sig_creation_date=>"2011-05-28", :sig_timestamp=>"1306618646",
|
104
|
+
:expire_timestamp=>"0", :sig_version=>"4", :reserved=>"0",
|
105
|
+
:pubkey_algo=>"1", :hash_algo=>"3", :sig_class=>"00",
|
106
|
+
:primary_key_fpr=>"A530C31CD7620D26E2BAC384B6F6FFD0E3B5806F"
|
107
|
+
}
|
108
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_trust_undefined
|
112
|
+
unparsed_msg = "[GNUPG:] TRUST_UNDEFINED"
|
113
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
114
|
+
|
115
|
+
assert (msg.status == :TRUST_UNDEFINED), "Expected TRUST_UNDEFINED"
|
116
|
+
|
117
|
+
args = {}
|
118
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_trust_undefined_with_token
|
122
|
+
unparsed_msg = "[GNUPG:] TRUST_UNDEFINED foo"
|
123
|
+
msg = GPGStatusParser::StatusMessage.new(unparsed_msg)
|
124
|
+
|
125
|
+
assert (msg.status == :TRUST_UNDEFINED), "Expected TRUST_UNDEFINED"
|
126
|
+
|
127
|
+
args = {:error_token=>"foo"}
|
128
|
+
assert (msg.args == args), "#{msg.args.inspect}"
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpg_status_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Grant T. Olson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Turns structured status messages provided by gpg into ruby objects for
|
15
|
+
easy manipulation in your code.
|
16
|
+
email: kgo@grant-olson.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE
|
22
|
+
- Rakefile
|
23
|
+
- lib/gpg_status_parser.rb
|
24
|
+
- lib/gpg_status_parser/status_codes.rb
|
25
|
+
- lib/gpg_status_parser/arguments.rb
|
26
|
+
- lib/gpg_status_parser/status_message.rb
|
27
|
+
- test/test_status_message.rb
|
28
|
+
- test/test_arguments.rb
|
29
|
+
- test/test_main_api.rb
|
30
|
+
homepage: https://github.com/grant-olson/gpg_status_parser
|
31
|
+
licenses:
|
32
|
+
- BSD 3 Clause
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Turns gpg status messages into ruby objects.
|
55
|
+
test_files:
|
56
|
+
- test/test_status_message.rb
|
57
|
+
- test/test_arguments.rb
|
58
|
+
- test/test_main_api.rb
|
metadata.gz.asc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
-----BEGIN PGP SIGNATURE-----
|
2
|
+
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
|
3
|
+
|
4
|
+
iQEcBAABCgAGBQJRICf/AAoJEP5F5V2hilTWHhQH/140mBfZ0bmss+LHrovNIknU
|
5
|
+
ptRbwphTP1gTjoxp9WImOhhu2+EpFmD0SkIElxTa8Q55Yr/H2hyZqXUffn56uiJy
|
6
|
+
PuIsipdBFvqmZTWXbo7/gu8wmTVSCEU8tnPcd/HhqBVPdN8bO3wX+M/VOXT3o8ST
|
7
|
+
4qS32FIapLjbWBRRweQrKW7BG+LFXa89cNG50ISYafk0ehE4YHpmWEbi4A02a+1j
|
8
|
+
Gccw1dkVmEKYJz7hjYUVTLE2Xojg9WytidBvfzl4r+GI3uNfGN2UdjTpQ/sp/siD
|
9
|
+
L35Sr5uVe7AO6JYUC1TcuU5ANA07bs9tr0XgxmAnmQvN5feC6lTceXA39H5a9kw=
|
10
|
+
=X4IE
|
11
|
+
-----END PGP SIGNATURE-----
|