mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
refactor(core/cardano): Clean up variable_length_encode().
This commit is contained in:
parent
97ca1e3341
commit
2964f2e855
@ -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]:
|
||||
|
Loading…
Reference in New Issue
Block a user