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)
if l == 0:
return b'\x00'
encodedlen = b''
while l > 0:
c = l & 0x7F
encodedlen = (l & 0x7F).to_bytes(1, 'little')
while l > 0x7F:
l = l >> 7
if l > 0:
c = c + 128
c = (l & 0x7F) | 0x80
encodedlen = c.to_bytes(1, 'little') + encodedlen
return encodedlen + s