fix encoding of length > 128

This commit is contained in:
Thomas Bernard 2021-01-12 01:01:47 +01:00
parent 6ce08c5871
commit f8b45ab854
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
1 changed files with 3 additions and 5 deletions

View File

@ -8,12 +8,10 @@ def codelength(s):
l = len(s) l = len(s)
if l == 0: if l == 0:
return b'\x00' return b'\x00'
encodedlen = b'' encodedlen = (l & 0x7F).to_bytes(1, 'little')
while l > 0: while l > 0x7F:
c = l & 0x7F
l = l >> 7 l = l >> 7
if l > 0: c = (l & 0x7F) | 0x80
c = c + 128
encodedlen = c.to_bytes(1, 'little') + encodedlen encodedlen = c.to_bytes(1, 'little') + encodedlen
return encodedlen + s return encodedlen + s