1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-21 12:51:03 +00:00
trezor-firmware/core/src/apps/bitcoin/readers.py

28 lines
612 B
Python
Raw Normal View History

from trezor.utils import BufferReader
from apps.common.readers import read_bitcoin_varint
def read_memoryview_prefixed(r: BufferReader) -> memoryview:
n = read_bitcoin_varint(r)
return r.read_memoryview(n)
def read_op_push(r: BufferReader) -> int:
prefix = r.get()
if prefix < 0x4C:
n = prefix
elif prefix == 0x4C:
n = r.get()
elif prefix == 0x4D:
n = r.get()
n += r.get() << 8
elif prefix == 0x4E:
n = r.get()
n += r.get() << 8
n += r.get() << 16
n += r.get() << 24
else:
raise ValueError
return n