diff --git a/nucypher/crypto/kits.py b/nucypher/crypto/kits.py index 1d8b1c062..b3caeedaa 100644 --- a/nucypher/crypto/kits.py +++ b/nucypher/crypto/kits.py @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ from constant_sorrow.constants import UNKNOWN_SENDER, NOT_SIGNED - +from bytestring_splitter import BytestringKwargifier, VariableLengthBytestring from nucypher.crypto.splitters import key_splitter, capsule_splitter @@ -31,21 +31,18 @@ class CryptoKit: if not cls.splitter: raise TypeError("This kit doesn't have a splitter defined.") - return cls.splitter(some_bytes, - return_remainder=cls.return_remainder_when_splitting) + splitter = cls.splitter() + return splitter(some_bytes) @classmethod def from_bytes(cls, some_bytes): - constituents = cls.split_bytes(some_bytes) - return cls(*constituents) + return cls.split_bytes(some_bytes) class MessageKit(CryptoKit): """ All the components needed to transmit and verify an encrypted message. """ - return_remainder_when_splitting = True - splitter = capsule_splitter + key_splitter def __init__(self, capsule, @@ -67,15 +64,22 @@ class MessageKit(CryptoKit): if include_alice_pubkey and self.sender_verifying_key: as_bytes += bytes(self.sender_verifying_key) - as_bytes += self.ciphertext + as_bytes += VariableLengthBytestring(self.ciphertext) return as_bytes + @classmethod + def splitter(cls, *args, **kwargs): + return BytestringKwargifier(cls, + capsule=(capsule_splitter, {'single': True}), + sender_verifying_key=(key_splitter, {'single': True}), + ciphertext=VariableLengthBytestring) + @property def signature(self): return self._signature def __bytes__(self): - return bytes(self.capsule) + self.ciphertext + return bytes(self.capsule) + VariableLengthBytestring(self.ciphertext) class PolicyMessageKit(MessageKit):