refactor(python): remove nrf magic from HeaderType
What changed, and why it matters
This is a small code cleanup in Trezor's Python firmware-handling library. It removes an unused firmware header type for Nordic (NRF) chips and renames an internal 'magic' field so it is no longer treated as a user-facing header type. It also fixes two default boolean values from the integers 1 to the Python booleans True. There is no security-relevant change here.
No action required. This is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes the NRF_FIRMWARE member from the HeaderType enum in core.py and removes the HeaderType type-checking import from vendor.py. In VendorTrust, two c.Default(c.Flag, 1) values are changed to c.Default(c.Flag, True), which is semantically equivalent because construct’s Flag treats 1 as true. In VendorHeader, the ‘magic’ field is renamed to ‘_magic’ and its type annotation is removed, making it an internal constant rather than a typed HeaderType. These are refactor/cleanup changes with no functional security impact.
Changed components
python/src/trezorlib/firmware/core.pypython/src/trezorlib/firmware/vendor.pyInspect captured patch +3 / −8
diff --git a/python/src/trezorlib/firmware/core.py b/python/src/trezorlib/firmware/core.py
index 67033928..4e1407ab 100644
--- a/python/src/trezorlib/firmware/core.py
+++ b/python/src/trezorlib/firmware/core.py
@@ -45,7 +45,6 @@ class HeaderType(Enum):
FIRMWARE = b"TRZF"
BOOTLOADER = b"TRZB"
BOOTLOADER_V2 = b"TRZQ"
- NRF_FIRMWARE = bytes.fromhex("3DB8F396")
class FirmwareHeader(SanityCheckedStruct):
diff --git a/python/src/trezorlib/firmware/vendor.py b/python/src/trezorlib/firmware/vendor.py
index ada5abb3..8860eebe 100644
--- a/python/src/trezorlib/firmware/vendor.py
+++ b/python/src/trezorlib/firmware/vendor.py
@@ -35,9 +35,6 @@ __all__ = [
"VendorHeader",
]
-if t.TYPE_CHECKING:
- from . import HeaderType
-
def _transform_vendor_trust(data: bytes) -> bytes:
"""Byte-swap and bit-invert the VendorTrust field.
@@ -67,8 +64,8 @@ class VendorTrust(SanityCheckedStruct):
SUBCON = c.Transformed(
c.BitStruct(
"reserved" / c.Default(c.BitsInteger(5), 0b11111),
- "limit_runtime" / c.Default(c.Flag, 1),
- "deny_provisioning_access" / c.Default(c.Flag, 1),
+ "limit_runtime" / c.Default(c.Flag, True),
+ "deny_provisioning_access" / c.Default(c.Flag, True),
"_dont_provide_secret"
/ c.Default(c.Flag, lambda this: not this.allow_run_with_secret),
"allow_run_with_secret" / c.Flag,
@@ -93,7 +90,6 @@ class VendorTrust(SanityCheckedStruct):
class VendorHeader(SanityCheckedStruct):
- magic: HeaderType
header_len: int
expiry: int
version: tuple[int, int]
@@ -115,7 +111,7 @@ class VendorHeader(SanityCheckedStruct):
# fmt: off
SUBCON = c.Struct(
"_start_offset" / c.Tell,
- "magic" / c.Const(b"TRZV"),
+ "_magic" / c.Const(b"TRZV"),
"header_len" / c.Int32ul,
"expiry" / c.Int32ul,
"version" / TupleAdapter(c.Int8ul, c.Int8ul),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.