From 66eedd164c8b2fc20994619704ddb9c5924d163c Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 19 Dec 2022 16:27:22 +0100 Subject: [PATCH] feat(python/firmware): introduce fw model field --- python/.changelog.d/2701.added.1 | 1 + python/src/trezorlib/firmware/core.py | 9 ++++++++- python/src/trezorlib/tools.py | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 python/.changelog.d/2701.added.1 diff --git a/python/.changelog.d/2701.added.1 b/python/.changelog.d/2701.added.1 new file mode 100644 index 0000000000..ef30bc87be --- /dev/null +++ b/python/.changelog.d/2701.added.1 @@ -0,0 +1 @@ +Add support for model field in firmware image. diff --git a/python/src/trezorlib/firmware/core.py b/python/src/trezorlib/firmware/core.py index ed9a75a985..b8c8533154 100644 --- a/python/src/trezorlib/firmware/core.py +++ b/python/src/trezorlib/firmware/core.py @@ -25,6 +25,7 @@ from construct_classes import Struct, subcon from .. import cosi from ..tools import EnumAdapter, TupleAdapter from . import consts, util +from .models import Model from .vendor import VendorHeader __all__ = [ @@ -47,6 +48,9 @@ class FirmwareHeader(Struct): code_length: int version: t.Tuple[int, int, int, int] fix_version: t.Tuple[int, int, int, int] + hw_model: Model + hw_revision: int + monotonic: int hashes: t.Sequence[bytes] v1_signatures: t.Sequence[bytes] @@ -69,7 +73,10 @@ class FirmwareHeader(Struct): ), "version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul), "fix_version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul), - "_reserved" / c.Padding(8), + "hw_model" / EnumAdapter(c.Bytes(4), Model), + "hw_revision" / c.Int8ul, + "monotonic" / c.Int8ul, + "_reserved" / c.Padding(2), "hashes" / c.Bytes(32)[16], "v1_signatures" / c.Bytes(64)[consts.V1_SIGNATURE_SLOTS], diff --git a/python/src/trezorlib/tools.py b/python/src/trezorlib/tools.py index 8162032b54..d33b4e50a6 100644 --- a/python/src/trezorlib/tools.py +++ b/python/src/trezorlib/tools.py @@ -382,7 +382,9 @@ class EnumAdapter(construct.Adapter): super().__init__(subcon) def _encode(self, obj: Any, ctx: Any, path: Any): - return obj.value + if isinstance(obj, self.enum): + return obj.value + return obj def _decode(self, obj: Any, ctx: Any, path: Any): try: