From eb531de5d220f84177543bbdc0b91cff8011e0b6 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 14 Jan 2022 17:32:17 +0100 Subject: [PATCH] [clean] Linting pass --- src/eth_plugin_handler.c | 4 +- src/main.c | 2 +- src/shared_context.h | 8 ++-- .../cmd_provideNFTInfo.c | 28 +++++------ src_features/setPlugin/cmd_setPlugin.c | 22 ++++----- src_plugins/erc1155/erc1155_plugin.c | 2 +- src_plugins/erc1155/erc1155_plugin.h | 8 ++-- .../erc1155/erc1155_provide_parameters.c | 47 ++++++++----------- src_plugins/erc1155/erc1155_ui.c | 8 ++-- src_plugins/erc721/erc721_plugin.c | 2 +- src_plugins/erc721/erc721_plugin.h | 2 +- .../erc721/erc721_provide_parameters.c | 2 +- src_plugins/erc721/erc721_ui.c | 4 +- 13 files changed, 65 insertions(+), 74 deletions(-) diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index a6e685e..b82c6a5 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -133,7 +133,7 @@ eth_plugin_result_t eth_plugin_perform_init(uint8_t *contractAddress, #ifdef HAVE_NFT_SUPPORT case ERC1155: case ERC721: -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT case EXTERNAL: eth_plugin_perform_init_default(contractAddress, init); contractAddress = NULL; @@ -277,7 +277,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) { erc1155_plugin_call(method, parameter); break; } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT case OLD_INTERNAL: { // Perform the call for (i = 0;; i++) { diff --git a/src/main.c b/src/main.c index 7799632..a06bac0 100644 --- a/src/main.c +++ b/src/main.c @@ -528,7 +528,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) { flags, tx); break; -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT case INS_SET_EXTERNAL_PLUGIN: handleSetExternalPlugin(G_io_apdu_buffer[OFFSET_P1], diff --git a/src/shared_context.h b/src/shared_context.h index b5c944f..035f7c2 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -204,10 +204,10 @@ extern const internalStorage_t N_storage_real; extern bool called_from_swap; typedef enum { - EXTERNAL, // External plugin, set by setExternalPlugin. - ERC721, // Specific ERC721 internal plugin, set by setPlugin. - ERC1155, // Specific ERC1155 internal plugin, set by setPlugin - OLD_INTERNAL // Old internal plugin, not set by any command. + EXTERNAL, // External plugin, set by setExternalPlugin. + ERC721, // Specific ERC721 internal plugin, set by setPlugin. + ERC1155, // Specific ERC1155 internal plugin, set by setPlugin + OLD_INTERNAL // Old internal plugin, not set by any command. } pluginType_t; extern pluginType_t pluginType; diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index 1495f2c..a4256a3 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -18,8 +18,8 @@ #define MIN_DER_SIG_SIZE 67 #define MAX_DER_SIG_SIZE 72 -#define TEST_NFT_METADATA_KEY 0 -#define PROD_NFT_METADATA_KEY 1 +#define TEST_NFT_METADATA_KEY 0 +#define PROD_NFT_METADATA_KEY 1 #define ALGORITHM_ID_1 1 @@ -29,18 +29,18 @@ static const uint8_t LEDGER_NFT_METADATA_PUBLIC_KEY[] = { #ifdef HAVE_NFT_TESTING_KEY - 0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, - 0xe3, 0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, - 0x30, 0x00, 0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, - 0xa5, 0xaa, 0xb0, 0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 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b3, 0x0d, 0xb9, 0xcc, 0xb4, 0x0f, 0x5a, + 0x02, 0xa1, 0x1a, 0x3a, 0xb9, 0x9d, 0x5f, 0x59, 0x5a, 0x3d, 0x50, 0xa0, 0xe1, 0x30, + 0x23, 0xfd, 0x0d, 0x95, 0x87, 0x92, 0xd7, 0x97, 0x01 #endif }; @@ -176,7 +176,7 @@ void handleProvideNFTInformation(uint8_t p1, switch (algorithmId) { case ALGORITHM_ID_1: curve = CX_CURVE_256K1; - verificationFn = (verificationAlgo*)cx_ecdsa_verify; + verificationFn = (verificationAlgo *) cx_ecdsa_verify; hashId = CX_SHA256; break; default: @@ -227,4 +227,4 @@ void handleProvideNFTInformation(uint8_t p1, THROW(0x9000); } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_features/setPlugin/cmd_setPlugin.c b/src_features/setPlugin/cmd_setPlugin.c index ea39aa2..d2969f7 100644 --- a/src_features/setPlugin/cmd_setPlugin.c +++ b/src_features/setPlugin/cmd_setPlugin.c @@ -46,17 +46,17 @@ typedef enum AlgorithmID { // Only used for signing NFT plugins (ERC721 and ERC1155) static const uint8_t LEDGER_NFT_SELECTOR_PUBLIC_KEY[] = { #ifdef HAVE_NFT_TESTING_KEY - 0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, - 0xe3, 0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, - 0x30, 0x00, 0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, - 0xa5, 0xaa, 0xb0, 0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, - 0xdd, 0xa6, 0xec, 0xe9, 0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4 + 0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, 0xe3, + 0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, 0x30, 0x00, + 0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0, + 0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9, + 0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4 #else - 0x04, 0xd8, 0x62, 0x6e, 0x01, 0x9e, 0x55, 0x3e, 0x19, 0x69, 0x56, 0xf1, 0x17, - 0x4d, 0xcd, 0xb8, 0x9a, 0x1c, 0xda, 0xc4, 0x93, 0x90, 0x08, 0xbc, 0x79, 0x77, - 0x33, 0x6d, 0x78, 0x24, 0xee, 0xe3, 0xa2, 0x62, 0x24, 0x1a, 0x62, 0x73, 0x52, - 0x3b, 0x09, 0xb8, 0xd0, 0xce, 0x0d, 0x39, 0xe8, 0x60, 0xc9, 0x4d, 0x02, 0x53, - 0x58, 0xdb, 0xdc, 0x25, 0x92, 0xc7, 0xc6, 0x48, 0x0d, 0x39, 0xce, 0xbb, 0xa3 + 0x04, 0xd8, 0x62, 0x6e, 0x01, 0x9e, 0x55, 0x3e, 0x19, 0x69, 0x56, 0xf1, 0x17, 0x4d, + 0xcd, 0xb8, 0x9a, 0x1c, 0xda, 0xc4, 0x93, 0x90, 0x08, 0xbc, 0x79, 0x77, 0x33, 0x6d, + 0x78, 0x24, 0xee, 0xe3, 0xa2, 0x62, 0x24, 0x1a, 0x62, 0x73, 0x52, 0x3b, 0x09, 0xb8, + 0xd0, 0xce, 0x0d, 0x39, 0xe8, 0x60, 0xc9, 0x4d, 0x02, 0x53, 0x58, 0xdb, 0xdc, 0x25, + 0x92, 0xc7, 0xc6, 0x48, 0x0d, 0x39, 0xce, 0xbb, 0xa3 #endif }; @@ -209,7 +209,7 @@ void handleSetPlugin(uint8_t p1, switch (algorithmId) { case ECC_SECG_P256K1__ECDSA_SHA_256: curve = CX_CURVE_256K1; - verificationFn = (verificationAlgo*)cx_ecdsa_verify; + verificationFn = (verificationAlgo *) cx_ecdsa_verify; hashId = CX_SHA256; break; default: diff --git a/src_plugins/erc1155/erc1155_plugin.c b/src_plugins/erc1155/erc1155_plugin.c index 7eebd8c..dbc1b8e 100644 --- a/src_plugins/erc1155/erc1155_plugin.c +++ b/src_plugins/erc1155/erc1155_plugin.c @@ -139,4 +139,4 @@ void erc1155_plugin_call(int message, void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc1155/erc1155_plugin.h b/src_plugins/erc1155/erc1155_plugin.h index 22462a8..0702fdf 100644 --- a/src_plugins/erc1155/erc1155_plugin.h +++ b/src_plugins/erc1155/erc1155_plugin.h @@ -34,9 +34,9 @@ typedef enum { } erc1155_selector_field; typedef struct erc1155_context_t { - uint8_t address[ADDRESS_LENGTH]; - uint8_t tokenId[INT256_LENGTH]; - uint256_t value; + uint8_t address[ADDRESS_LENGTH]; + uint8_t tokenId[INT256_LENGTH]; + uint256_t value; uint16_t ids_array_len; uint32_t ids_offset; @@ -52,4 +52,4 @@ typedef struct erc1155_context_t { void handle_provide_parameter_1155(void *parameters); void handle_query_contract_ui_1155(void *parameters); -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc1155/erc1155_provide_parameters.c b/src_plugins/erc1155/erc1155_provide_parameters.c index 59da428..800aafb 100644 --- a/src_plugins/erc1155/erc1155_provide_parameters.c +++ b/src_plugins/erc1155/erc1155_provide_parameters.c @@ -30,7 +30,7 @@ static void handle_safe_transfer(ethPluginProvideParameter_t *msg, erc1155_conte } static void handle_batch_transfer(ethPluginProvideParameter_t *msg, erc1155_context_t *context) { - uint256_t new_value; + uint256_t new_value; switch (context->next_param) { case FROM: @@ -41,23 +41,19 @@ static void handle_batch_transfer(ethPluginProvideParameter_t *msg, erc1155_cont context->next_param = TOKEN_IDS_OFFSET; break; case TOKEN_IDS_OFFSET: - context->ids_offset = \ - U4BE(msg->parameter, - PARAMETER_LENGTH - sizeof(context->ids_offset)) + 4; + context->ids_offset = + U4BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->ids_offset)) + 4; context->next_param = VALUE_OFFSET; break; case VALUE_OFFSET: - context->values_offset = \ - U4BE(msg->parameter, - PARAMETER_LENGTH - sizeof(context->values_offset)) + 4; + context->values_offset = + U4BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->values_offset)) + 4; context->next_param = TOKEN_IDS_LENGTH; break; case TOKEN_IDS_LENGTH: - if ((msg->parameterOffset + PARAMETER_LENGTH) > context->ids_offset) - { - context->ids_array_len = \ - U2BE(msg->parameter, - PARAMETER_LENGTH - sizeof(context->ids_array_len)); + if ((msg->parameterOffset + PARAMETER_LENGTH) > context->ids_offset) { + context->ids_array_len = + U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->ids_array_len)); context->next_param = TOKEN_ID; // set to zero for next step context->array_index = 0; @@ -65,20 +61,16 @@ static void handle_batch_transfer(ethPluginProvideParameter_t *msg, erc1155_cont break; case TOKEN_ID: // don't copy anything since we won't display it - if (--context->ids_array_len == 0) - { + if (--context->ids_array_len == 0) { context->next_param = VALUE_LENGTH; } context->array_index++; break; case VALUE_LENGTH: - if ((msg->parameterOffset + PARAMETER_LENGTH) > context->values_offset) - { - context->values_array_len = \ - U2BE(msg->parameter, - PARAMETER_LENGTH - sizeof(context->values_array_len)); - if (context->values_array_len != context->array_index) - { + if ((msg->parameterOffset + PARAMETER_LENGTH) > context->values_offset) { + context->values_array_len = + U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->values_array_len)); + if (context->values_array_len != context->array_index) { PRINTF("Token ids and values array sizes mismatch!"); } context->next_param = VALUE; @@ -92,8 +84,7 @@ static void handle_batch_transfer(ethPluginProvideParameter_t *msg, erc1155_cont copy_parameter(context->tokenId, msg->parameter, sizeof(context->value)); convertUint256BE(context->tokenId, sizeof(context->tokenId), &new_value); add256(&context->value, &new_value, &context->value); - if (--context->values_array_len == 0) - { + if (--context->values_array_len == 0) { context->next_param = NONE; } context->array_index++; @@ -132,10 +123,10 @@ void handle_provide_parameter_1155(void *parameters) { msg->result = ETH_PLUGIN_RESULT_SUCCESSFUL; - //if (context->targetOffset > SELECTOR_SIZE && - // context->targetOffset != msg->parameterOffset - SELECTOR_SIZE) { - // return; - //} + // if (context->targetOffset > SELECTOR_SIZE && + // context->targetOffset != msg->parameterOffset - SELECTOR_SIZE) { + // return; + // } switch (context->selectorIndex) { case SAFE_TRANSFER: handle_safe_transfer(msg, context); @@ -153,4 +144,4 @@ void handle_provide_parameter_1155(void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc1155/erc1155_ui.c b/src_plugins/erc1155/erc1155_ui.c index 5237a16..5b4e941 100644 --- a/src_plugins/erc1155/erc1155_ui.c +++ b/src_plugins/erc1155/erc1155_ui.c @@ -59,7 +59,7 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress((uint8_t *)msg->item1->nft.contractAddress, + getEthDisplayableAddress((uint8_t *) msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -84,7 +84,7 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex } static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) { - char quantity_str[48]; + char quantity_str[48]; switch (msg->screenIndex) { case 0: @@ -105,7 +105,7 @@ static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t * break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress((uint8_t *)msg->item1->nft.contractAddress, + getEthDisplayableAddress((uint8_t *) msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -149,4 +149,4 @@ void handle_query_contract_ui_1155(void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc721/erc721_plugin.c b/src_plugins/erc721/erc721_plugin.c index 4bdd232..badddb3 100644 --- a/src_plugins/erc721/erc721_plugin.c +++ b/src_plugins/erc721/erc721_plugin.c @@ -147,4 +147,4 @@ void erc721_plugin_call(int message, void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc721/erc721_plugin.h b/src_plugins/erc721/erc721_plugin.h index 2ab80df..1846609 100644 --- a/src_plugins/erc721/erc721_plugin.h +++ b/src_plugins/erc721/erc721_plugin.h @@ -43,4 +43,4 @@ typedef struct erc721_context_t { void handle_provide_parameter_721(void *parameters); void handle_query_contract_ui_721(void *parameters); -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc721/erc721_provide_parameters.c b/src_plugins/erc721/erc721_provide_parameters.c index a315af0..ac5b870 100644 --- a/src_plugins/erc721/erc721_provide_parameters.c +++ b/src_plugins/erc721/erc721_provide_parameters.c @@ -94,4 +94,4 @@ void handle_provide_parameter_721(void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT diff --git a/src_plugins/erc721/erc721_ui.c b/src_plugins/erc721/erc721_ui.c index bb8264c..e312932 100644 --- a/src_plugins/erc721/erc721_ui.c +++ b/src_plugins/erc721/erc721_ui.c @@ -115,7 +115,7 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress((uint8_t *)msg->item1->nft.contractAddress, + getEthDisplayableAddress((uint8_t *) msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -167,4 +167,4 @@ void handle_query_contract_ui_721(void *parameters) { } } -#endif // HAVE_NFT_SUPPORT +#endif // HAVE_NFT_SUPPORT