Skip to content

Commit

Permalink
Merge pull request #1475 from ianco/neg_encoding_fix
Browse files Browse the repository at this point in the history
Update credential and proof mappings to allow negative encoded values
  • Loading branch information
ianco committed Nov 3, 2021
2 parents ed9ab88 + 19ba4b0 commit aca310c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions aries_cloudagent/indy/models/cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
INDY_CRED_DEF_ID,
INDY_REV_REG_ID,
INDY_SCHEMA_ID,
NUM_STR_WHOLE,
NUM_STR_ANY,
)


Expand Down Expand Up @@ -44,7 +44,7 @@ class Meta:
encoded = fields.Str(
required=True,
description="Attribute encoded value",
**NUM_STR_WHOLE,
**NUM_STR_ANY,
)


Expand Down
5 changes: 3 additions & 2 deletions aries_cloudagent/indy/models/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
INDY_SCHEMA_ID,
INT_EPOCH,
NUM_STR_WHOLE,
NUM_STR_ANY,
)
from ...utils.tracing import AdminAPIMessageTracingSchema

Expand Down Expand Up @@ -60,7 +61,7 @@ class Meta:

revealed_attrs = fields.Dict(
keys=fields.Str(example="preference"),
values=fields.Str(**NUM_STR_WHOLE),
values=fields.Str(**NUM_STR_ANY),
)
a_prime = fields.Str(**NUM_STR_WHOLE)
e = fields.Str(**NUM_STR_WHOLE)
Expand Down Expand Up @@ -375,7 +376,7 @@ class Meta:
unknown = EXCLUDE

raw = fields.Str(description="Raw value")
encoded = fields.Str(description="Encoded value", **NUM_STR_WHOLE)
encoded = fields.Str(description="Encoded value", **NUM_STR_ANY)


class IndyProofRequestedProofRevealedAttr(RawEncoded):
Expand Down
16 changes: 16 additions & 0 deletions aries_cloudagent/messaging/valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ def __init__(self):
)


class NumericStrAny(Regexp):
"""Validate value against any number numeric string."""

EXAMPLE = "-1"
PATTERN = r"^-?[0-9]*$"

def __init__(self):
"""Initializer."""

super().__init__(
NumericStrAny.PATTERN,
error="Value {input} is not a numeric string",
)


class NaturalNumber(Range):
"""Validate value as positive integer."""

Expand Down Expand Up @@ -762,6 +777,7 @@ def __init__(
INT_EPOCH = {"validate": IntEpoch(), "example": IntEpoch.EXAMPLE}
WHOLE_NUM = {"validate": WholeNumber(), "example": WholeNumber.EXAMPLE}
NUM_STR_WHOLE = {"validate": NumericStrWhole(), "example": NumericStrWhole.EXAMPLE}
NUM_STR_ANY = {"validate": NumericStrAny(), "example": NumericStrAny.EXAMPLE}
NATURAL_NUM = {"validate": NaturalNumber(), "example": NaturalNumber.EXAMPLE}
NUM_STR_NATURAL = {
"validate": NumericStrNatural(),
Expand Down

0 comments on commit aca310c

Please sign in to comment.