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:
parent
97ca1e3341
commit
2964f2e855
@ -18,17 +18,12 @@ def variable_length_encode(number: int) -> bytes:
|
|||||||
if number < 0:
|
if number < 0:
|
||||||
raise ValueError("Negative numbers not supported. Number supplied: %s" % number)
|
raise ValueError("Negative numbers not supported. Number supplied: %s" % number)
|
||||||
|
|
||||||
encoded = []
|
encoded = [number & 0x7F]
|
||||||
|
while number > 0x7F:
|
||||||
bit_length = len(bin(number)[2:])
|
|
||||||
encoded.append(number & 127)
|
|
||||||
|
|
||||||
while bit_length > 7:
|
|
||||||
number >>= 7
|
number >>= 7
|
||||||
bit_length -= 7
|
encoded.append((number & 0x7F) + 0x80)
|
||||||
encoded.insert(0, (number & 127) + 128)
|
|
||||||
|
|
||||||
return bytes(encoded)
|
return bytes(reversed(encoded))
|
||||||
|
|
||||||
|
|
||||||
def to_account_path(path: list[int]) -> list[int]:
|
def to_account_path(path: list[int]) -> list[int]:
|
||||||
|
Loading…
Reference in New Issue
Block a user