aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/mime.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
-rw-r--r--src/mailman_pgp/pgp/mime.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py
index d593525..a2742f1 100644
--- a/src/mailman_pgp/pgp/mime.py
+++ b/src/mailman_pgp/pgp/mime.py
@@ -19,7 +19,7 @@
from email.message import Message
from email.utils import collapse_rfc2231_value
-from pgpy import PGPKey, PGPSignature
+from pgpy import PGPKey, PGPMessage, PGPSignature
class PGPMIMEWrapper:
@@ -46,9 +46,10 @@ class PGPMIMEWrapper:
protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol'))
content_subtype = self.msg.get_content_subtype()
- return second_type == PGPMIMEWrapper._signed_subtype and \
- content_subtype == 'signed' and \
- protocol_param == PGPMIMEWrapper._signed_subtype
+ return \
+ second_type == PGPMIMEWrapper._signed_subtype and \
+ content_subtype == 'signed' and \
+ protocol_param == PGPMIMEWrapper._signed_subtype
def is_encrypted(self):
"""
@@ -63,11 +64,12 @@ class PGPMIMEWrapper:
content_subtype = self.msg.get_content_subtype()
protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol'))
- return 'Version: 1' in first_part and \
- first_type == PGPMIMEWrapper._encrypted_subtype and \
- second_type == 'application/octet-stream' and \
- content_subtype == 'encrypted' and \
- protocol_param == PGPMIMEWrapper._encrypted_subtype
+ return \
+ 'Version: 1' in first_part and \
+ first_type == PGPMIMEWrapper._encrypted_subtype and \
+ second_type == 'application/octet-stream' and \
+ content_subtype == 'encrypted' and \
+ protocol_param == PGPMIMEWrapper._encrypted_subtype
def verify(self, key: PGPKey):
"""
@@ -81,4 +83,11 @@ class PGPMIMEWrapper:
return key.verify(clear_text, signature)
def decrypt(self, key: PGPKey):
- pass
+ """
+
+ :param key:
+ :return:
+ """
+ msg_text = self.msg.get_payload(1).get_payload()
+ msg = PGPMessage.from_blob(msg_text)
+ return key.decrypt(msg)