mirror of https://github.com/nucypher/nucypher.git
Tearing out all lookup_actor logic. Also, as @tuxxy pointed out a while ago, there's really no reason to have Character.hash(); we can just use keccak_digest.
parent
857a91855a
commit
e1b4f242ab
|
@ -67,8 +67,6 @@ class Character(object):
|
|||
raise ValueError("Pass crypto_power or crypto_power_ups (or neither), but not both.")
|
||||
|
||||
if is_me:
|
||||
self._actor_mapping = {}
|
||||
|
||||
self._stamp = SignatureStamp(self)
|
||||
|
||||
if attach_server:
|
||||
|
@ -145,13 +143,6 @@ class Character(object):
|
|||
def name(self):
|
||||
return self.__class__.__name__
|
||||
|
||||
@staticmethod
|
||||
def hash(message):
|
||||
return keccak_digest(message)
|
||||
|
||||
def learn_about_actor(self, actor):
|
||||
self._actor_mapping[actor.id()] = actor
|
||||
|
||||
def encrypt_for(self,
|
||||
recipient: "Character",
|
||||
plaintext: bytes,
|
||||
|
@ -265,9 +256,6 @@ class Character(object):
|
|||
def sign(self, message):
|
||||
return self._crypto_power.power_ups(SigningPower).sign(message)
|
||||
|
||||
def id(self):
|
||||
return hexlify(bytes(self.stamp))
|
||||
|
||||
def public_key(self, power_up_class):
|
||||
power_up = self._crypto_power.power_ups(power_up_class)
|
||||
return power_up.public_key()
|
||||
|
@ -369,7 +357,6 @@ class Bob(Character):
|
|||
|
||||
@alice.setter
|
||||
def alice(self, alice_object):
|
||||
self.learn_about_actor(alice_object)
|
||||
self._alice = alice_object
|
||||
|
||||
def follow_treasure_map(self, hrac):
|
||||
|
@ -559,7 +546,7 @@ class Ursula(Character):
|
|||
self.interface_hrac = interface_hrac
|
||||
|
||||
def __bytes__(self):
|
||||
return Ursula.hash(self.pubkey_sig_bytes + self.interface_hrac)
|
||||
return keccak_digest(self.pubkey_sig_bytes + self.interface_hrac)
|
||||
|
||||
def __add__(self, other):
|
||||
return bytes(self) + other
|
||||
|
@ -584,7 +571,7 @@ class Ursula(Character):
|
|||
)
|
||||
|
||||
def interface_hrac(self):
|
||||
return self.hash(msgpack.dumps(self.dht_interface_info()))
|
||||
return keccak_digest(msgpack.dumps(self.dht_interface_info()))
|
||||
|
||||
def publish_dht_information(self):
|
||||
if not self.dht_port and self.dht_interface:
|
||||
|
@ -645,7 +632,6 @@ class Ursula(Character):
|
|||
# policy_payload_splitter = BytestringSplitter((KFrag, KFRAG_LENGTH))
|
||||
|
||||
alice = Alice.from_public_keys((SigningPower, policy_message_kit.alice_pubkey))
|
||||
self.learn_about_actor(alice)
|
||||
|
||||
verified, cleartext = self.verify_from(
|
||||
alice, policy_message_kit,
|
||||
|
@ -764,9 +750,3 @@ class StrangerStamp(SignatureStamp):
|
|||
def __call__(self, *args, **kwargs):
|
||||
raise TypeError(
|
||||
"This isn't your SignatureStamp; it belongs to {} (a Stranger). You can't sign with it.".format(self.character))
|
||||
|
||||
|
||||
def congregate(*characters):
|
||||
for character in characters:
|
||||
for newcomer in characters:
|
||||
character.learn_about_actor(newcomer)
|
||||
|
|
|
@ -65,7 +65,6 @@ def test_anybody_can_verify():
|
|||
|
||||
# So, our story is fairly simple: an everyman meets Alice.
|
||||
somebody = Character()
|
||||
somebody.learn_about_actor(alice)
|
||||
|
||||
# Alice signs a message.
|
||||
message = b"A message for all my friends who can only verify and not sign."
|
||||
|
@ -87,7 +86,6 @@ def test_anybody_can_encrypt():
|
|||
"""
|
||||
can_sign_and_encrypt = Character(crypto_power_ups=[SigningPower, EncryptingPower])
|
||||
ursula = Ursula()
|
||||
can_sign_and_encrypt.learn_about_actor(ursula)
|
||||
|
||||
cleartext = b"This is Officer Rod Farva. Come in, Ursula! Come in Ursula!"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
|||
|
||||
import pytest
|
||||
|
||||
from nkms.characters import congregate, Alice, Bob
|
||||
from nkms.characters import Alice, Bob
|
||||
from nkms.crypto.kits import MessageKit
|
||||
from nkms.crypto.powers import SigningPower, EncryptingPower
|
||||
from nkms.network import blockchain_client
|
||||
|
@ -63,7 +63,6 @@ def bob(alice, ursulas):
|
|||
BOB.attach_server()
|
||||
BOB.server.listen(8475)
|
||||
EVENT_LOOP.run_until_complete(BOB.server.bootstrap([("127.0.0.1", URSULA_PORT)]))
|
||||
congregate(alice, BOB, *ursulas)
|
||||
return BOB
|
||||
|
||||
|
||||
|
|
|
@ -50,28 +50,6 @@ def test_vladimir_illegal_interface_key_does_not_propagate(ursulas):
|
|||
assert digest(illegal_key) in ursula.server.protocol.illegal_keys_seen
|
||||
|
||||
|
||||
def test_trying_to_find_unknown_actor_raises_not_found(alice):
|
||||
"""
|
||||
Tony the test character can't make reference to a character he doesn't know about yet.
|
||||
"""
|
||||
tony_clifton = Character()
|
||||
|
||||
message = b"some_message"
|
||||
signature = alice.stamp(message)
|
||||
|
||||
# Tony can't reference Alice...
|
||||
|
||||
# TODO: This may not actually be necessary anymore since we are mostly doing Character.from_public_keys()
|
||||
# with pytest.raises(Character.NotFound):
|
||||
# verification = tony_clifton.verify_from(alice, message, signature)
|
||||
|
||||
# ...before learning about Alice.
|
||||
tony_clifton.learn_about_actor(alice)
|
||||
verification, NO_DECRYPTION_PERFORMED = tony_clifton.verify_from(alice, message, signature=signature)
|
||||
|
||||
assert verification is True
|
||||
|
||||
|
||||
def test_alice_finds_ursula(alice, ursulas):
|
||||
"""
|
||||
With the help of any Ursula, Alice can find a specific Ursula.
|
||||
|
|
Loading…
Reference in New Issue