2022-09-21 07:56:28 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2020-06-24 12:25:48 +00:00
|
|
|
|
2022-09-21 07:56:28 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from trezor.utils import BufferReader
|
2020-06-24 12:25:48 +00:00
|
|
|
|
2020-07-13 11:57:36 +00:00
|
|
|
|
2021-03-19 20:22:30 +00:00
|
|
|
def read_memoryview_prefixed(r: BufferReader) -> memoryview:
|
2022-09-21 07:56:28 +00:00
|
|
|
from apps.common.readers import read_compact_size
|
|
|
|
|
2022-01-17 12:03:21 +00:00
|
|
|
n = read_compact_size(r)
|
2021-03-19 20:22:30 +00:00
|
|
|
return r.read_memoryview(n)
|
2020-06-24 12:25:48 +00:00
|
|
|
|
|
|
|
|
2020-07-13 11:57:36 +00:00
|
|
|
def read_op_push(r: BufferReader) -> int:
|
2022-09-21 07:56:28 +00:00
|
|
|
get = r.get # local_cache_attribute
|
|
|
|
|
|
|
|
prefix = get()
|
2020-06-24 12:25:48 +00:00
|
|
|
if prefix < 0x4C:
|
|
|
|
n = prefix
|
|
|
|
elif prefix == 0x4C:
|
2022-09-21 07:56:28 +00:00
|
|
|
n = get()
|
2020-06-24 12:25:48 +00:00
|
|
|
elif prefix == 0x4D:
|
2022-09-21 07:56:28 +00:00
|
|
|
n = get()
|
|
|
|
n += get() << 8
|
2020-06-24 12:25:48 +00:00
|
|
|
elif prefix == 0x4E:
|
2022-09-21 07:56:28 +00:00
|
|
|
n = get()
|
|
|
|
n += get() << 8
|
|
|
|
n += get() << 16
|
|
|
|
n += get() << 24
|
2020-06-24 12:25:48 +00:00
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
return n
|