1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#
#-*- coding:utf-8 -*-
"""
Gentoo-keys - gkey.py
Holds GKEY class and related values
@copyright: 2012-2015 by Brian Dolbec <dol-sen@gentoo.org>
@license: GNU GPL2, see COPYING for details.
"""
from collections import namedtuple
GKEY_STRING = ''' ----------
Name.........: %(name)s
Nick.........: %(nick)s
Keydir.......: %(keydir)s
'''
GKEY_UID = \
''' UID..........: %(uid)s
'''
GKEY_FINGERPRINTS = \
''' Keyid........: %(keyid)s
Fingerprint: %(fingerprint)s
'''
class GKEY(namedtuple('GKEY', ['nick', 'name', 'keydir', 'keys', 'fingerprint', 'uid'])):
'''Class to hold the relavent info about a key'''
field_types = {'nick': str, 'name': str, 'keydir': str, 'keys': list,
'fingerprint': list, 'uid': list}
__slots__ = ()
@property
def keyid(self):
'''Keyid is a substring value of the fingerprint'''
return ['0x' + x[-16:] for x in self.fingerprint]
@property
def pub_keyid(self):
'''Keyid is a substring value of the keys fingerprints'''
return ['0x' + x[-16:] for x in self.keys]
@property
def pretty_print(self):
'''Pretty printing a GKEY'''
gkey = {
'name': self.name,
'nick': self.nick,
'keydir': self.keydir,
}
output = GKEY_STRING % gkey
for uid in self.uid:
output += GKEY_UID % {'uid': uid}
for f in self.fingerprint:
fingerprint = {'fingerprint': f, 'keyid': '0x' + f[-16:]}
output += GKEY_FINGERPRINTS % fingerprint
return output
def update(self, result_list):
'''Processes a results instance from a colon listing
and mines all fingerprints found.
@param result_list: list of pyGPG.output.GPGResult instances
(one for each fingerprint in the list)
@return: A new, updated GKEY instance
'''
fingerprints = set()
uids = set()
for result in result_list:
for data in result.status.data:
if data.name == "FPR":
fingerprints.add(data.fingerprint)
elif data.name == "UID":
uids.add(data.user_ID)
return self._make([self.nick, self.name, self.keydir, self.keys, list(fingerprints), sorted(uids)])
class GKEY_CHECK(namedtuple('GKEY_CHECK', ['keyid', 'revoked', 'expired', 'invalid', 'sign'])):
__slots__ = ()
|