Skip to content

Commit

Permalink
some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithSamuelM committed Mar 8, 2024
1 parent 59544a8 commit e78b67f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
32 changes: 18 additions & 14 deletions src/keri/core/serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ class Serder:
generation and verification in addition to the required fields.
Class Attributes:
Dummy (str): dummy character for computing SAIDs
Digests (dict): map of digestive codes. Should be same set of codes as
in coring.DigestCodex coring.DigDex so that .digestive property works.
Use unit tests to ensure codex sets match
Protocol (str): default protocol version type
Proto (str): default CESR protocol genus type
Vrsn (Versionage): default version
Kind (str): default serialization kind one of Serials
Fields (dict): nested dict of field labels keyed by protocol, version,
and message type (ilk). Felds labels are provided with a Fieldage
named tuple (saids, reqs, alls) that governs field type and presence.
Expand Down Expand Up @@ -218,7 +226,7 @@ class Serder:
"""
Dummy = "#" # dummy spaceholder char for said. Must not be a valid Base64 char
Dummy = "#" # dummy spaceholder char for SAID. Must not be a valid Base64 char

# should be same set of codes as in coring.DigestCodex coring.DigDex so
# .digestive property works. Use unit tests to ensure codex sets match
Expand All @@ -237,7 +245,7 @@ class Serder:
#override in subclass to enforce specific protocol
Protocol = None # required protocol, None means any in Protos is ok

Proto = Protos.keri # default protocol type
Proto = Protos.keri # default CESR protocol type
Vrsn = Vrsn_1_0 # default protocol version for protocol type
Kind = Serials.json # default serialization kind

Expand Down Expand Up @@ -368,12 +376,6 @@ class Serder:
}


# default ilk for each protocol at default version is zeroth ilk in dict
DefaultIlks = dict()
for key, val in Fields.items():
DefaultIlks[key] = list(list(val.values())[0].keys())


def __init__(self, *, raw=b'', sad=None, strip=False, version=Version,
smellage=None, verify=True, makify=False,
proto=None, vrsn=None, kind=None, ilk=None, saids=None):
Expand Down Expand Up @@ -646,19 +648,21 @@ def makify(self, sad, *, version=None,
if proto is None:
proto = sproto if sproto is not None else self.Proto

if proto not in self.Fields:
raise SerializeError(f"Invalid protocol type = {proto}.")

if vrsn is None:
vrsn = svrsn if svrsn is not None else self.Vrsn

if vrsn not in self.Fields[proto]:
raise SerializeError(f"Invalid version = {vrsn} for protocol = {proto}.")

if kind is None:
kind = skind if skind is not None else self.Kind

if ilk is None:
ilk = silk if silk is not None else self.DefaultIlks[proto][0]


if proto not in self.Fields:
raise SerializeError(f"Invalid protocol type = {proto}.")

ilk = (silk if silk is not None else
list(self.Fields[proto][vrsn].keys())[0])

if self.Protocol and proto != self.Protocol:
raise SerializeError(f"Expected protocol = {self.Protocol}, got "
Expand Down
20 changes: 0 additions & 20 deletions tests/core/test_serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,6 @@ def test_serder():

assert Serder.Fields

# Version 1.0 ilks
assert Serder.DefaultIlks == {'KERI': ['icp',
'rot',
'ixn',
'dip',
'drt',
'rct',
'qry',
'rpy',
'pro',
'bar',
'exn',
'vcp',
'vrt',
'iss',
'rev',
'bis',
'brv'],
'ACDC': [None]}

assert Serder.Fields[kering.Protos.acdc][kering.Vrsn_1_0][None].saids == {'d': 'E'}
assert Serder.Fields[kering.Protos.acdc][kering.Vrsn_1_0][None].alls == {'v': '', 'd': '', 'i': '', 's': ''}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_kering.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def test_ilks():
"""
assert Ilks == Ilkage(icp='icp', rot='rot', ixn='ixn', dip='dip', drt='drt',
rct='rct', qry='qry', rpy='rpy',
exn='exn', pro='pro', bar='bar',
xip='xip', exn='exn', pro='pro', bar='bar',
vcp='vcp', vrt='vrt',
iss='iss', rev='rev', bis='bis', brv='brv', )

Expand Down

0 comments on commit e78b67f

Please sign in to comment.