From f0ab88907c15093f09678e76f5de937ed0e4d98a Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Wed, 21 Sep 2022 19:01:33 +0530 Subject: [PATCH 1/5] Increase the defined max word length to 16 to match wallet names The ui_list component is defined with rows size of 15 in one of its parameter. Using the component to list wallet names results in trimming of last letter of the wallet name. Fixes https://app.clickup.com/t/37308523/CHI-2010 --- common/coin_support/wallet.h | 2 +- common/interfaces/user_interface/ui_list.c | 2 +- common/interfaces/user_interface/ui_list.h | 4 ++-- common/libraries/util/utils.c | 4 ++-- common/libraries/util/utils.h | 4 ++-- src/level_four/card_health_check/cyt_card_hc.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/coin_support/wallet.h b/common/coin_support/wallet.h index afed8ed2f..3a160e95b 100644 --- a/common/coin_support/wallet.h +++ b/common/coin_support/wallet.h @@ -42,7 +42,7 @@ #define MAX_NUMBER_OF_MNEMONIC_WORDS 24 /// Max length of mnemonic word -#define MAX_MNEMONIC_WORD_LENGTH 15 +#define MAX_MNEMONIC_WORD_LENGTH 16 /// Max length of passphrase entered #define MAX_PASSPHRASE_INPUT_LENGTH 65 diff --git a/common/interfaces/user_interface/ui_list.c b/common/interfaces/user_interface/ui_list.c index 1433448f1..80007833b 100644 --- a/common/interfaces/user_interface/ui_list.c +++ b/common/interfaces/user_interface/ui_list.c @@ -63,7 +63,7 @@ static struct List_Data* data = NULL; static struct List_Object* obj = NULL; -void list_init(const char option_list[24][15], const int number_of_options, const char* heading, bool dynamic_heading) +void list_init(const char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], const int number_of_options, const char* heading, bool dynamic_heading) { ASSERT(option_list != NULL); ASSERT(heading != NULL); diff --git a/common/interfaces/user_interface/ui_list.h b/common/interfaces/user_interface/ui_list.h index d323c8621..029a546f2 100644 --- a/common/interfaces/user_interface/ui_list.h +++ b/common/interfaces/user_interface/ui_list.h @@ -23,7 +23,7 @@ * @note */ struct List_Data { - char option_list[24][15]; + char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]; int number_of_options; int current_index; bool dynamic_heading; @@ -65,7 +65,7 @@ struct List_Object { * * @note Do not use this if number of options to be displayed in list is 1. */ -void list_init(const char option_list[24][15], int number_of_options, const char *heading, bool dynamic_heading); +void list_init(const char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], int number_of_options, const char *heading, bool dynamic_heading); /** * @brief Create UI for list diff --git a/common/libraries/util/utils.c b/common/libraries/util/utils.c index d1f736c2a..4a5cbdd20 100644 --- a/common/libraries/util/utils.c +++ b/common/libraries/util/utils.c @@ -152,7 +152,7 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, const uint32_t byte_len, return (i * 2 + 1); } -void __single_to_multi_line(const char* input, const uint16_t input_len, char output[24][15]) +void __single_to_multi_line(const char* input, const uint16_t input_len, char output[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]) { if (input == NULL || output == NULL) return; uint16_t i = 0U; @@ -174,7 +174,7 @@ void __single_to_multi_line(const char* input, const uint16_t input_len, char ou } } -void __multi_to_single_line(const char input[24][15], const uint8_t number_of_mnemonics, char* output) +void __multi_to_single_line(const char input[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], const uint8_t number_of_mnemonics, char* output) { if (input == NULL || output == NULL) return; uint8_t word_len; diff --git a/common/libraries/util/utils.h b/common/libraries/util/utils.h index 8f1600ac0..5f645249a 100644 --- a/common/libraries/util/utils.h +++ b/common/libraries/util/utils.h @@ -131,7 +131,7 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, uint32_t len, char *hex_ * * @note */ -void __single_to_multi_line(const char* input, uint16_t input_len, char output[24][15]); +void __single_to_multi_line(const char* input, uint16_t input_len, char output[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]); /** * @brief convert multi-d mnemonics to single-d array for trezor crypto functions @@ -149,7 +149,7 @@ void __single_to_multi_line(const char* input, uint16_t input_len, char output[2 * * @note */ -void __multi_to_single_line(const char input[24][15], uint8_t number_of_mnemonics, char *output); +void __multi_to_single_line(const char input[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], uint8_t number_of_mnemonics, char *output); /** * @brief Converts a hex string to a byte array. diff --git a/src/level_four/card_health_check/cyt_card_hc.c b/src/level_four/card_health_check/cyt_card_hc.c index 7d00daaad..8b1818997 100644 --- a/src/level_four/card_health_check/cyt_card_hc.c +++ b/src/level_four/card_health_check/cyt_card_hc.c @@ -105,7 +105,7 @@ void cyt_card_hc() { message_scr_init(ui_text_no_wallets_present); } else if(wallet_count <= MAX_WALLETS_ALLOWED){ - char choices[MAX_WALLETS_ALLOWED][15]={"","","",""}, heading[50]; + char choices[MAX_WALLETS_ALLOWED][16]={"","","",""}, heading[50]; for(int i=0; i < wallet_count; i++){ strcpy(choices[i], (char*)wallet_list[i][0]); } From 6bec56ffb7413ccb812d3d9abca2265a295cdbf3 Mon Sep 17 00:00:00 2001 From: Aman Agarwal Date: Thu, 29 Sep 2022 12:58:06 +0530 Subject: [PATCH 2/5] updated macros used for ui list component --- common/coin_support/wallet.h | 6 +++--- common/interfaces/user_interface/ui_list.c | 2 +- common/interfaces/user_interface/ui_list.h | 9 ++++++--- src/level_four/card_health_check/cyt_card_hc.c | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common/coin_support/wallet.h b/common/coin_support/wallet.h index 3a160e95b..b9f5f92a1 100644 --- a/common/coin_support/wallet.h +++ b/common/coin_support/wallet.h @@ -42,13 +42,13 @@ #define MAX_NUMBER_OF_MNEMONIC_WORDS 24 /// Max length of mnemonic word -#define MAX_MNEMONIC_WORD_LENGTH 16 +#define MAX_MNEMONIC_WORD_LENGTH 9 /// Max length of passphrase entered #define MAX_PASSPHRASE_INPUT_LENGTH 65 -/// Max length of coin name (set as some MAX_MNEMONIC_WORD_LENGTH because they both use ui_list) -#define MAX_COIN_NAME_LENGTH MAX_MNEMONIC_WORD_LENGTH +/// Max length of coin name +#define MAX_COIN_NAME_LENGTH MAX_UI_LIST_CHAR_LEN /// Returns 0 if PIN is not set else 1 diff --git a/common/interfaces/user_interface/ui_list.c b/common/interfaces/user_interface/ui_list.c index 80007833b..f6458cbed 100644 --- a/common/interfaces/user_interface/ui_list.c +++ b/common/interfaces/user_interface/ui_list.c @@ -63,7 +63,7 @@ static struct List_Data* data = NULL; static struct List_Object* obj = NULL; -void list_init(const char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], const int number_of_options, const char* heading, bool dynamic_heading) +void list_init(const char option_list[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], const int number_of_options, const char* heading, bool dynamic_heading) { ASSERT(option_list != NULL); ASSERT(heading != NULL); diff --git a/common/interfaces/user_interface/ui_list.h b/common/interfaces/user_interface/ui_list.h index 029a546f2..0f1a117f6 100644 --- a/common/interfaces/user_interface/ui_list.h +++ b/common/interfaces/user_interface/ui_list.h @@ -12,7 +12,10 @@ #include "ui_common.h" -//TODO : Add constant +//TODO: Update count for higher coin list +#define MAX_UI_LIST_WORDS 24 +#define MAX_UI_LIST_CHAR_LEN 16 + /** * @brief struct to store list data * @details @@ -23,7 +26,7 @@ * @note */ struct List_Data { - char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]; + char option_list[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]; int number_of_options; int current_index; bool dynamic_heading; @@ -65,7 +68,7 @@ struct List_Object { * * @note Do not use this if number of options to be displayed in list is 1. */ -void list_init(const char option_list[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], int number_of_options, const char *heading, bool dynamic_heading); +void list_init(const char option_list[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], int number_of_options, const char *heading, bool dynamic_heading); /** * @brief Create UI for list diff --git a/src/level_four/card_health_check/cyt_card_hc.c b/src/level_four/card_health_check/cyt_card_hc.c index 8b1818997..133809d4e 100644 --- a/src/level_four/card_health_check/cyt_card_hc.c +++ b/src/level_four/card_health_check/cyt_card_hc.c @@ -105,7 +105,7 @@ void cyt_card_hc() { message_scr_init(ui_text_no_wallets_present); } else if(wallet_count <= MAX_WALLETS_ALLOWED){ - char choices[MAX_WALLETS_ALLOWED][16]={"","","",""}, heading[50]; + char choices[MAX_WALLETS_ALLOWED][MAX_UI_LIST_CHAR_LEN]={"","","",""}, heading[50]; for(int i=0; i < wallet_count; i++){ strcpy(choices[i], (char*)wallet_list[i][0]); } From 12cc1079902bc75220b586564228ccc437b431b2 Mon Sep 17 00:00:00 2001 From: amanCypherock <102408904+amanCypherock@users.noreply.github.com> Date: Tue, 1 Nov 2022 17:00:53 +0530 Subject: [PATCH 3/5] Updated mnemonic max size --- common/coin_support/wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/coin_support/wallet.h b/common/coin_support/wallet.h index b9f5f92a1..fba010f19 100644 --- a/common/coin_support/wallet.h +++ b/common/coin_support/wallet.h @@ -42,7 +42,7 @@ #define MAX_NUMBER_OF_MNEMONIC_WORDS 24 /// Max length of mnemonic word -#define MAX_MNEMONIC_WORD_LENGTH 9 +#define MAX_MNEMONIC_WORD_LENGTH 16 /// Max length of passphrase entered #define MAX_PASSPHRASE_INPUT_LENGTH 65 From f4b9fbd6ab7a179ec8f1beb499a145cbb98b3641 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Wed, 12 Apr 2023 22:22:09 +0530 Subject: [PATCH 4/5] fix (Style): Accept clang-format suggested changes --- common/interfaces/user_interface/ui_list.h | 6 +++--- common/libraries/util/utils.c | 14 ++++++++------ common/libraries/util/utils.h | 14 ++++++++------ src/level_four/card_health_check/cyt_card_hc.c | 6 +++++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/common/interfaces/user_interface/ui_list.h b/common/interfaces/user_interface/ui_list.h index d8e840763..828e79bff 100644 --- a/common/interfaces/user_interface/ui_list.h +++ b/common/interfaces/user_interface/ui_list.h @@ -13,10 +13,10 @@ #include "ui_common.h" -#define MAX_UI_LIST_WORDS 24 -#define MAX_UI_LIST_CHAR_LEN 16 +#define MAX_UI_LIST_WORDS 24 +#define MAX_UI_LIST_CHAR_LEN 16 -//TODO: Update count for higher coin list +// TODO: Update count for higher coin list /** * @brief struct to store list data diff --git a/common/libraries/util/utils.c b/common/libraries/util/utils.c index 85b75a19b..cf82d5a16 100644 --- a/common/libraries/util/utils.c +++ b/common/libraries/util/utils.c @@ -174,9 +174,10 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, return (i * 2 + 1); } -void __single_to_multi_line(const char *input, - const uint16_t input_len, - char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]) { +void __single_to_multi_line( + const char *input, + const uint16_t input_len, + char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]) { if (input == NULL || output == NULL) return; uint16_t i = 0U; @@ -198,9 +199,10 @@ void __single_to_multi_line(const char *input, } } -void __multi_to_single_line(const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], - const uint8_t number_of_mnemonics, - char *output) { +void __multi_to_single_line( + const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], + const uint8_t number_of_mnemonics, + char *output) { if (input == NULL || output == NULL) return; uint8_t word_len; diff --git a/common/libraries/util/utils.h b/common/libraries/util/utils.h index c8513f148..c9af9414d 100644 --- a/common/libraries/util/utils.h +++ b/common/libraries/util/utils.h @@ -182,9 +182,10 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, * * @note */ -void __single_to_multi_line(const char *input, - uint16_t input_len, - char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]); +void __single_to_multi_line( + const char *input, + uint16_t input_len, + char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]); /** * @brief convert multi-d mnemonics to single-d array for trezor crypto @@ -203,9 +204,10 @@ void __single_to_multi_line(const char *input, * * @note */ -void __multi_to_single_line(const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], - uint8_t number_of_mnemonics, - char *output); +void __multi_to_single_line( + const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], + uint8_t number_of_mnemonics, + char *output); /** * @brief Converts a hex string to a byte array. diff --git a/src/level_four/card_health_check/cyt_card_hc.c b/src/level_four/card_health_check/cyt_card_hc.c index e0ab1e76b..d286f9a5c 100644 --- a/src/level_four/card_health_check/cyt_card_hc.c +++ b/src/level_four/card_health_check/cyt_card_hc.c @@ -109,7 +109,11 @@ void cyt_card_hc() { if (wallet_count == 0) { message_scr_init(ui_text_no_wallets_present); } else if (wallet_count <= MAX_WALLETS_ALLOWED) { - char choices[MAX_WALLETS_ALLOWED][MAX_UI_LIST_CHAR_LEN] = {"", "", "", ""}, heading[50]; + char choices[MAX_WALLETS_ALLOWED][MAX_UI_LIST_CHAR_LEN] = {"", + "", + "", + ""}, + heading[50]; for (int i = 0; i < wallet_count; i++) { strcpy(choices[i], (char *)wallet_list[i][0]); } From 4f824350af659da67038d713c6781721fca9c6a8 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Wed, 26 Apr 2023 14:47:11 +0530 Subject: [PATCH 5/5] fix (ui): Use recursive macro def for list_init item lengths The MAX_UI_LIST_WORDS will be kept same as MAX_NUMBER_OF_MNEMONIC_WORDS and MAX_UI_LIST_CHAR_LEN := MAX_MNEMONIC_WORD_LENGTH. Applications and utils use MNEMONICS macros while ui_list will use UI_LIST macros. --- common/CMakeLists.txt | 0 common/interfaces/user_interface/ui_list.h | 4 ++-- common/libraries/util/utils.c | 4 ++-- common/libraries/util/utils.h | 4 ++-- src/level_four/card_health_check/cyt_card_hc.c | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 common/CMakeLists.txt diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb diff --git a/common/interfaces/user_interface/ui_list.h b/common/interfaces/user_interface/ui_list.h index 828e79bff..1a063aa03 100644 --- a/common/interfaces/user_interface/ui_list.h +++ b/common/interfaces/user_interface/ui_list.h @@ -13,8 +13,8 @@ #include "ui_common.h" -#define MAX_UI_LIST_WORDS 24 -#define MAX_UI_LIST_CHAR_LEN 16 +#define MAX_UI_LIST_WORDS MAX_NUMBER_OF_MNEMONIC_WORDS +#define MAX_UI_LIST_CHAR_LEN MAX_MNEMONIC_WORD_LENGTH // TODO: Update count for higher coin list diff --git a/common/libraries/util/utils.c b/common/libraries/util/utils.c index cf82d5a16..379524145 100644 --- a/common/libraries/util/utils.c +++ b/common/libraries/util/utils.c @@ -177,7 +177,7 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, void __single_to_multi_line( const char *input, const uint16_t input_len, - char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]) { + char output[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]) { if (input == NULL || output == NULL) return; uint16_t i = 0U; @@ -200,7 +200,7 @@ void __single_to_multi_line( } void __multi_to_single_line( - const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], + const char input[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], const uint8_t number_of_mnemonics, char *output) { if (input == NULL || output == NULL) diff --git a/common/libraries/util/utils.h b/common/libraries/util/utils.h index c9af9414d..d90d59b8c 100644 --- a/common/libraries/util/utils.h +++ b/common/libraries/util/utils.h @@ -185,7 +185,7 @@ uint32_t byte_array_to_hex_string(const uint8_t *bytes, void __single_to_multi_line( const char *input, uint16_t input_len, - char output[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN]); + char output[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH]); /** * @brief convert multi-d mnemonics to single-d array for trezor crypto @@ -205,7 +205,7 @@ void __single_to_multi_line( * @note */ void __multi_to_single_line( - const char input[MAX_UI_LIST_WORDS][MAX_UI_LIST_CHAR_LEN], + const char input[MAX_NUMBER_OF_MNEMONIC_WORDS][MAX_MNEMONIC_WORD_LENGTH], uint8_t number_of_mnemonics, char *output); diff --git a/src/level_four/card_health_check/cyt_card_hc.c b/src/level_four/card_health_check/cyt_card_hc.c index d286f9a5c..fcbb39df8 100644 --- a/src/level_four/card_health_check/cyt_card_hc.c +++ b/src/level_four/card_health_check/cyt_card_hc.c @@ -109,10 +109,10 @@ void cyt_card_hc() { if (wallet_count == 0) { message_scr_init(ui_text_no_wallets_present); } else if (wallet_count <= MAX_WALLETS_ALLOWED) { - char choices[MAX_WALLETS_ALLOWED][MAX_UI_LIST_CHAR_LEN] = {"", - "", - "", - ""}, + char choices[MAX_WALLETS_ALLOWED][MAX_MNEMONIC_WORD_LENGTH] = {"", + "", + "", + ""}, heading[50]; for (int i = 0; i < wallet_count; i++) { strcpy(choices[i], (char *)wallet_list[i][0]);