From 90a3c262980e5d275face6107062e33bd18a6d91 Mon Sep 17 00:00:00 2001 From: jMyles Date: Sat, 8 Feb 2020 04:18:17 -0800 Subject: [PATCH] Finishing the layup for which @michwill set me up vis a vis TreasureMaps being passed through Bob's controller. --- nucypher/characters/control/interfaces.py | 5 ++++- nucypher/characters/lawful.py | 16 ++++++++++++---- .../blockchain/test_rpc_control_blockchain.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/nucypher/characters/control/interfaces.py b/nucypher/characters/control/interfaces.py index 224539895..bc5b684e5 100644 --- a/nucypher/characters/control/interfaces.py +++ b/nucypher/characters/control/interfaces.py @@ -202,10 +202,13 @@ class BobInterface(CharacterPublicInterface): label=label) self.character.join_policy(label=label, alice_verifying_key=alice_verifying_key) + + plaintexts = self.character.retrieve(message_kit, enrico=enrico, alice_verifying_key=alice_verifying_key, - label=label) + label=label, + treasure_map=treasure_map) response_data = {'cleartexts': plaintexts} return response_data diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index 4f343f7c6..c87ce427d 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -17,7 +17,7 @@ along with nucypher. If not, see . import json import time -from base64 import b64encode +from base64 import b64encode, b64decode from collections import OrderedDict from functools import partial from json.decoder import JSONDecodeError @@ -679,13 +679,21 @@ class Bob(Character): hrac, map_id = self.construct_hrac_and_map_id(alice_verifying_key, label) if treasure_map is not None: + alice = Alice.from_public_keys(verifying_key=alice_verifying_key) + 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) - alice = Alice.from_public_keys(verifying_key=alice_verifying_key) - compass = self.make_compass_for_alice(alice) - treasure_map.orient(compass) + + 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) _unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(treasure_map=treasure_map, block=True) else: _unknown_ursulas, _known_ursulas, m = self.follow_treasure_map(map_id=map_id, block=True) diff --git a/tests/characters/control/blockchain/test_rpc_control_blockchain.py b/tests/characters/control/blockchain/test_rpc_control_blockchain.py index f875a7a81..519eea3a0 100644 --- a/tests/characters/control/blockchain/test_rpc_control_blockchain.py +++ b/tests/characters/control/blockchain/test_rpc_control_blockchain.py @@ -145,6 +145,6 @@ def test_bob_rpc_character_control_retrieve_with_tmap( blockchain_alice.stamp, b'Wrong!') tmap_64 = b64encode(bytes(wrong_tmap)).decode() - params['treasure_map'] = tmap_64 + request_data['params']['treasure_map'] = tmap_64 with pytest.raises(TreasureMap.IsDisorienting): bob_rpc_controller.send(request_data)