1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-12 01:18:14 +00:00
trezor-firmware/core/src/apps/common/readers.py

38 lines
742 B
Python
Raw Normal View History

from trezor.utils import BufferReader
def read_bitcoin_varint(r: BufferReader) -> int:
prefix = r.get()
if prefix < 253:
n = prefix
elif prefix == 253:
n = r.get()
n += r.get() << 8
elif prefix == 254:
n = r.get()
n += r.get() << 8
n += r.get() << 16
n += r.get() << 24
else:
raise ValueError
return n
def read_uint16_be(r: BufferReader) -> int:
n = r.get()
return (n << 8) + r.get()
def read_uint32_be(r: BufferReader) -> int:
n = r.get()
for _ in range(3):
n = (n << 8) + r.get()
return n
def read_uint64_be(r: BufferReader) -> int:
n = r.get()
for _ in range(7):
n = (n << 8) + r.get()
return n