psbt: remove branching for getting public/private key function call
What changed, and why it matters
This commit is a small internal code cleanup in a Bitcoin hardware wallet library. It replaces an if/else branch that chose between two similar key-lookup functions with a single function pointer. There is no change to what data is read, what keys are used, or what is returned to the caller. It is a stylistic refactor, not a security fix.
No security action needed. Treat as a normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In main/utils/psbt.c, the key_iter_next() function previously branched on iter->is_private to call either wally_map_keypath_get_bip32_key_from() or wally_map_keypath_get_bip32_public_key_from(). The patch introduces a typedef and a function pointer that selects the same function based on iter->is_private, then calls it once. The arguments, return-value handling, and subsequent logic are unchanged. No security boundary or cryptographic behavior is modified.
Changed components
main/utils/psbt.cInspect captured patch +7 / −7
diff --git a/main/utils/psbt.c b/main/utils/psbt.c
index 5c0addf..27fa012 100644
--- a/main/utils/psbt.c
+++ b/main/utils/psbt.c
@@ -92,13 +92,13 @@ bool key_iter_next(key_iter* iter)
}
if (iter->is_valid) {
int ret;
- if (iter->is_private) {
- ret = wally_map_keypath_get_bip32_key_from(
- keypaths, iter->key_index, &keychain_get()->xpriv, &iter->hdkey, &key_index);
- } else {
- ret = wally_map_keypath_get_bip32_public_key_from(
- keypaths, iter->key_index, &keychain_get()->xpriv, &iter->hdkey, &key_index);
- }
+ typedef int (*get_bip32_key_fn)(
+ const struct wally_map*, size_t, const struct ext_key*, struct ext_key*, size_t*);
+ get_bip32_key_fn get_key
+ = iter->is_private ? wally_map_keypath_get_bip32_key_from : wally_map_keypath_get_bip32_public_key_from;
+
+ ret = get_key(keypaths, iter->key_index, &keychain_get()->xpriv, &iter->hdkey, &key_index);
+
JADE_WALLY_VERIFY(ret);
if (key_index) {
iter->is_valid = true; // Found
Why this scored 12/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.