Kwargifiying the splitter for PolicyMessageKit.

pull/2712/head
jMyles 2019-10-07 17:31:21 +09:00
parent 5a67030054
commit d187bbe325
1 changed files with 13 additions and 9 deletions

View File

@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
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):