sks_dump_parser 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sks_parser.rb +95 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc2072d8798b3c5e6b1787c229cefd29a2ae6ea4
|
4
|
+
data.tar.gz: 0af9b88fe85a7552bf1ed31a6b6209a2a2e340c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33bea1eca1ce2669da2cab6ab5cee89aedcc9f672e8d1e67d8648433b533201dece67151e270e92fb30f263292be0b77d7e458b77bdb4a63d32e1c79f3079f84
|
7
|
+
data.tar.gz: d3f7dfb95c53ca6351ebb2dca75b165d0ae1ef77faf4cbf0e51612d6586ebadb62808d73da01e41cd2cabe0a414e8a8dba0c0881018135844a6e517bc0a9ad67
|
data/lib/sks_parser.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
class SksParser
|
2
|
+
|
3
|
+
class StateMachine
|
4
|
+
attr_accessor(:dump_hash)
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@state = S_READING_UID
|
8
|
+
@dump_hash = {}
|
9
|
+
@keyid = ''
|
10
|
+
end
|
11
|
+
|
12
|
+
# enumerate states
|
13
|
+
S_READING_UID = 0
|
14
|
+
S_READING_USER = 1
|
15
|
+
S_READING_SIGS = 2
|
16
|
+
S_READING_SUBS = 3
|
17
|
+
|
18
|
+
def self.get_dump_hash_from(dump)
|
19
|
+
sm = StateMachine.new
|
20
|
+
dump.each do |line|
|
21
|
+
sm.process(line)
|
22
|
+
end
|
23
|
+
sm.dump_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def state=(new_state)
|
27
|
+
@state = new_state
|
28
|
+
end
|
29
|
+
|
30
|
+
def process(line)
|
31
|
+
case @state
|
32
|
+
when S_READING_UID
|
33
|
+
process_uid_line(line)
|
34
|
+
when S_READING_USER
|
35
|
+
process_user_line(line)
|
36
|
+
when S_READING_SIGS
|
37
|
+
process_sig_line(line)
|
38
|
+
when S_READING_SUBS
|
39
|
+
process_sub_line(line)
|
40
|
+
else
|
41
|
+
raise 'invalid state detected'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_uid_line(line)
|
46
|
+
if line.start_with?('keyid')
|
47
|
+
@keyid = line.split(' ')[1]
|
48
|
+
@dump_hash[@keyid] = {}
|
49
|
+
self.state = S_READING_USER
|
50
|
+
else
|
51
|
+
return
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_user_line(line)
|
56
|
+
@dump_hash[@keyid][:user] = line.split(' ', 4)[3][1..-2]
|
57
|
+
@dump_hash[@keyid][:sigs] = []
|
58
|
+
self.state = S_READING_SIGS
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_sig_line(line)
|
62
|
+
if line.start_with?(':signature')
|
63
|
+
@dump_hash[@keyid][:sigs] << line.split(' ')[5]
|
64
|
+
end
|
65
|
+
if line.start_with?(':public sub')
|
66
|
+
self.state = S_READING_SUBS
|
67
|
+
elsif line.start_with?(':public key')
|
68
|
+
self.state = S_READING_UID
|
69
|
+
elsif line.start_with?(':user')
|
70
|
+
self.state = S_READING_UID
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def process_sub_line(line)
|
75
|
+
if line.start_with?(':public key')
|
76
|
+
self.state = S_READING_UID
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.parse_dump(directory)
|
83
|
+
output = []
|
84
|
+
files = Dir.glob("#{directory}/*")
|
85
|
+
files.each do |file|
|
86
|
+
IO.popen("gpg --list-packets #{file}").each do |line|
|
87
|
+
output << line.chomp.gsub(/\t/, '')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
StateMachine.get_dump_hash_from(output)
|
91
|
+
end
|
92
|
+
|
93
|
+
#self.parse_dump('dumps')
|
94
|
+
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sks_dump_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sue White
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: sue@mailworks.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/sks_parser.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.2.2
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Parse the SKS keydump into a useful Ruby hash.
|
43
|
+
test_files: []
|