diff options
| author | J08nY | 2017-08-01 22:53:15 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-02 01:35:10 +0200 |
| commit | dff7befbc5860f2f78f63ab694ef88d21a53771f (patch) | |
| tree | 458e8004705eab2ca024da0cd21057cc2f5f56f3 /src/mailman_pgp/pgp/mime.py | |
| parent | 7c0aaf28767e494323557b6cb8fb6500df5822e5 (diff) | |
| download | mailman-pgp-dff7befbc5860f2f78f63ab694ef88d21a53771f.tar.gz mailman-pgp-dff7befbc5860f2f78f63ab694ef88d21a53771f.tar.zst mailman-pgp-dff7befbc5860f2f78f63ab694ef88d21a53771f.zip | |
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
| -rw-r--r-- | src/mailman_pgp/pgp/mime.py | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py index a1303c9..e40f581 100644 --- a/src/mailman_pgp/pgp/mime.py +++ b/src/mailman_pgp/pgp/mime.py @@ -29,7 +29,7 @@ from pgpy.constants import HashAlgorithm, SymmetricKeyAlgorithm from public import public from mailman_pgp.utils.email import copy_headers -from mailman_pgp.utils.pgp import key_from_blob +from mailman_pgp.utils.pgp import key_from_blob, revoc_from_blob @public @@ -208,6 +208,59 @@ class MIMEWrapper: out.attach(key_part) return out + def _is_revoc(self, part): + if part.get_content_type() != MIMEWrapper._keys_type: + return False + 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() # noqa + and part.get_content_type() == MIMEWrapper._keys_type): + try: + revoc = revoc_from_blob(part.get_payload()) + except: + continue + yield revoc + + def attach_revoc(self, key_revocation): + """ + Attach a key revocation signature to the message, as a key subpart. + + :param key_revocation: A key revocation signature to attach. + :type key_revocation: pgpy.PGPSignature + :return: The message with the signature attached. + :rtype: mailman.email.message.Message + """ + filename = '0x' + key_revocation.signer + '.asc' + key_part = MIMEApplication(_data=str(key_revocation), + _subtype=MIMEWrapper._keys_subtype, + _encoder=encode_7or8bit, + name=filename) + key_part.add_header('Content-Description', + 'OpenPGP key') + key_part.add_header('Content-Disposition', 'attachment', + filename=filename) + out = copy.deepcopy(self.msg) + out.attach(key_part) + return out + def verify(self, key): """ Verify the signature of this message with key. |
