1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00

refactor(core/cardano): Clean up variable_length_encode().

This commit is contained in:
Andrew Kozlik 2021-03-22 21:15:23 +01:00 committed by Andrew Kozlik
parent 97ca1e3341
commit 2964f2e855

View File

@ -18,17 +18,12 @@ def variable_length_encode(number: int) -> bytes:
if number < 0:
raise ValueError("Negative numbers not supported. Number supplied: %s" % number)
encoded = []
bit_length = len(bin(number)[2:])
encoded.append(number & 127)
while bit_length > 7:
encoded = [number & 0x7F]
while number > 0x7F:
number >>= 7
bit_length -= 7
encoded.insert(0, (number & 127) + 128)
encoded.append((number & 0x7F) + 0x80)
return bytes(encoded)
return bytes(reversed(encoded))
def to_account_path(path: list[int]) -> list[int]: