diff options
| author | J08nY | 2017-07-18 20:50:01 +0200 |
|---|---|---|
| committer | J08nY | 2017-07-18 20:50:01 +0200 |
| commit | 456bb91e2e8593b6a30c7776ef426594a01de755 (patch) | |
| tree | 6a0f6aaa906668509e297aea69654f7b8c85d993 | |
| parent | 7a751f15069338887643b0cd3f22c143c605780a (diff) | |
| download | mailman-pgp-456bb91e2e8593b6a30c7776ef426594a01de755.tar.gz mailman-pgp-456bb91e2e8593b6a30c7776ef426594a01de755.tar.zst mailman-pgp-456bb91e2e8593b6a30c7776ef426594a01de755.zip | |
| -rw-r--r-- | src/mailman_pgp/pgp/inline.py | 23 | ||||
| -rw-r--r-- | src/mailman_pgp/pgp/mime.py | 22 |
2 files changed, 27 insertions, 18 deletions
diff --git a/src/mailman_pgp/pgp/inline.py b/src/mailman_pgp/pgp/inline.py index 372204a..5c23777 100644 --- a/src/mailman_pgp/pgp/inline.py +++ b/src/mailman_pgp/pgp/inline.py @@ -221,19 +221,21 @@ class InlineWrapper: self._decrypt(part, key) return out - def _encrypt(self, pmsg, *keys, cipher): + def _encrypt(self, pmsg, *keys, cipher, **kwargs): emsg = copy.copy(pmsg) if len(keys) == 1: - emsg = keys[0].encrypt(emsg, cipher=cipher) + emsg = keys[0].encrypt(emsg, cipher=cipher, **kwargs) else: session_key = cipher.gen_key() for key in keys: emsg = key.encrypt(emsg, cipher=cipher, - session_key=session_key) + session_key=session_key, + **kwargs) del session_key return emsg - def encrypt(self, *keys, cipher=SymmetricKeyAlgorithm.AES256): + def encrypt(self, *keys, cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): """ Encrypt the message with key/s, using cipher. @@ -251,12 +253,13 @@ class InlineWrapper: if not part.is_multipart(): payload = str(part.get_payload()) pmsg = PGPMessage.new(payload) - emsg = self._encrypt(pmsg, *keys, cipher=cipher) + emsg = self._encrypt(pmsg, *keys, cipher=cipher, **kwargs) part.set_payload(str(emsg)) return out def sign_encrypt(self, key, *keys, hash=None, - cipher=SymmetricKeyAlgorithm.AES256): + cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): """ Sign and encrypt the message, in one go. @@ -280,12 +283,14 @@ class InlineWrapper: payload = str(part.get_payload()) pmsg = PGPMessage.new(payload) smsg = self._sign(pmsg, key, hash=hash) - emsg = self._encrypt(smsg, *keys, cipher=cipher) + emsg = self._encrypt(smsg, *keys, cipher=cipher, **kwargs) part.set_payload(str(emsg)) return out def sign_then_encrypt(self, key, *keys, hash=None, - cipher=SymmetricKeyAlgorithm.AES256): + cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): # TODO: sign into cleartext here and then encrypt? I mean that's weird # but thats what sing *then* encrypt means for inline pgp. - return self.sign_encrypt(key, *keys, hash=hash, cipher=cipher) + return self.sign_encrypt(key, *keys, hash=hash, cipher=cipher, + **kwargs) diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py index 27dafa6..3c28132 100644 --- a/src/mailman_pgp/pgp/mime.py +++ b/src/mailman_pgp/pgp/mime.py @@ -260,14 +260,15 @@ class MIMEWrapper: copy_headers(self.msg, out) return out - def _encrypt(self, pmsg, *keys, cipher): + def _encrypt(self, pmsg, *keys, cipher, **kwargs): if len(keys) == 1: - pmsg = keys[0].encrypt(pmsg, cipher=cipher) + pmsg = keys[0].encrypt(pmsg, cipher=cipher, **kwargs) else: session_key = cipher.gen_key() for key in keys: pmsg = key.encrypt(pmsg, cipher=cipher, - session_key=session_key) + session_key=session_key, + **kwargs) del session_key return pmsg @@ -294,7 +295,8 @@ class MIMEWrapper: out.attach(second_part) return out - def encrypt(self, *keys, cipher=SymmetricKeyAlgorithm.AES256): + def encrypt(self, *keys, cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): """ Encrypt the message with key/s, using cipher. @@ -310,13 +312,14 @@ class MIMEWrapper: payload = self.msg.as_string() pmsg = PGPMessage.new(payload) - pmsg = self._encrypt(pmsg, *keys, cipher=cipher) + pmsg = self._encrypt(pmsg, *keys, cipher=cipher, **kwargs) out = self._wrap_encrypted(pmsg) copy_headers(self.msg, out) return out def sign_encrypt(self, key, *keys, hash=None, - cipher=SymmetricKeyAlgorithm.AES256): + cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): """ Sign and encrypt the message, in one go. @@ -339,13 +342,14 @@ class MIMEWrapper: payload = self.msg.as_string() pmsg = PGPMessage.new(payload) pmsg |= key.sign(pmsg, hash=hash) - pmsg = self._encrypt(pmsg, *keys, cipher=cipher) + pmsg = self._encrypt(pmsg, *keys, cipher=cipher, **kwargs) out = self._wrap_encrypted(pmsg) copy_headers(self.msg, out) return out def sign_then_encrypt(self, key, *keys, hash=None, - cipher=SymmetricKeyAlgorithm.AES256): + cipher=SymmetricKeyAlgorithm.AES256, + **kwargs): """ Sign then encrypt the message. @@ -367,4 +371,4 @@ class MIMEWrapper: out = self.sign(key, hash) out_wrapped = MIMEWrapper(out) - return out_wrapped.encrypt(*keys, cipher=cipher) + return out_wrapped.encrypt(*keys, cipher=cipher, **kwargs) |
