Skip to content

Commit

Permalink
Merge pull request #237 from LedgerHQ/count_keys
Browse files Browse the repository at this point in the history
Refactor `count_distinct_keys_info`
  • Loading branch information
bigspider authored Mar 11, 2024
2 parents 205a65a + 5bcea87 commit 73b3984
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ endif

include $(BOLOS_SDK)/Makefile.defines

# TODO: compile with the right path restrictions
# TODO: Compile with the right path restrictions
#
# The right path restriction would be something like
# --path "*'/0'"
# for mainnet, and
# --path "*'/1'"
# for testnet.
#
# That is, restrict the BIP-44 coin_type, but not the purpose.
# However, such wildcards are not currently supported by the OS.
#
# Note that the app still requires explicit user approval before exporting
# any xpub outside of a small set of allowed standard paths.

# Application allowed derivation curves.
CURVE_APP_LOAD_PARAMS = secp256k1
Expand Down
15 changes: 9 additions & 6 deletions src/handler/lib/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,13 +1723,16 @@ int get_key_placeholder_by_index(const policy_node_t *policy,
}

int count_distinct_keys_info(const policy_node_t *policy) {
policy_node_key_placeholder_t placeholder;
int ret = -1, cur, n_placeholders;
int ret = -1;

for (cur = 0;
cur < (n_placeholders = get_key_placeholder_by_index(policy, cur, NULL, &placeholder));
++cur) {
if (n_placeholders < 0) {
int n_placeholders = get_key_placeholder_by_index(policy, 0, NULL, NULL);
if (n_placeholders < 0) {
return -1;
}

for (int cur = 0; cur < n_placeholders; ++cur) {
policy_node_key_placeholder_t placeholder;
if (0 > get_key_placeholder_by_index(policy, cur, NULL, &placeholder)) {
return -1;
}
ret = MAX(ret, placeholder.key_index + 1);
Expand Down

0 comments on commit 73b3984

Please sign in to comment.