noise: Sort TlvPayload fields before serializing

This is part of the spec
This commit is contained in:
Christian Decker
2020-01-20 13:52:44 +01:00
parent 11a946f152
commit c3e316d79e

View File

@@ -146,6 +146,7 @@ class TlvPayload(OnionPayload):
return default return default
def to_bytes(self): def to_bytes(self):
self.fields = sorted(self.fields, key=lambda f: f.typenum)
ser = [f.to_bytes() for f in self.fields] ser = [f.to_bytes() for f in self.fields]
b = BytesIO() b = BytesIO()
varint_encode(sum([len(b) for b in ser]), b) varint_encode(sum([len(b) for b in ser]), b)