aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/inline.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/pgp/inline.py')
-rw-r--r--src/mailman_pgp/pgp/inline.py53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/mailman_pgp/pgp/inline.py b/src/mailman_pgp/pgp/inline.py
index bb0971d..49f0a6e 100644
--- a/src/mailman_pgp/pgp/inline.py
+++ b/src/mailman_pgp/pgp/inline.py
@@ -18,12 +18,14 @@
"""Strict inline PGP message wrapper."""
import copy
from email.iterators import walk
+from email.mime.text import MIMEText
from pgpy import PGPMessage
from pgpy.constants import SymmetricKeyAlgorithm
from public import public
-from mailman_pgp.utils.pgp import key_from_blob
+from mailman_pgp.utils.email import make_multipart
+from mailman_pgp.utils.pgp import key_from_blob, revoc_from_blob
@public
@@ -95,7 +97,7 @@ class InlineWrapper:
:rtype: typing.Generator[pgpy.PGPMessage]
"""
for part in walk(self.msg):
- if not part.is_multipart() and self._is_signed(part):
+ if not part.is_multipart():
try:
msg = PGPMessage.from_blob(part.get_payload())
except:
@@ -135,7 +137,7 @@ class InlineWrapper:
:rtype: typing.Generator[pgpy.PGPMessage]
"""
for part in walk(self.msg):
- if not part.is_multipart() and self._is_encrypted(part):
+ if not part.is_multipart():
try:
msg = PGPMessage.from_blob(part.get_payload())
except:
@@ -176,13 +178,56 @@ class InlineWrapper:
:rtype: Generator[pgpy.PGPKey]
"""
for part in walk(self.msg):
- if not part.is_multipart() and self._has_keys(part):
+ if not part.is_multipart():
try:
key = key_from_blob(part.get_payload())
except:
continue
yield key
+ def _is_revoc(self, part):
+ try:
+ revoc_from_blob(part.get_payload())
+ except ValueError:
+ return False
+ return True
+
+ def is_revocs(self):
+ for part in walk(self.msg):
+ if (not part.is_multipart() and not self._is_revoc(part)):
+ return False
+ return True
+
+ def has_revocs(self):
+ for part in walk(self.msg):
+ if (not part.is_multipart() and self._is_revoc(part)):
+ return True
+ return False
+
+ def revocs(self):
+ for part in walk(self.msg):
+ if not part.is_multipart():
+ try:
+ revoc = revoc_from_blob(part.get_payload())
+ except:
+ continue
+ yield revoc
+
+ def attach_revocs(self, *key_revocations):
+ """
+ Attach a key revocation signature to the message.
+
+ :param key_revocations: A key revocation signature to attach.
+ :type key_revocations: pgpy.PGPSignature
+ :return: The message with the signature attached.
+ :rtype: mailman.email.message.Message
+ """
+ out = make_multipart(self.msg)
+ for key_revocation in key_revocations:
+ revoc_part = MIMEText(str(key_revocation))
+ out.attach(revoc_part)
+ return out
+
def verify(self, key):
"""
Verify the signatures of this message with key.