mirror of https://github.com/nucypher/nucypher.git
Making names uniform throughout the codebase: policy_key -> policy_encrypting_key
Also change recipient_key to policy_encrypting_key in MessageKit.author(), now that MessageKit is only used for reencryptable messages.pull/2809/head
parent
70b2a1d57b
commit
fe02c30fc7
|
@ -364,7 +364,7 @@ class Character(Learner):
|
|||
|
||||
# TODO: who even uses this method except for tests?
|
||||
|
||||
message_kit = MessageKit.author(recipient_key=recipient.public_keys(DecryptingPower),
|
||||
message_kit = MessageKit.author(policy_encrypting_key=recipient.public_keys(DecryptingPower),
|
||||
plaintext=plaintext)
|
||||
return message_kit
|
||||
|
||||
|
|
|
@ -1304,7 +1304,7 @@ class Enrico(Character):
|
|||
|
||||
def encrypt_message(self, plaintext: bytes) -> MessageKit:
|
||||
# TODO: #2107 Rename to "encrypt"
|
||||
message_kit = MessageKit.author(recipient_key=self.policy_pubkey,
|
||||
message_kit = MessageKit.author(policy_encrypting_key=self.policy_pubkey,
|
||||
plaintext=plaintext)
|
||||
return message_kit
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ class MessageKit(Versioned):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def author(cls, recipient_key: PublicKey, plaintext: bytes) -> 'MessageKit':
|
||||
capsule, ciphertext = umbral.encrypt(recipient_key, plaintext)
|
||||
def author(cls, policy_encrypting_key: PublicKey, plaintext: bytes) -> 'MessageKit':
|
||||
capsule, ciphertext = umbral.encrypt(policy_encrypting_key, plaintext)
|
||||
return cls(capsule=capsule, ciphertext=ciphertext)
|
||||
|
||||
def __init__(self, capsule: Capsule, ciphertext: bytes):
|
||||
|
@ -78,8 +78,12 @@ class MessageKit(Versioned):
|
|||
def decrypt(self, sk: SecretKey) -> bytes:
|
||||
return decrypt_original(sk, self.capsule, self.ciphertext)
|
||||
|
||||
def decrypt_reencrypted(self, sk: SecretKey, policy_key: PublicKey, cfrags: Sequence[VerifiedCapsuleFrag]) -> bytes:
|
||||
return decrypt_reencrypted(sk, policy_key, self.capsule, cfrags, self.ciphertext)
|
||||
def decrypt_reencrypted(self,
|
||||
sk: SecretKey,
|
||||
policy_encrypting_key: PublicKey,
|
||||
cfrags: Sequence[VerifiedCapsuleFrag],
|
||||
) -> bytes:
|
||||
return decrypt_reencrypted(sk, policy_encrypting_key, self.capsule, cfrags, self.ciphertext)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.__class__.__name__}({self.capsule})"
|
||||
|
@ -595,7 +599,7 @@ class ReencryptionResponse(Versioned):
|
|||
capsules: Sequence[Capsule],
|
||||
alice_verifying_key: PublicKey,
|
||||
ursula_verifying_key: PublicKey,
|
||||
policy_key: PublicKey,
|
||||
policy_encrypting_key: PublicKey,
|
||||
bob_encrypting_key: PublicKey,
|
||||
) -> List[VerifiedCapsuleFrag]:
|
||||
|
||||
|
@ -615,7 +619,7 @@ class ReencryptionResponse(Versioned):
|
|||
for capsule, cfrag in zip(capsules, self.cfrags):
|
||||
verified_cfrags[capsule] = cfrag.verify(capsule,
|
||||
verifying_pk=alice_verifying_key,
|
||||
delegating_pk=policy_key,
|
||||
delegating_pk=policy_encrypting_key,
|
||||
receiving_pk=bob_encrypting_key)
|
||||
|
||||
return verified_cfrags
|
||||
|
|
|
@ -178,7 +178,7 @@ class RetrievalClient:
|
|||
ursula: 'Ursula',
|
||||
reencryption_request: ReencryptionRequest,
|
||||
alice_verifying_key: PublicKey,
|
||||
policy_key: PublicKey,
|
||||
policy_encrypting_key: PublicKey,
|
||||
bob_encrypting_key: PublicKey,
|
||||
) -> Dict['Capsule', 'VerifiedCapsuleFrag']:
|
||||
"""
|
||||
|
@ -221,7 +221,7 @@ class RetrievalClient:
|
|||
verified_cfrags = reencryption_response.verify(capsules=reencryption_request.capsules,
|
||||
alice_verifying_key=alice_verifying_key,
|
||||
ursula_verifying_key=ursula_verifying_key,
|
||||
policy_key=policy_key,
|
||||
policy_encrypting_key=policy_encrypting_key,
|
||||
bob_encrypting_key=bob_encrypting_key,
|
||||
)
|
||||
except InvalidSignature as e:
|
||||
|
@ -271,7 +271,7 @@ class RetrievalClient:
|
|||
cfrags = self._request_reencryption(ursula=ursula,
|
||||
reencryption_request=reencryption_request,
|
||||
alice_verifying_key=alice_verifying_key,
|
||||
policy_key=treasure_map.policy_encrypting_key,
|
||||
policy_encrypting_key=treasure_map.policy_encrypting_key,
|
||||
bob_encrypting_key=bob_encrypting_key)
|
||||
except Exception as e:
|
||||
# TODO (#2789): at this point we can separate the exceptions to "acceptable"
|
||||
|
|
|
@ -30,19 +30,19 @@ class PolicyMessageKit:
|
|||
@classmethod
|
||||
def from_message_kit(cls,
|
||||
message_kit: MessageKit,
|
||||
policy_key: PublicKey,
|
||||
policy_encrypting_key: PublicKey,
|
||||
threshold: int
|
||||
) -> 'PolicyMessageKit':
|
||||
return cls(policy_key, threshold, RetrievalResult.empty(), message_kit)
|
||||
return cls(policy_encrypting_key, threshold, RetrievalResult.empty(), message_kit)
|
||||
|
||||
def __init__(self,
|
||||
policy_key: PublicKey,
|
||||
policy_encrypting_key: PublicKey,
|
||||
threshold: int,
|
||||
result: 'RetrievalResult',
|
||||
message_kit: MessageKit,
|
||||
):
|
||||
self.message_kit = message_kit
|
||||
self.policy_key = policy_key
|
||||
self.policy_encrypting_key = policy_encrypting_key
|
||||
self.threshold = threshold
|
||||
self._result = result
|
||||
|
||||
|
@ -50,13 +50,13 @@ class PolicyMessageKit:
|
|||
return RetrievalKit(self.message_kit.capsule, self._result.addresses())
|
||||
|
||||
def decrypt(self, sk: SecretKey) -> bytes:
|
||||
return self.message_kit.decrypt_reencrypted(sk, self.policy_key, self._result.cfrags.values())
|
||||
return self.message_kit.decrypt_reencrypted(sk, self.policy_encrypting_key, self._result.cfrags.values())
|
||||
|
||||
def is_decryptable_by_receiver(self) -> bool:
|
||||
return len(self._result.cfrags) >= self.threshold
|
||||
|
||||
def with_result(self, result: 'RetrievalResult') -> 'PolicyMessageKit':
|
||||
return PolicyMessageKit(policy_key=self.policy_key,
|
||||
return PolicyMessageKit(policy_encrypting_key=self.policy_encrypting_key,
|
||||
threshold=self.threshold,
|
||||
result=self._result.with_result(result),
|
||||
message_kit=self.message_kit)
|
||||
|
|
|
@ -129,7 +129,7 @@ def test_retrieve_cfrags(blockchain_porter,
|
|||
# check that the re-encryption performed was valid
|
||||
treasure_map = retrieve_args['treasure_map']
|
||||
policy_message_kit = PolicyMessageKit.from_message_kit(message_kit=message_kit,
|
||||
policy_key=enacted_policy.public_key,
|
||||
policy_encrypting_key=enacted_policy.public_key,
|
||||
threshold=treasure_map.threshold)
|
||||
assert len(retrieval_results) == 1
|
||||
field = RetrievalResultSchema()
|
||||
|
|
|
@ -126,7 +126,7 @@ def test_retrieve_cfrags(federated_porter,
|
|||
# check that the re-encryption performed was valid
|
||||
treasure_map = retrieve_args['treasure_map']
|
||||
policy_message_kit = PolicyMessageKit.from_message_kit(message_kit=message_kit,
|
||||
policy_key=enacted_federated_policy.public_key,
|
||||
policy_encrypting_key=enacted_federated_policy.public_key,
|
||||
threshold=treasure_map.threshold)
|
||||
assert len(retrieval_results) == 1
|
||||
field = RetrievalResultSchema()
|
||||
|
|
Loading…
Reference in New Issue