Finishing the layup for which @michwill set me up vis a vis TreasureMaps being passed through Bob's controller.

pull/1330/head
jMyles 2020-02-08 04:18:17 -08:00
parent 4f8e266bf6
commit 90a3c26298
3 changed files with 17 additions and 6 deletions

View File

@ -202,10 +202,13 @@ class BobInterface(CharacterPublicInterface):
label=label) label=label)
self.character.join_policy(label=label, alice_verifying_key=alice_verifying_key) self.character.join_policy(label=label, alice_verifying_key=alice_verifying_key)
plaintexts = self.character.retrieve(message_kit, plaintexts = self.character.retrieve(message_kit,
enrico=enrico, enrico=enrico,
alice_verifying_key=alice_verifying_key, alice_verifying_key=alice_verifying_key,
label=label) label=label,
treasure_map=treasure_map)
response_data = {'cleartexts': plaintexts} response_data = {'cleartexts': plaintexts}
return response_data return response_data

View File

@ -17,7 +17,7 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import json import json
import time import time
from base64 import b64encode from base64 import b64encode, b64decode
from collections import OrderedDict from collections import OrderedDict
from functools import partial from functools import partial
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
@ -679,12 +679,20 @@ class Bob(Character):
hrac, map_id = self.construct_hrac_and_map_id(alice_verifying_key, label) hrac, map_id = self.construct_hrac_and_map_id(alice_verifying_key, label)
if treasure_map is not None: if treasure_map is not None:
from nucypher.policy.collections import TreasureMap
if isinstance(treasure_map, bytes):
treasure_map = TreasureMap.from_bytes(treasure_map)
alice = Alice.from_public_keys(verifying_key=alice_verifying_key) alice = Alice.from_public_keys(verifying_key=alice_verifying_key)
compass = self.make_compass_for_alice(alice) compass = self.make_compass_for_alice(alice)
from nucypher.policy.collections import TreasureMap
# TODO: This LBYL is ugly and fraught with danger.
if isinstance(treasure_map, bytes):
treasure_map = TreasureMap.from_bytes(treasure_map)
if isinstance(treasure_map, str):
tmap_bytes = treasure_map.encode()
b64decode(tmap_bytes)
treasure_map = TreasureMap.from_bytes(b64decode(tmap_bytes))
treasure_map.orient(compass) treasure_map.orient(compass)
_unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(treasure_map=treasure_map, block=True) _unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(treasure_map=treasure_map, block=True)
else: else:

View File

@ -145,6 +145,6 @@ def test_bob_rpc_character_control_retrieve_with_tmap(
blockchain_alice.stamp, blockchain_alice.stamp,
b'Wrong!') b'Wrong!')
tmap_64 = b64encode(bytes(wrong_tmap)).decode() tmap_64 = b64encode(bytes(wrong_tmap)).decode()
params['treasure_map'] = tmap_64 request_data['params']['treasure_map'] = tmap_64
with pytest.raises(TreasureMap.IsDisorienting): with pytest.raises(TreasureMap.IsDisorienting):
bob_rpc_controller.send(request_data) bob_rpc_controller.send(request_data)