diff options
| author | J08nY | 2017-06-22 20:03:26 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-22 20:03:26 +0200 |
| commit | 263577d4826630e6871b35c73fe3dd114ee70e22 (patch) | |
| tree | 20613916e85536d16fe803a6e73a6126a7866bcb /src/mailman_pgp/pgp/mime.py | |
| parent | 90529b7058362d2a43625f95bcd3afc8b9733203 (diff) | |
| download | mailman-pgp-263577d4826630e6871b35c73fe3dd114ee70e22.tar.gz mailman-pgp-263577d4826630e6871b35c73fe3dd114ee70e22.tar.zst mailman-pgp-263577d4826630e6871b35c73fe3dd114ee70e22.zip | |
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
| -rw-r--r-- | src/mailman_pgp/pgp/mime.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py index fde9d49..3421167 100644 --- a/src/mailman_pgp/pgp/mime.py +++ b/src/mailman_pgp/pgp/mime.py @@ -16,10 +16,10 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """RFC1847 and RFC3156 compliant message wrapped.""" - +from email.iterators import walk from email.utils import collapse_rfc2231_value -from pgpy import PGPMessage, PGPSignature +from pgpy import PGPKey, PGPMessage, PGPSignature from public import public @@ -29,6 +29,7 @@ class MIMEWrapper: _signed_subtype = 'application/pgp-signature' _encrypted_subtype = 'application/pgp-encrypted' + _keys_subtype = 'application/pgp-keys' def __init__(self, msg): """ @@ -58,10 +59,9 @@ class MIMEWrapper: protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol')) content_subtype = self.msg.get_content_subtype() - return \ - second_type == MIMEWrapper._signed_subtype and \ - content_subtype == 'signed' and \ - protocol_param == MIMEWrapper._signed_subtype + return (second_type == MIMEWrapper._signed_subtype and + content_subtype == 'signed' and + protocol_param == MIMEWrapper._signed_subtype) def is_encrypted(self): """ @@ -78,12 +78,34 @@ class MIMEWrapper: 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 == MIMEWrapper._encrypted_subtype and \ - second_type == 'application/octet-stream' and \ - content_subtype == 'encrypted' and \ - protocol_param == MIMEWrapper._encrypted_subtype + return ('Version: 1' in first_part and + first_type == MIMEWrapper._encrypted_subtype and + second_type == 'application/octet-stream' and + content_subtype == 'encrypted' and + protocol_param == MIMEWrapper._encrypted_subtype) + + def has_keys(self): + """ + Whether the message contains keys as per RFC3156 section 7. + + :return: If the message contains keys. + :rtype: bool + """ + for part in walk(self.msg): + if part.get_content_type() == MIMEWrapper._keys_subtype: + return True + return False + + def keys(self): + """ + Get the collection of keys in this message. + + :return: A collection of keys. + """ + for part in walk(self.msg): + if part.get_content_type() == MIMEWrapper._keys_subtype: + key, _ = PGPKey.from_blob(part.get_payload()) + yield key def verify(self, key): """ |
