Rename PolicyMessageKit to MessageKit

pull/2730/head
Bogdan Opanchuk 2021-08-20 09:08:39 -04:00
parent 0b697881a1
commit 3ef534b812
24 changed files with 71 additions and 71 deletions

View File

@ -27,7 +27,7 @@ import sys
from nucypher.characters.lawful import Bob, Enrico, Ursula
from nucypher.config.constants import TEMPORARY_DOMAIN
from nucypher.crypto.keypairs import DecryptingKeypair, SigningKeypair
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower, SigningPower
from nucypher.crypto.umbral_adapter import PublicKey
from nucypher.network.middleware import RestMiddleware
@ -95,7 +95,7 @@ treasure_map = EncryptedTreasureMap.from_bytes(base64.b64decode(policy_data["tre
# Let's read the file produced by the heart monitor and unpack the MessageKits,
# which are the individual ciphertexts.
data = msgpack.load(open("heart_data.msgpack", "rb"), raw=False)
message_kits = (PolicyMessageKit.from_bytes(k) for k in data['kits'])
message_kits = (MessageKit.from_bytes(k) for k in data['kits'])
# The doctor also needs to create a view of the Data Source from its public keys
data_source = Enrico.from_public_keys(

View File

@ -43,7 +43,7 @@ from nucypher.blockchain.eth.signers.base import Signer
from nucypher.characters.control.controllers import CharacterCLIController
from nucypher.control.controllers import JSONRPCController
from nucypher.crypto.keystore import Keystore
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import (
CryptoPower,
CryptoPowerUp,
@ -384,7 +384,7 @@ class Character(Learner):
def verify_from(self,
stranger: 'Character',
message_kit: Union[PolicyMessageKit, bytes],
message_kit: Union[MessageKit, bytes],
signature: Signature = None,
decrypt=False,
label=None,
@ -470,7 +470,7 @@ class Character(Learner):
return cleartext
def decrypt(self,
message_kit: PolicyMessageKit,
message_kit: MessageKit,
label: Optional[bytes] = None) -> bytes:
if label and DelegatingPower in self._default_crypto_powerups:
delegating_power = self._crypto_power.power_ups(DelegatingPower)

View File

@ -23,7 +23,7 @@ import maya
from nucypher.characters.base import Character
from nucypher.characters.control.specifications import alice, bob, enrico
from nucypher.control.interfaces import attach_schema, ControlInterface
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower, SigningPower
from nucypher.crypto.umbral_adapter import PublicKey
from nucypher.network.middleware import RestMiddleware
@ -132,7 +132,7 @@ class AliceInterface(CharacterPublicInterface):
policy_encrypting_key = self.implementer.get_policy_encrypting_key_from_label(label)
# TODO #846: May raise UnknownOpenSSLError and InvalidTag.
message_kit = PolicyMessageKit.from_bytes(message_kit)
message_kit = MessageKit.from_bytes(message_kit)
enrico = Enrico.from_public_keys(
verifying_key=message_kit.sender_verifying_key,
@ -175,7 +175,7 @@ class BobInterface(CharacterPublicInterface):
policy_encrypting_key = PublicKey.from_bytes(policy_encrypting_key)
alice_verifying_key = PublicKey.from_bytes(alice_verifying_key)
message_kit = PolicyMessageKit.from_bytes(message_kit) # TODO #846: May raise UnknownOpenSSLError and InvalidTag.
message_kit = MessageKit.from_bytes(message_kit) # TODO #846: May raise UnknownOpenSSLError and InvalidTag.
enrico = Enrico.from_public_keys(verifying_key=message_kit.sender_verifying_key,
policy_encrypting_key=policy_encrypting_key,

View File

@ -138,7 +138,7 @@ class Decrypt(BaseSchema):
label = character_fields.Label(
required=True, load_only=True,
click=options.option_label(required=True))
message_kit = character_fields.PolicyMessageKit(
message_kit = character_fields.MessageKit(
load_only=True,
click=options.option_message_kit(required=True))

View File

@ -45,7 +45,7 @@ class Retrieve(BaseSchema):
type=click.STRING,
required=False)
)
message_kit = character_fields.PolicyMessageKit(
message_kit = character_fields.MessageKit(
required=True,
load_only=True,
click=options.option_message_kit(required=False)

View File

@ -65,5 +65,5 @@ class EncryptMessage(BaseSchema):
return {"plaintext": data}
# output
message_kit = fields.PolicyMessageKit(dump_only=True)
message_kit = fields.MessageKit(dump_only=True)
signature = fields.UmbralSignature(dump_only=True)

View File

@ -22,12 +22,12 @@ from marshmallow import fields
from nucypher.characters.control.specifications.exceptions import InvalidNativeDataTypes
from nucypher.control.specifications.exceptions import InvalidInputData
from nucypher.control.specifications.fields.base import BaseField
from nucypher.crypto.kits import PolicyMessageKit as PolicyMessageKitClass
from nucypher.crypto.kits import MessageKit as MessageKitClass
class PolicyMessageKit(BaseField, fields.Field):
class MessageKit(BaseField, fields.Field):
def _serialize(self, value: PolicyMessageKitClass, attr, obj, **kwargs):
def _serialize(self, value: MessageKitClass, attr, obj, **kwargs):
return b64encode(value.to_bytes()).decode()
def _deserialize(self, value, attr, data, **kwargs):
@ -40,6 +40,6 @@ class PolicyMessageKit(BaseField, fields.Field):
def _validate(self, value):
try:
PolicyMessageKitClass.from_bytes(value)
MessageKitClass.from_bytes(value)
except InvalidNativeDataTypes as e:
raise InvalidInputData(f"Could not parse {self.name}: {e}")

View File

@ -76,7 +76,7 @@ from nucypher.config.storages import ForgetfulNodeStorage, NodeStorage
from nucypher.control.controllers import WebController
from nucypher.control.emitters import StdoutEmitter
from nucypher.crypto.keypairs import HostingKeypair
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import (
DecryptingPower,
DelegatingPower,
@ -420,7 +420,7 @@ class Alice(Character, BlockchainPolicyAuthor):
return receipt, failed
def decrypt_message_kit(self,
message_kit: PolicyMessageKit,
message_kit: MessageKit,
data_source: Character,
label: bytes
) -> List[bytes]:
@ -698,7 +698,7 @@ class Bob(Character):
def _filter_work_orders_and_capsules(self,
work_orders: Dict[ChecksumAddress, 'WorkOrder'],
message_kits: Sequence['PolicyMessageKit'],
message_kits: Sequence['MessageKit'],
threshold: int,
) -> Tuple[List['WorkOrder'], Set['Capsule']]:
remaining_work_orders = []
@ -713,7 +713,7 @@ class Bob(Character):
work_order: 'WorkOrder',
# TODO (#2028): it's kind of awkward to pass this mapping here,
# there should be a better way to handle this.
message_kits_map: Dict[Capsule, PolicyMessageKit],
message_kits_map: Dict[Capsule, MessageKit],
retain_cfrags: bool = False
) -> Tuple[bool, Union[List['Ursula'], List['CapsuleFrag']]]:
@ -770,7 +770,7 @@ class Bob(Character):
return True, verified_cfrags
def _assemble_work_orders(self,
*message_kits: List[PolicyMessageKit],
*message_kits: List[MessageKit],
enrico: 'Enrico',
policy_encrypting_key: PublicKey,
use_attached_cfrags: bool,
@ -829,7 +829,7 @@ class Bob(Character):
def _get_cleartexts(self,
*message_kits,
message_kits_map: Dict[Capsule, PolicyMessageKit],
message_kits_map: Dict[Capsule, MessageKit],
new_work_orders: Sequence['WorkOrder'],
threshold: int,
retain_cfrags: bool
@ -912,7 +912,7 @@ class Bob(Character):
def retrieve(self,
# Policy
*message_kits: PolicyMessageKit,
*message_kits: MessageKit,
label: bytes,
encrypted_treasure_map: Optional['EncryptedTreasureMap'] = None,
policy_encrypting_key: Optional[PublicKey] = None,
@ -1830,7 +1830,7 @@ class Enrico(Character):
if is_me:
self.log.info(self.banner.format(policy_encrypting_key))
def encrypt_message(self, plaintext: bytes) -> Tuple[PolicyMessageKit, Signature]:
def encrypt_message(self, plaintext: bytes) -> Tuple[MessageKit, Signature]:
# TODO: #2107 Rename to "encrypt"
message_kit, signature = encrypt_and_sign(self.policy_pubkey,
plaintext=plaintext,

View File

@ -45,7 +45,7 @@ class CryptoKit:
return cls.split_bytes(some_bytes)
class MessageKit(CryptoKit):
class BaseMessageKit(CryptoKit):
"""
All the components needed to transmit and verify an encrypted message.
"""
@ -131,7 +131,7 @@ class MessageKit(CryptoKit):
return self._signature
class PolicyMessageKit(MessageKit):
class MessageKit(BaseMessageKit):
"""
A MessageKit which includes sufficient additional information to be retrieved on the NuCypher Network.
"""

View File

@ -28,7 +28,7 @@ from eth_keys import KeyAPI as EthKeyAPI
from eth_utils.address import to_checksum_address
import nucypher.crypto.umbral_adapter as umbral
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.signing import SignatureStamp
from nucypher.crypto.umbral_adapter import Signature, PublicKey
@ -132,7 +132,7 @@ def encrypt_and_sign(recipient_pubkey_enc: PublicKey,
plaintext: bytes,
signer: 'SignatureStamp',
sign_plaintext: bool = True
) -> Tuple[PolicyMessageKit, Signature]:
) -> Tuple[MessageKit, Signature]:
if signer is not constants.DO_NOT_SIGN:
# The caller didn't expressly tell us not to sign; we'll sign.
if sign_plaintext:
@ -145,13 +145,13 @@ def encrypt_and_sign(recipient_pubkey_enc: PublicKey,
sig_header = constants.SIGNATURE_IS_ON_CIPHERTEXT
capsule, ciphertext = umbral.encrypt(recipient_pubkey_enc, sig_header + plaintext)
signature = signer(ciphertext)
message_kit = PolicyMessageKit(ciphertext=ciphertext, capsule=capsule,
message_kit = MessageKit(ciphertext=ciphertext, capsule=capsule,
sender_verifying_key=signer.as_umbral_pubkey(),
signature=signature)
else:
# Don't sign.
signature = sig_header = constants.NOT_SIGNED
capsule, ciphertext = umbral.encrypt(recipient_pubkey_enc, sig_header + plaintext)
message_kit = PolicyMessageKit(ciphertext=ciphertext, capsule=capsule)
message_kit = MessageKit(ciphertext=ciphertext, capsule=capsule)
return message_kit, signature

View File

@ -56,7 +56,7 @@ from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import BaseContractRegistry
from nucypher.config.constants import SeednodeMetadata
from nucypher.config.storages import ForgetfulNodeStorage
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower, NoSigningPower, SigningPower
from nucypher.crypto.splitters import signature_splitter
from nucypher.crypto.signing import SignatureStamp
@ -739,7 +739,7 @@ class Learner:
def verify_from(self,
stranger: 'Teacher',
message_kit: Union[PolicyMessageKit, bytes],
message_kit: Union[MessageKit, bytes],
signature: Signature):
#
# Optional Sanity Check

View File

@ -30,7 +30,7 @@ from mako.template import Template
from nucypher.blockchain.eth.utils import period_to_epoch
from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH
from nucypher.crypto.keypairs import DecryptingKeypair
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import KeyPairBasedPower, PowerUpError
from nucypher.crypto.signing import InvalidSignature
from nucypher.datastore.datastore import Datastore
@ -204,7 +204,7 @@ def _make_rest_app(datastore: Datastore, this_node, domain: str, log: Logger) ->
bob_identity_message = f"[{bob_ip_address}] Bob({bytes(bob.stamp).hex()})"
# Verify & Decrypt KFrag Payload
encrypted_kfrag_payload = PolicyMessageKit.from_bytes(work_order.encrypted_kfrag)
encrypted_kfrag_payload = MessageKit.from_bytes(work_order.encrypted_kfrag)
try:
plaintext_kfrag_payload = this_node.verify_from(stranger=alice,
message_kit=encrypted_kfrag_payload,

View File

@ -30,7 +30,7 @@ from eth_typing.evm import ChecksumAddress
from nucypher.blockchain.eth.constants import ETH_ADDRESS_BYTE_LENGTH
from nucypher.characters.base import Character
from nucypher.crypto.constants import EIP712_MESSAGE_SIGNATURE_SIZE
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower, SigningPower
from nucypher.crypto.signing import SignatureStamp
from nucypher.crypto.splitters import signature_splitter, kfrag_splitter
@ -54,7 +54,7 @@ class TreasureMap:
ursula_and_kfrag_payload_splitter = BytestringSplitter(
(to_checksum_address, ETH_ADDRESS_BYTE_LENGTH),
(PolicyMessageKit, VariableLengthBytestring),
(MessageKit, VariableLengthBytestring),
)
@classmethod
@ -203,7 +203,7 @@ class EncryptedTreasureMap:
_splitter = BytestringSplitter(
signature_splitter, # public signature
hrac_splitter, # HRAC
(PolicyMessageKit, VariableLengthBytestring), # encrypted TreasureMap
(MessageKit, VariableLengthBytestring), # encrypted TreasureMap
(bytes, EIP712_MESSAGE_SIGNATURE_SIZE)) # blockchain signature
_EMPTY_BLOCKCHAIN_SIGNATURE = b'\x00' * EIP712_MESSAGE_SIGNATURE_SIZE
@ -215,7 +215,7 @@ class EncryptedTreasureMap:
def _sign(blockchain_signer: Callable[[bytes], bytes],
public_signature: Signature,
hrac: HRAC,
encrypted_tmap: PolicyMessageKit,
encrypted_tmap: MessageKit,
) -> bytes:
# This method exists mainly to link this scheme to the corresponding test
payload = bytes(public_signature) + bytes(hrac) + encrypted_tmap.to_bytes()
@ -251,7 +251,7 @@ class EncryptedTreasureMap:
def __init__(self,
hrac: HRAC,
public_signature: Signature,
encrypted_tmap: PolicyMessageKit,
encrypted_tmap: MessageKit,
blockchain_signature: Optional[bytes] = None,
):

View File

@ -25,7 +25,7 @@ from constant_sorrow.constants import CFRAG_NOT_RETAINED
from eth_typing.evm import ChecksumAddress
from eth_utils.address import to_canonical_address, to_checksum_address
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.signing import SignatureStamp, InvalidSignature
from nucypher.crypto.splitters import (
key_splitter,
@ -80,7 +80,7 @@ class WorkOrder:
def get_specification(self,
ursula_stamp: SignatureStamp,
encrypted_kfrag: Union[PolicyMessageKit, bytes],
encrypted_kfrag: Union[MessageKit, bytes],
identity_evidence: Optional[bytes] = b''
) -> bytes:
@ -159,7 +159,7 @@ class WorkOrder:
@staticmethod
def make_receipt(tasks: Dict,
ursula: 'Ursula',
encrypted_kfrag: Union[PolicyMessageKit, bytes]
encrypted_kfrag: Union[MessageKit, bytes]
) -> bytes:
# TODO: What is the goal of the receipt and where can it be used?
capsules = b''.join(map(bytes, tasks.keys()))

View File

@ -24,7 +24,7 @@ import pytest
from click.testing import CliRunner
import nucypher
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower
from nucypher.policy.maps import TreasureMap, EncryptedTreasureMap
@ -220,7 +220,7 @@ def test_enrico_web_character_control_encrypt_message(enrico_web_controller_test
assert 'signature' in response_data['result']
# Check that it serializes correctly.
message_kit = PolicyMessageKit.from_bytes(b64decode(response_data['result']['message_kit']))
message_kit = MessageKit.from_bytes(b64decode(response_data['result']['message_kit']))
# Send bad data to assert error return
response = enrico_web_controller_test_client.post('/encrypt_message', data=json.dumps({'bad': 'input'}))
@ -296,7 +296,7 @@ def test_web_character_control_lifecycle(alice_web_controller_test_client,
assert 'signature' in enrico_response_data['result']
kit_bytes = b64decode(enrico_response_data['result']['message_kit'].encode())
bob_message_kit = PolicyMessageKit.from_bytes(kit_bytes)
bob_message_kit = MessageKit.from_bytes(kit_bytes)
# Retrieve data via Bob control
encoded_message_kit = b64encode(bob_message_kit.to_bytes()).decode()

View File

@ -21,7 +21,7 @@ import datetime
import maya
import pytest
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.utils import keccak_digest
from nucypher.datastore.models import EncryptedTreasureMap as DatastoreTreasureMap
from nucypher.policy.maps import EncryptedTreasureMap
@ -54,4 +54,4 @@ def test_decentralized_grant(blockchain_alice, blockchain_bob, blockchain_ursula
# TODO: try to decrypt?
# TODO: Use a new type for EncryptedKFrags?
assert isinstance(kfrag_kit, PolicyMessageKit)
assert isinstance(kfrag_kit, MessageKit)

View File

@ -33,7 +33,7 @@ from nucypher.cli.main import nucypher_cli
from nucypher.config.characters import AliceConfiguration, BobConfiguration
from nucypher.config.constants import NUCYPHER_ENVVAR_KEYSTORE_PASSWORD, TEMPORARY_DOMAIN, \
NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD, NUCYPHER_ENVVAR_BOB_ETH_PASSWORD
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.policy.maps import EncryptedTreasureMap
from nucypher.utilities.logging import GlobalLoggerSettings
from tests.constants import INSECURE_DEVELOPMENT_PASSWORD, TEST_PROVIDER_URI
@ -61,7 +61,7 @@ class MockSideChannel:
def save_message_kit(self, message_kit: str) -> None:
self.__message_kits.append(message_kit)
def fetch_message_kit(self) -> PolicyMessageKit:
def fetch_message_kit(self) -> MessageKit:
if self.__message_kits:
message_kit = self.__message_kits.pop()
return message_kit

View File

@ -30,7 +30,7 @@ from nucypher.cli.literature import SUCCESSFUL_DESTRUCTION, COLLECT_NUCYPHER_PAS
from nucypher.cli.main import nucypher_cli
from nucypher.config.characters import BobConfiguration
from nucypher.config.constants import TEMPORARY_DOMAIN
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import SigningPower
from nucypher.utilities.logging import GlobalLoggerSettings, Logger
from nucypher.policy.identity import Card
@ -151,7 +151,7 @@ def test_bob_retrieves_twice_via_cli(click_runner,
message_kit_bytes = bytes(three_message_kits[0])
message_kit_b64_bytes = b64encode(message_kit_bytes)
PolicyMessageKit.from_bytes(message_kit_bytes)
MessageKit.from_bytes(message_kit_bytes)
retrieve_args = ('bob', 'retrieve',
'--mock-networking',

View File

@ -25,7 +25,7 @@ import pytest
from click.testing import CliRunner
import nucypher
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower
from nucypher.policy.maps import EncryptedTreasureMap
@ -216,7 +216,7 @@ def test_enrico_web_character_control_encrypt_message(enrico_web_controller_test
assert 'signature' in response_data['result']
# Check that it serializes correctly.
PolicyMessageKit.from_bytes(b64decode(response_data['result']['message_kit']))
MessageKit.from_bytes(b64decode(response_data['result']['message_kit']))
# Send bad data to assert error return
response = enrico_web_controller_test_client.post('/encrypt_message', data=json.dumps({'bad': 'input'}))
@ -292,7 +292,7 @@ def test_web_character_control_lifecycle(alice_web_controller_test_client,
assert 'signature' in enrico_response_data['result']
kit_bytes = b64decode(enrico_response_data['result']['message_kit'].encode())
bob_message_kit = PolicyMessageKit.from_bytes(kit_bytes)
bob_message_kit = MessageKit.from_bytes(kit_bytes)
# Retrieve data via Bob control
encoded_message_kit = b64encode(bob_message_kit.to_bytes()).decode()

View File

@ -22,7 +22,7 @@ from twisted.internet import threads
from nucypher.characters.lawful import Alice
from nucypher.config.constants import TEMPORARY_DOMAIN
from nucypher.crypto.keypairs import DecryptingKeypair
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.crypto.powers import DecryptingPower
from nucypher.crypto.umbral_adapter import reencrypt
from nucypher.datastore.models import Workorder
@ -695,9 +695,9 @@ def test_bob_retrieves_multiple_messages_in_a_single_adventure(federated_bob,
alices_verifying_key = federated_alice.stamp.as_umbral_pubkey()
delivered_cleartexts = federated_bob.retrieve(PolicyMessageKit.from_bytes(message1_bytes),
PolicyMessageKit.from_bytes(message2_bytes),
PolicyMessageKit.from_bytes(message3_bytes),
delivered_cleartexts = federated_bob.retrieve(MessageKit.from_bytes(message1_bytes),
MessageKit.from_bytes(message2_bytes),
MessageKit.from_bytes(message3_bytes),
alice_verifying_key=alices_verifying_key,
label=enacted_federated_policy.label,
use_precedent_work_orders=True,

View File

@ -21,7 +21,7 @@ import datetime
import maya
import pytest
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
from nucypher.characters.lawful import Enrico
from nucypher.crypto.utils import keccak_digest
from nucypher.policy.orders import Revocation
@ -53,7 +53,7 @@ def test_federated_grant(federated_alice, federated_bob, federated_ursulas):
# TODO: try to decrypt?
# TODO: Use a new type for EncryptedKFrags?
assert isinstance(kfrag_kit, PolicyMessageKit)
assert isinstance(kfrag_kit, MessageKit)
def test_federated_alice_can_decrypt(federated_alice, federated_bob):

View File

@ -102,7 +102,7 @@ def test_messagekit_validation(capsule_side_channel):
class MessageKitsOnly(BaseSchema):
mkit = fields.PolicyMessageKit()
mkit = fields.MessageKit()
# this will raise a base64 error
with pytest.raises(SpecificationError) as e:

View File

@ -21,13 +21,13 @@ import maya
import pytest
from nucypher.crypto.umbral_adapter import SecretKey, Signer
from nucypher.crypto.kits import PolicyMessageKit as PolicyMessageKitClass
from nucypher.crypto.kits import MessageKit as MessageKitClass
from nucypher.characters.control.specifications.fields import (
DateTime,
FileField,
Key,
PolicyMessageKit,
MessageKit,
UmbralSignature,
EncryptedTreasureMap
)
@ -114,27 +114,27 @@ def test_key():
field._validate(value=b"PublicKey")
def test_umbral_message_kit(enacted_federated_policy, federated_alice):
def test_message_kit(enacted_federated_policy, federated_alice):
# Setup
enrico = Enrico.from_alice(federated_alice, label=enacted_federated_policy.label)
message = 'this is a message'
plaintext_bytes = bytes(message, encoding='utf-8')
message_kit, signature = enrico.encrypt_message(plaintext=plaintext_bytes)
message_kit_bytes = message_kit.to_bytes()
umbral_message_kit = PolicyMessageKitClass.from_bytes(message_kit_bytes)
message_kit = MessageKitClass.from_bytes(message_kit_bytes)
# Test
field = PolicyMessageKit()
serialized = field._serialize(value=umbral_message_kit, attr=None, obj=None)
assert serialized == b64encode(umbral_message_kit.to_bytes()).decode()
field = MessageKit()
serialized = field._serialize(value=message_kit, attr=None, obj=None)
assert serialized == b64encode(message_kit.to_bytes()).decode()
deserialized = field._deserialize(value=serialized, attr=None, data=None)
assert deserialized == b64decode(serialized)
field._validate(value=umbral_message_kit.to_bytes())
field._validate(value=message_kit.to_bytes())
with pytest.raises(InvalidInputData):
field._validate(value=b"PolicyMessageKit")
field._validate(value=b"MessageKit")
def test_umbral_signature():

View File

@ -16,7 +16,7 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
from nucypher.characters.lawful import Enrico
from nucypher.crypto.kits import PolicyMessageKit
from nucypher.crypto.kits import MessageKit
def test_message_kit_serialization_via_enrico(federated_alice):
@ -37,7 +37,7 @@ def test_message_kit_serialization_via_enrico(federated_alice):
message_kit_bytes = message_kit.to_bytes()
# Deserialize
the_same_message_kit = PolicyMessageKit.from_bytes(message_kit_bytes)
the_same_message_kit = MessageKit.from_bytes(message_kit_bytes)
# Confirm
assert message_kit_bytes == the_same_message_kit.to_bytes()