Skip to content

Commit a20d33d

Browse files
committed
makify now ensures correct ordering of all fields
1 parent 8521368 commit a20d33d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/keri/core/serdering.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,15 @@ def makify(self, sad, *, version=None,
780780
value = copy.copy(value) # copy iterable defaults
781781
sad[label] = value
782782

783-
# Need to insert required fields in proper place because passed in sad
784-
# may have missing require fields that appear before provided ones so
785-
# can't simply append
783+
sadold = sad
784+
sad = {}
785+
for label in oalls: # make sure all fields are in correct order
786+
if label in sadold:
787+
sad[label] = sadold[label]
788+
789+
for label in sadold: # copy extras if any
790+
if label not in sad:
791+
sad[label] = sadold[label]
786792

787793
if 't' in sad: # when packet type field then force ilk
788794
sad['t'] = ilk # assign ilk

tests/core/test_serdering.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,10 @@ def test_serder():
606606
sad = serder.sad
607607
sad["ri"] = ""
608608

609-
with pytest.raises(kering.SerializeError):
610-
serder = Serder(makify=True, sad=sad) # make using sad
611-
609+
serder = Serder(makify=True, sad=sad) # make using sad fixes order
612610

613611
# extra field with strict
614612
sad = serder.sad
615-
assert 'ri' not in sad
616613
sad["x"] = ""
617614

618615
with pytest.raises(kering.SerializeError):
@@ -659,8 +656,7 @@ def test_serder():
659656
# out of order with extra
660657
sad = serder.sad
661658
sad["ri"] = ""
662-
with pytest.raises(kering.SerializeError):
663-
serder = Serder(makify=True, sad=sad) # make using sad
659+
serder = Serder(makify=True, sad=sad) # makify fixes order with extra
664660

665661
# ToDo: create malicious raw values to test verify more thoroughly
666662
# ToDo: create bad sad values to test makify more thoroughly
@@ -1313,6 +1309,7 @@ def test_serderkeri_dip():
13131309
assert serder.verify()
13141310

13151311
raw = serder.raw
1312+
sad = serder.sad
13161313
said = serder.said
13171314
size = serder.size
13181315
ilk = serder.ilk

0 commit comments

Comments
 (0)