refactor(prodtest): factor out `find_pairing_key()`
What changed, and why it matters
This commit is a simple code cleanup in Trezor's production-test tooling. It moves a small block of code that searches for an available pairing key into its own helper function, then replaces the original inline code with a call to that helper. No behavior changes are visible in the diff, and the file is part of the factory/production test suite rather than end-user wallet firmware.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors prodtest_tropic_stress_test() in core/embed/projects/prodtest/cmd/prodtest_tropic.c. A loop that iterates over Tropic pairing-key slots and calls tropic_custom_session_start() is extracted into a new static helper find_pairing_key(cli_t* cli, lt_pkey_index_t* pairing_key_index). The helper returns true on success and false on failure, preserving the original error-reporting paths. The caller now checks the boolean return value instead of comparing pairing_key_index == -1. Logic, error messages, and control flow are unchanged.
Changed components
core/embed/projects/prodtest/cmd/prodtest_tropic.cInspect captured patch +23 / −18
diff --git a/core/embed/projects/prodtest/cmd/prodtest_tropic.c b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
index 55f5f194..9f24fbfb 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_tropic.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
@@ -1620,6 +1620,28 @@ cleanup:
tropic_deinit();
}
+static bool find_pairing_key(cli_t* cli, lt_pkey_index_t* pairing_key_index) {
+ *pairing_key_index = -1;
+
+ for (lt_pkey_index_t i = TROPIC_FACTORY_PAIRING_KEY_SLOT;
+ i <= TROPIC_PRIVILEGED_PAIRING_KEY_SLOT; i++) {
+ lt_ret_t res = tropic_custom_session_start(cli, i);
+ if (res == LT_OK) {
+ *pairing_key_index = i;
+ return true;
+ }
+ if (res != LT_L2_HSK_ERR) {
+ cli_error(
+ cli, CLI_ERROR,
+ "`tropic_custom_session_start()` for key %d failed with error '%s'",
+ i, lt_ret_verbose(res));
+ return false;
+ }
+ }
+
+ return false;
+}
+
static void prodtest_tropic_stress_test(cli_t* cli) {
if (cli_arg_count(cli) > 6) {
cli_error_arg_count(cli);
@@ -1694,24 +1716,7 @@ static void prodtest_tropic_stress_test(cli_t* cli) {
lt_ret_t res = LT_FAIL;
lt_pkey_index_t pairing_key_index = -1;
- // Find an available pairing key
- for (lt_pkey_index_t i = TROPIC_FACTORY_PAIRING_KEY_SLOT;
- i <= TROPIC_PRIVILEGED_PAIRING_KEY_SLOT; i++) {
- res = tropic_custom_session_start(cli, i);
- if (res == LT_OK) {
- pairing_key_index = i;
- break;
- }
- if (res != LT_L2_HSK_ERR) {
- cli_error(
- cli, CLI_ERROR,
- "`tropic_custom_session_start() for key %d failed with error '%s'", i,
- lt_ret_verbose(res));
- return;
- }
- }
-
- if (pairing_key_index == -1) {
+ if (!find_pairing_key(cli, &pairing_key_index)) {
cli_error(cli, CLI_ERROR, "No pairing key is available");
return;
}
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.