1.1 --- a/MoinMessage.py Mon Nov 11 19:29:29 2013 +0100
1.2 +++ b/MoinMessage.py Mon Nov 11 23:06:22 2013 +0100
1.3 @@ -358,6 +358,28 @@
1.4 text = self.run(["--armor", "--export", keyid])
1.5 return MIMEApplication(text, "pgp-keys", encode_noop)
1.6
1.7 + def listKeys(self, keyid=None):
1.8 +
1.9 + """
1.10 + Return a list of key details for keys on the keychain, selecting only
1.11 + one specific key if 'keyid' is specified.
1.12 + """
1.13 +
1.14 + text = self.run(["--list-keys", "--with-colons", "--with-fingerprint"] +
1.15 + (keyid and ["0x%s" % keyid] or []))
1.16 + return self._getKeysFromResult(text)
1.17 +
1.18 + def listSignatures(self, keyid=None):
1.19 +
1.20 + """
1.21 + Return a list of key and signature details for keys on the keychain,
1.22 + selecting only one specific key if 'keyid' is specified.
1.23 + """
1.24 +
1.25 + text = self.run(["--list-sigs", "--with-colons", "--with-fingerprint"] +
1.26 + (keyid and ["0x%s" % keyid] or []))
1.27 + return self._getKeysFromResult(text)
1.28 +
1.29 def getKeysFromMessagePart(self, part):
1.30
1.31 """
1.32 @@ -369,16 +391,27 @@
1.33
1.34 def getKeysFromString(self, s):
1.35
1.36 - "Return a list of key details extracted from the given string 's'."
1.37 + """
1.38 + Return a list of key details extracted from the given key block string
1.39 + 's'.
1.40 + """
1.41
1.42 text = self.run(["--with-colons", "--with-fingerprint"], s)
1.43 + return self._getKeysFromResult(text)
1.44 +
1.45 + def _getKeysFromResult(self, text):
1.46 +
1.47 + """
1.48 + Return a list of key details extracted from the given command result
1.49 + 'text'.
1.50 + """
1.51 +
1.52 keys = []
1.53 -
1.54 for line in text.split("\n"):
1.55 try:
1.56 recordtype, trust, keylength, algorithm, keyid, cdate, expdate, serial, ownertrust, _rest = line.split(":", 9)
1.57 except ValueError:
1.58 - break
1.59 + continue
1.60
1.61 if recordtype == "pub":
1.62 userid, _rest = _rest.split(":", 1)
1.63 @@ -386,7 +419,7 @@
1.64 "type" : recordtype, "trust" : trust, "keylength" : keylength,
1.65 "algorithm" : algorithm, "keyid" : keyid, "cdate" : cdate,
1.66 "expdate" : expdate, "userid" : userid, "ownertrust" : ownertrust,
1.67 - "fingerprint" : None, "subkeys" : []
1.68 + "fingerprint" : None, "subkeys" : [], "signatures" : []
1.69 })
1.70 elif recordtype == "sub" and keys:
1.71 keys[-1]["subkeys"].append({
1.72 @@ -397,6 +430,12 @@
1.73 elif recordtype == "fpr" and keys:
1.74 fingerprint, _rest = _rest.split(":", 1)
1.75 keys[-1]["fingerprint"] = fingerprint
1.76 + elif recordtype == "sig" and keys:
1.77 + userid, _rest = _rest.split(":", 1)
1.78 + keys[-1]["signatures"].append({
1.79 + "keyid" : keyid, "cdate" : cdate, "expdate" : expdate,
1.80 + "userid" : userid
1.81 + })
1.82
1.83 return keys
1.84