Skip to content

Commit

Permalink
Better avoid protected keyword
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Jul 2, 2024
1 parent aaa8b8c commit 4670ed6
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 56 deletions.
12 changes: 6 additions & 6 deletions aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,17 +477,17 @@ async def _get_credential(self, credential_id: str) -> Credential:
raise AnonCredsHolderError("Error loading requested credential") from err

async def credential_revoked(
self, credential_id: str, fro: int = None, to: int = None
self, credential_id: str, timestamp_from: int = None, timestamp_to: int = None
) -> bool:
"""Check ledger for revocation status of credential by credential id.
Args:
ledger (BaseLedger): The ledger to check for revocation status.
credential_id (str): The ID of the credential to check.
fro (int, optional): The earliest timestamp to consider for revocation status.
Defaults to None.
to (int, optional): The latest timestamp to consider for revocation status.
Defaults to None.
timestamp_from (int, optional): The earliest timestamp to consider for
revocation status. Defaults to None.
timestamp_to (int, optional): The latest timestamp to consider for revocation
status. Defaults to None.
Returns:
bool: True if the credential is revoked, False otherwise.
Expand All @@ -498,7 +498,7 @@ async def credential_revoked(
anoncreds_registry = self.profile.inject(AnonCredsRegistry)
rev_list = (
await anoncreds_registry.get_revocation_list(
self.profile, rev_reg_id, fro, to
self.profile, rev_reg_id, timestamp_from, timestamp_to
)
).revocation_list

Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/anoncreds/tests/test_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ async def test_credential_revoked(self, mock_handle):
assert (
await self.holder.credential_revoked(
credential_id="cred-id",
to=None,
fro=None,
timestamp_to=None,
timestamp_from=None,
)
is False
)
Expand Down
18 changes: 11 additions & 7 deletions aries_cloudagent/indy/credx/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,21 @@ async def _get_credential(self, credential_id: str) -> Credential:
raise IndyHolderError("Error loading requested credential") from err

async def credential_revoked(
self, ledger: BaseLedger, credential_id: str, fro: int = None, to: int = None
self,
ledger: BaseLedger,
credential_id: str,
timestamp_from: int = None,
timestamp_to: int = None,
) -> bool:
"""Check ledger for revocation status of credential by cred id.
Args:
ledger (BaseLedger): The ledger to check for revocation status.
credential_id (str): The ID of the credential to check.
fro (int, optional): The starting sequence number of the revocation registry
delta. Defaults to None.
to (int, optional): The ending sequence number of the revocation registry
delta. Defaults to None.
timestamp_from (int, optional): The starting sequence number of the revocation
registry delta. Defaults to None.
timestamp_to (int, optional): The ending sequence number of the revocation
registry delta. Defaults to None.
Returns:
bool: True if the credential is revoked, False otherwise.
Expand All @@ -396,8 +400,8 @@ async def credential_revoked(
cred_rev_id = cred.rev_reg_index
(rev_reg_delta, _) = await ledger.get_revoc_reg_delta(
rev_reg_id,
fro,
to,
timestamp_from,
timestamp_to,
)
return cred_rev_id in rev_reg_delta["value"].get("revoked", [])
else:
Expand Down
14 changes: 9 additions & 5 deletions aries_cloudagent/indy/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ async def get_credential(self, credential_id: str) -> str:

@abstractmethod
async def credential_revoked(
self, ledger: BaseLedger, credential_id: str, fro: int = None, to: int = None
self,
ledger: BaseLedger,
credential_id: str,
timestamp_from: int = None,
timestamp_to: int = None,
) -> bool:
"""Check ledger for revocation status of credential by cred id.
Args:
ledger (BaseLedger): The ledger to check for revocation status.
credential_id (str): The ID of the credential to check.
fro (int, optional): The starting time of the revocation status check range.
Defaults to None.
to (int, optional): The ending time of the revocation status check range.
Defaults to None.
timestamp_from (int, optional): The starting time of the revocation status
check range. Defaults to None.
timestamp_to (int, optional): The ending time of the revocation status check
range. Defaults to None.
Returns:
bool: True if the credential is revoked, False otherwise.
Expand Down
16 changes: 9 additions & 7 deletions aries_cloudagent/indy/models/non_rev_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class Meta:

schema_class = "IndyNonRevocationIntervalSchema"

def __init__(self, fro: int = None, to: int = None, **kwargs):
def __init__(self, timestamp_from: int = None, timestamp_to: int = None, **kwargs):
"""Initialize non-revocation interval.
Args:
fro: earliest time of interest
to: latest time of interest
timestamp_from: earliest time of interest
timestamp_to: latest time of interest
kwargs: additional attributes
"""
super().__init__(**kwargs)
self.fro = fro
self.to = to
self.timestamp_from = timestamp_from
self.timestamp_to = timestamp_to

def covers(self, timestamp: int = None) -> bool:
"""Whether input timestamp (default now) lies within non-revocation interval.
Expand All @@ -40,11 +40,13 @@ def covers(self, timestamp: int = None) -> bool:
"""
timestamp = timestamp or int(time())
return (self.fro or 0) <= timestamp <= (self.to or timestamp)
return (
(self.timestamp_from or 0) <= timestamp <= (self.timestamp_to or timestamp)
)

def timestamp(self) -> bool:
"""Return a timestamp that the non-revocation interval covers."""
return self.to or self.fro or int(time())
return self.timestamp_to or self.timestamp_from or int(time())


class IndyNonRevocationIntervalSchema(BaseModelSchema):
Expand Down
16 changes: 9 additions & 7 deletions aries_cloudagent/indy/models/tests/test_non_rev_interval.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from unittest import TestCase


from ..non_rev_interval import IndyNonRevocationInterval

FROM = 1000000000
TO = 1234567890

INTERVAL_FROM = IndyNonRevocationInterval(fro=FROM)
INTERVAL_TO = IndyNonRevocationInterval(to=TO)
INTERVAL = IndyNonRevocationInterval(fro=FROM, to=TO)
INTERVAL_FROM = IndyNonRevocationInterval(timestamp_from=FROM)
INTERVAL_TO = IndyNonRevocationInterval(timestamp_to=TO)
INTERVAL = IndyNonRevocationInterval(timestamp_from=FROM, timestamp_to=TO)


class TestInterval(TestCase):
Expand All @@ -18,11 +17,14 @@ def test_serde(self):
"""Test serialization and deserialization."""
for interval in (INTERVAL_FROM, INTERVAL_TO, INTERVAL):
non_revo_dict = interval.serialize()
assert non_revo_dict.get("from") == interval.fro
assert non_revo_dict.get("to") == interval.to
assert non_revo_dict.get("from") == interval.timestamp_from
assert non_revo_dict.get("to") == interval.timestamp_to

model = IndyNonRevocationInterval.deserialize(non_revo_dict)
assert model.fro == interval.fro and model.to == interval.to
assert (
model.timestamp_from == interval.timestamp_from
and model.timestamp_to == interval.timestamp_to
)
assert model.timestamp()

def test_covers(self):
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/indy/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def indy_proof_req2non_revoc_intervals(indy_proof_req: dict):
indy_proof_req.get("non_revoked"),
)
if interval:
fro = interval.get("from")
to = interval.get("to")
if (to is not None) and fro == to:
timestamp_from = interval.get("from")
timestamp_to = interval.get("to")
if (timestamp_to is not None) and timestamp_from == timestamp_to:
interval["from"] = 0 # accommodate indy-sdk verify=False if fro=to
non_revoc_intervals[reft] = interval
return non_revoc_intervals
10 changes: 5 additions & 5 deletions aries_cloudagent/revocation/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ async def list_issuer_registries(self) -> Sequence[IssuerRevRegRecord]:
return await IssuerRevRegRecord.query(session)

async def get_issuer_rev_reg_delta(
self, rev_reg_id: str, fro: int = None, to: int = None
self, rev_reg_id: str, timestamp_from: int = None, timestamp_to: int = None
) -> dict:
"""Check ledger for revocation status for a given revocation registry.
Args:
rev_reg_id (str): ID of the revocation registry
fro (int, optional): The sequence number to start from (exclusive).
timestamp_from (int, optional): The sequence number to start from (exclusive).
Defaults to None.
to (int, optional): The sequence number to end at (inclusive).
timestamp_to (int, optional): The sequence number to end at (inclusive).
Defaults to None.
Returns:
Expand All @@ -222,8 +222,8 @@ async def get_issuer_rev_reg_delta(
async with ledger:
(rev_reg_delta, _) = await ledger.get_revoc_reg_delta(
rev_reg_id,
fro,
to,
timestamp_from,
timestamp_to,
)

return rev_reg_delta
Expand Down
16 changes: 9 additions & 7 deletions aries_cloudagent/revocation/models/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class Meta:

schema_class = "NonRevocationIntervalSchema"

def __init__(self, fro: int = None, to: int = None, **kwargs):
def __init__(self, timestamp_from: int = None, timestamp_to: int = None, **kwargs):
"""Initialize non-revocation interval.
Args:
fro: earliest time of interest
to: latest time of interest
timestamp_from: earliest time of interest
timestamp_to: latest time of interest
kwargs: additional keyword arguments
"""
super().__init__(**kwargs)
self.fro = fro
self.to = to
self.timestamp_from = timestamp_from
self.timestamp_to = timestamp_to

def covers(self, timestamp: int = None) -> bool:
"""Whether input timestamp (default now) lies within non-revocation interval.
Expand All @@ -40,11 +40,13 @@ def covers(self, timestamp: int = None) -> bool:
"""
timestamp = timestamp or int(time())
return (self.fro or 0) <= timestamp <= (self.to or timestamp)
return (
(self.timestamp_from or 0) <= timestamp <= (self.timestamp_to or timestamp)
)

def timestamp(self) -> bool:
"""Return a timestamp that the non-revocation interval covers."""
return self.to or self.fro or int(time())
return self.timestamp_to or self.timestamp_from or int(time())


class NonRevocationIntervalSchema(BaseModelSchema):
Expand Down
16 changes: 9 additions & 7 deletions aries_cloudagent/revocation/models/tests/test_indy.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from unittest import TestCase


from ..indy import NonRevocationInterval

FROM = 1000000000
TO = 1234567890

INTERVAL_FROM = NonRevocationInterval(fro=FROM)
INTERVAL_TO = NonRevocationInterval(to=TO)
INTERVAL = NonRevocationInterval(fro=FROM, to=TO)
INTERVAL_FROM = NonRevocationInterval(timestamp_from=FROM)
INTERVAL_TO = NonRevocationInterval(timestamp_to=TO)
INTERVAL = NonRevocationInterval(timestamp_from=FROM, timestamp_to=TO)


class TestInterval(TestCase):
Expand All @@ -18,11 +17,14 @@ def test_serde(self):
"""Test serialization and deserialization."""
for interval in (INTERVAL_FROM, INTERVAL_TO, INTERVAL):
non_revo_dict = interval.serialize()
assert non_revo_dict.get("from") == interval.fro
assert non_revo_dict.get("to") == interval.to
assert non_revo_dict.get("from") == interval.timestamp_from
assert non_revo_dict.get("to") == interval.timestamp_to

model = NonRevocationInterval.deserialize(non_revo_dict)
assert model.fro == interval.fro and model.to == interval.to
assert (
model.timestamp_from == interval.timestamp_from
and model.timestamp_to == interval.timestamp_to
)
assert model.timestamp()

def test_covers(self):
Expand Down

0 comments on commit 4670ed6

Please sign in to comment.