refactor(core): rename pairing_cache to pairing_names
What changed, and why it matters
This commit is a simple rename-only code cleanup. It changes internal names like 'paired_cache' to 'paired_names' and updates comments to clarify that the data is stored in flash and survives reboots. No behavior, logic, or security properties change.
No security action needed; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff renames the storage key constant _THP_PAIRED_CACHE to THP_PAIRED_NAMES and the accessor functions set_thp_paired_cache/get_thp_paired_cache to set_thp_paired_names/get_thp_paired_names. All call sites in paired_cache.py and the test file are updated. The underlying storage slot (0x22), serialization format, and data flow are unchanged. A docstring is added noting that the structure persists across reboots, unlike storage.cache.
Changed components
core/src/storage/device.pycore/src/trezor/wire/thp/paired_cache.pycore/tests/test_apps.thp.paired_cache.pyInspect captured patch +15 / −12
diff --git a/core/src/storage/device.py b/core/src/storage/device.py
index edeb5ad3d..8388c8bd0 100644
--- a/core/src/storage/device.py
+++ b/core/src/storage/device.py
@@ -45,7 +45,7 @@ if utils.USE_THP:
_DISABLE_HAPTIC_FEEDBACK = const(0x20) # bool (0x01 or empty)
_DISABLE_RGB_LED = const(0x21) # bool (0x01 or empty)
if utils.USE_THP:
- _THP_PAIRED_CACHE = const(0x22) # bytes
+ THP_PAIRED_NAMES = const(0x22) # bytes
if utils.USE_POWER_MANAGER:
_AUTOLOCK_DELAY_BATT_MS = const(0x23) # int
_DISABLE_BLUETOOTH = const(0x24) # bool (0x01 or empty)
@@ -472,14 +472,17 @@ def get_rgb_led() -> bool:
if utils.USE_THP:
- def set_thp_paired_cache(blob: AnyBytes) -> None:
+ def set_thp_paired_names(blob: AnyBytes) -> None:
"""
Set THP paired entries' cache (using protobuf serialization).
"""
- common.set(_NAMESPACE, _THP_PAIRED_CACHE, blob)
+ common.set(_NAMESPACE, THP_PAIRED_NAMES, blob)
- def get_thp_paired_cache() -> bytes | None:
+ def get_thp_paired_names() -> bytes | None:
"""
Get THP paired entries' cache (using protobuf serialization).
+
+ Please note that while THP calls this a cache, it is persisted
+ across reboots, unlike storage.cache.
"""
- return common.get(_NAMESPACE, _THP_PAIRED_CACHE)
+ return common.get(_NAMESPACE, THP_PAIRED_NAMES)
diff --git a/core/src/trezor/wire/thp/paired_cache.py b/core/src/trezor/wire/thp/paired_cache.py
index af5b91df7..7b8eb3ab6 100644
--- a/core/src/trezor/wire/thp/paired_cache.py
+++ b/core/src/trezor/wire/thp/paired_cache.py
@@ -14,10 +14,10 @@ _ENABLE_EXPERIMENTAL = const(False)
def load() -> list[ThpPairedCacheEntry]:
"""Load THP paired entries from flash."""
- from storage.device import get_thp_paired_cache
+ from storage.device import get_thp_paired_names
from trezor.protobuf import decode
- if (blob := get_thp_paired_cache()) is None:
+ if (blob := get_thp_paired_names()) is None:
return [] # an empty cache
cache = decode(blob, ThpPairedCache, _ENABLE_EXPERIMENTAL)
@@ -29,7 +29,7 @@ def load() -> list[ThpPairedCacheEntry]:
def store(entries: list[ThpPairedCacheEntry], _bonds: set[bytes] | None = None) -> None:
"""Store THP paired entries to flash."""
- from storage.device import set_thp_paired_cache
+ from storage.device import set_thp_paired_names
from trezor.protobuf import dump_message_buffer
if _bonds is None:
@@ -44,7 +44,7 @@ def store(entries: list[ThpPairedCacheEntry], _bonds: set[bytes] | None = None)
if __debug__:
log.debug(__name__, "storing THP cache:\n%s", utils.dump_protobuf(cache))
- set_thp_paired_cache(dump_message_buffer(cache))
+ set_thp_paired_names(dump_message_buffer(cache))
def cache_host_info(mac_addr: AnyBytes | None, host_name: str, app_name: str) -> None:
diff --git a/core/tests/test_apps.thp.paired_cache.py b/core/tests/test_apps.thp.paired_cache.py
index 67154ab5e..bc53e6213 100644
--- a/core/tests/test_apps.thp.paired_cache.py
+++ b/core/tests/test_apps.thp.paired_cache.py
@@ -3,7 +3,7 @@ from common import * # isort: skip
from trezor import config, utils
if utils.USE_THP:
- from storage.device import get_thp_paired_cache
+ from storage.device import get_thp_paired_names
from trezor.messages import ThpPairedCacheEntry
from trezor.wire.thp import paired_cache
@@ -88,7 +88,7 @@ class TestTrezorHostProtocolPairedCache(unittest.TestCase):
self.assertListEqual(paired_cache.load(), [])
def test_max_size(self):
- self.assertIsNone(get_thp_paired_cache())
+ self.assertIsNone(get_thp_paired_names())
# serialize longest `host_name` and `app_name` and maximal number of bonds
entries = [
ThpPairedCacheEntry(
@@ -100,7 +100,7 @@ class TestTrezorHostProtocolPairedCache(unittest.TestCase):
paired_cache.store(entries=entries, _bonds=bonds)
self.assertListEqual(paired_cache.load(), entries)
- cache_blob = get_thp_paired_cache()
+ cache_blob = get_thp_paired_names()
self.assertIsNotNone(cache_blob)
# Check that serialized size is not too large:
# 8 entries x (32 bytes [host name] + 32 bytes [app name] + 6 bytes [addr]) = 560 bytes
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.