mirror of https://github.com/nucypher/nucypher.git
Code cleanup based on RFCs from #3007.
parent
1255047722
commit
08bf1a0515
|
@ -185,7 +185,6 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
|
|||
|
||||
# Bob
|
||||
bob_ip_address = request.remote_addr
|
||||
bob_verifying_key = bob.stamp.as_umbral_pubkey()
|
||||
bob_identity_message = f"[{bob_ip_address}] Bob({bytes(bob.stamp).hex()})"
|
||||
|
||||
# Verify & Decrypt KFrag Payload
|
||||
|
@ -215,19 +214,15 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
|
|||
# Enforce Reencryption Conditions
|
||||
providers = this_node.condition_providers if not this_node.federated_only else dict()
|
||||
capsules_to_process = list()
|
||||
for capsule, lingo in packets:
|
||||
# raises an exception or continues
|
||||
for capsule, condition_lingo in packets:
|
||||
error = evaluate_conditions(
|
||||
lingo=lingo, providers=providers, context=context
|
||||
lingo=condition_lingo, providers=providers, context=context
|
||||
)
|
||||
if error:
|
||||
# error cases
|
||||
return Response(*error)
|
||||
|
||||
capsules_to_process.append((lingo, capsule))
|
||||
|
||||
# Strip away conditions that have already been evaluated
|
||||
capsules_to_process = tuple(p[1] for p in capsules_to_process)
|
||||
capsules_to_process.append(capsule)
|
||||
|
||||
# FIXME: DISABLED FOR PRE-adapted-TDEC
|
||||
# TODO: Accept multiple payment methods?
|
||||
|
|
|
@ -113,14 +113,11 @@ def evaluate_conditions(
|
|||
if lingo is not None:
|
||||
# TODO: Evaluate all conditions even if one fails and report the result
|
||||
try:
|
||||
log.info(f'Evaluating access conditions {lingo.id}')
|
||||
log.info(f"Evaluating access conditions {lingo}")
|
||||
result = lingo.eval(providers=providers, **context)
|
||||
if not result:
|
||||
# explicit condition failure
|
||||
error = (
|
||||
"Decryption conditions not satisfied",
|
||||
HTTPStatus.FORBIDDEN
|
||||
)
|
||||
error = ("Decryption conditions not satisfied", HTTPStatus.FORBIDDEN)
|
||||
except InvalidCondition as e:
|
||||
error = (
|
||||
f"Incorrect value provided for condition: {e}",
|
||||
|
|
|
@ -29,7 +29,11 @@ from nucypher.policy.conditions import STANDARD_ABI_CONTRACT_TYPES, STANDARD_ABI
|
|||
from nucypher.policy.conditions._utils import CamelCaseSchema
|
||||
from nucypher.policy.conditions.base import ReencryptionCondition
|
||||
from nucypher.policy.conditions.context import get_context_value, is_context_variable
|
||||
from nucypher.policy.conditions.exceptions import InvalidCondition, RPCExecutionFailed
|
||||
from nucypher.policy.conditions.exceptions import (
|
||||
InvalidCondition,
|
||||
NoConnectionToChain,
|
||||
RPCExecutionFailed,
|
||||
)
|
||||
from nucypher.policy.conditions.lingo import ReturnValueTest
|
||||
|
||||
# Permitted blockchains for condition evaluation
|
||||
|
@ -160,7 +164,7 @@ class RPCCondition(ReencryptionCondition):
|
|||
try:
|
||||
provider = providers[self.chain]
|
||||
except KeyError:
|
||||
raise self.NoConnectionToChain(
|
||||
raise NoConnectionToChain(
|
||||
chain=self.chain,
|
||||
message=f"This node does not have a connection to chain ID {self.chain}",
|
||||
)
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
|
||||
from nucypher.policy.conditions.lingo import ConditionLingo
|
||||
|
||||
|
||||
def test_compound_condition_timelock():
|
||||
conditions = [
|
||||
CONDITIONS = [
|
||||
{
|
||||
"returnValueTest": {"value": 0, "comparator": ">"},
|
||||
"method": "timelock"
|
||||
|
@ -31,5 +29,15 @@ def test_compound_condition_timelock():
|
|||
},
|
||||
]
|
||||
|
||||
clingo = ConditionLingo.from_list(conditions)
|
||||
|
||||
def test_compound_condition_timelock():
|
||||
clingo = ConditionLingo.from_list(CONDITIONS)
|
||||
assert clingo.eval()
|
||||
|
||||
|
||||
def test_condition_lingo_repr():
|
||||
clingo = ConditionLingo.from_list(CONDITIONS)
|
||||
clingo_string = f"{clingo}"
|
||||
assert f"{clingo.__class__.__name__}" in clingo_string
|
||||
assert f"id={clingo.id}" in clingo_string
|
||||
assert f"size={len(bytes(clingo))}" in clingo_string
|
||||
|
|
Loading…
Reference in New Issue