diff --git a/.github/workflows/lint-workflow.yml b/.github/workflows/lint-workflow.yml index b9ea676..f74416d 100644 --- a/.github/workflows/lint-workflow.yml +++ b/.github/workflows/lint-workflow.yml @@ -19,8 +19,8 @@ jobs: uses: actions/checkout@v2 - name: Lint - uses: DoozyX/clang-format-lint-action@v0.13 + uses: DoozyX/clang-format-lint-action@v0.14 with: source: "./" extensions: "h,c" - clangFormatVersion: 12.0.0 + clangFormatVersion: 12.0.1 diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index d0de69c..e5187ca 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -113,7 +113,7 @@ static bool eth_plugin_perform_init_old_internal(uint8_t *contractAddress, j++) { if (memcmp(init->selector, (const void *) PIC(selectors[j]), SELECTOR_SIZE) == 0) { if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) || - ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck)) ()) { + ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) { strlcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias, PLUGIN_ID_LENGTH); diff --git a/src_bagl/ui_flow_signMessage.c b/src_bagl/ui_flow_signMessage.c index b620b56..97546a3 100644 --- a/src_bagl/ui_flow_signMessage.c +++ b/src_bagl/ui_flow_signMessage.c @@ -5,33 +5,24 @@ static uint8_t ui_pos; - -static void dummy_pre_cb(void) -{ - if (ui_pos == UI_191_POS_REVIEW) - { +static void dummy_pre_cb(void) { + if (ui_pos == UI_191_POS_REVIEW) { question_switcher(); - } - else - { + } else { ux_flow_prev(); ui_pos = UI_191_POS_REVIEW; } } -static void dummy_post_cb(void) -{ - if (ui_pos == UI_191_POS_QUESTION) - { +static void dummy_post_cb(void) { + if (ui_pos == UI_191_POS_QUESTION) { continue_displaying_message(); - } - else // UI_191_END + } else // UI_191_END { ui_191_switch_to_message_end(); } } - // clang-format off UX_STEP_NOCB( ux_191_step_review, @@ -99,34 +90,28 @@ UX_FLOW(ux_191_flow, &ux_191_step_sign, &ux_191_step_cancel); - -void ui_191_start(void) -{ +void ui_191_start(void) { ux_flow_init(0, ux_191_flow, NULL); ui_pos = UI_191_POS_REVIEW; } -void ui_191_switch_to_message(void) -{ +void ui_191_switch_to_message(void) { ux_flow_init(0, ux_191_flow, &ux_191_step_message); ui_pos = UI_191_POS_REVIEW; } -void ui_191_switch_to_message_end(void) -{ +void ui_191_switch_to_message_end(void) { // Force it to a value that will make it automatically do a prev() ui_pos = UI_191_POS_QUESTION; ux_flow_init(0, ux_191_flow, &ux_191_step_dummy_pre); } -void ui_191_switch_to_sign(void) -{ +void ui_191_switch_to_sign(void) { ux_flow_init(0, ux_191_flow, &ux_191_step_sign); ui_pos = UI_191_POS_END; } -void ui_191_switch_to_question(void) -{ +void ui_191_switch_to_question(void) { ux_flow_init(0, ux_191_flow, &ux_191_step_theres_more); ui_pos = UI_191_POS_QUESTION; } diff --git a/src_features/signMessage/cmd_signMessage.c b/src_features/signMessage/cmd_signMessage.c index b70d018..77f5ac0 100644 --- a/src_features/signMessage/cmd_signMessage.c +++ b/src_features/signMessage/cmd_signMessage.c @@ -6,8 +6,7 @@ #include "ui_flow_signMessage.h" static uint8_t processed_size; -static struct -{ +static struct { sign_message_state sign_state : 1; bool ui_started : 1; } states; @@ -16,14 +15,12 @@ static const char SIGN_MAGIC[] = "\x19" "Ethereum Signed Message:\n"; - /** * Send a response APDU with the given Status Word * * @param[in] sw status word */ -static void apdu_reply(uint16_t sw) -{ +static void apdu_reply(uint16_t sw) { *(uint16_t *) G_io_apdu_buffer = __builtin_bswap16(sw); io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); } @@ -33,8 +30,7 @@ static void apdu_reply(uint16_t sw) * * @return pointer to data in APDU buffer */ -static const uint8_t *unprocessed_data(void) -{ +static const uint8_t *unprocessed_data(void) { return &G_io_apdu_buffer[OFFSET_CDATA] + processed_size; } @@ -43,8 +39,7 @@ static const uint8_t *unprocessed_data(void) * * @return size of data in bytes */ -static size_t unprocessed_length(void) -{ +static size_t unprocessed_length(void) { return G_io_apdu_buffer[OFFSET_LC] - processed_size; } @@ -53,8 +48,7 @@ static size_t unprocessed_length(void) * * @return size in bytes */ -static size_t ui_buffer_length(void) -{ +static size_t ui_buffer_length(void) { return strlen(UI_191_BUFFER); } @@ -63,8 +57,7 @@ static size_t ui_buffer_length(void) * * @return size in bytes */ -static size_t remaining_ui_buffer_length(void) -{ +static size_t remaining_ui_buffer_length(void) { // -1 for the ending NULL byte return (sizeof(UI_191_BUFFER) - 1) - ui_buffer_length(); } @@ -74,8 +67,7 @@ static size_t remaining_ui_buffer_length(void) * * @return pointer to the free space */ -static char *remaining_ui_buffer(void) -{ +static char *remaining_ui_buffer(void) { return &UI_191_BUFFER[ui_buffer_length()]; } @@ -84,8 +76,7 @@ static char *remaining_ui_buffer(void) * * Simply sets its first byte to a NULL character */ -static void reset_ui_buffer(void) -{ +static void reset_ui_buffer(void) { UI_191_BUFFER[0] = '\0'; } @@ -96,8 +87,7 @@ static void reset_ui_buffer(void) * @param[in] length the payload size * @return pointer to the start of the start of the message; \ref NULL if it failed */ -static const uint8_t *first_apdu_data(const uint8_t *data, uint16_t *length) -{ +static const uint8_t *first_apdu_data(const uint8_t *data, uint16_t *length) { if (appState != APP_STATE_IDLE) { reset_app_context(); } @@ -120,12 +110,7 @@ static const uint8_t *first_apdu_data(const uint8_t *data, uint16_t *length) // Initialize message header + length cx_keccak_init(&global_sha3, 256); - cx_hash((cx_hash_t *) &global_sha3, - 0, - (uint8_t *) SIGN_MAGIC, - sizeof(SIGN_MAGIC) - 1, - NULL, - 0); + cx_hash((cx_hash_t *) &global_sha3, 0, (uint8_t *) SIGN_MAGIC, sizeof(SIGN_MAGIC) - 1, NULL, 0); snprintf(strings.tmp.tmp2, sizeof(strings.tmp.tmp2), "%u", @@ -149,19 +134,16 @@ static const uint8_t *first_apdu_data(const uint8_t *data, uint16_t *length) * @param[in] length the data length * @return whether it was successful or not */ -static bool feed_hash(const uint8_t *const data, uint8_t length) -{ - if (length > tmpCtx.messageSigningContext.remainingLength) - { +static bool feed_hash(const uint8_t *const data, uint8_t length) { + if (length > tmpCtx.messageSigningContext.remainingLength) { PRINTF("Error: Length mismatch ! (%u > %u)!\n", - length, - tmpCtx.messageSigningContext.remainingLength); + length, + tmpCtx.messageSigningContext.remainingLength); apdu_reply(0x6a80); return false; } cx_hash((cx_hash_t *) &global_sha3, 0, data, length, NULL, 0); - if ((tmpCtx.messageSigningContext.remainingLength -= length) == 0) - { + if ((tmpCtx.messageSigningContext.remainingLength -= length) == 0) { // Finalize hash cx_hash((cx_hash_t *) &global_sha3, CX_LAST, @@ -176,56 +158,43 @@ static bool feed_hash(const uint8_t *const data, uint8_t length) /** * Feed the UI with new data */ -static void feed_display(void) -{ +static void feed_display(void) { int c; - while ((unprocessed_length() > 0) && (remaining_ui_buffer_length() > 0)) - { - c = *(char*)unprocessed_data(); - if (isspace(c)) // to replace all white-space characters as spaces + while ((unprocessed_length() > 0) && (remaining_ui_buffer_length() > 0)) { + c = *(char *) unprocessed_data(); + if (isspace(c)) // to replace all white-space characters as spaces { c = ' '; } - if (isprint(c)) - { - sprintf(remaining_ui_buffer(), "%c", (char)c); + if (isprint(c)) { + sprintf(remaining_ui_buffer(), "%c", (char) c); processed_size += 1; - } - else - { - if (remaining_ui_buffer_length() >= 4) // 4 being the fixed length of \x00 + } else { + if (remaining_ui_buffer_length() >= 4) // 4 being the fixed length of \x00 { snprintf(remaining_ui_buffer(), remaining_ui_buffer_length(), "\\x%02x", c); processed_size += 1; - } - else - { + } else { // fill the rest of the UI buffer spaces, to consider the buffer full - while (remaining_ui_buffer_length()) - { + while (remaining_ui_buffer_length()) { sprintf(remaining_ui_buffer(), " "); } } } } - if ((remaining_ui_buffer_length() == 0) - || (tmpCtx.messageSigningContext.remainingLength == 0)) - { - if (!states.ui_started) - { + if ((remaining_ui_buffer_length() == 0) || + (tmpCtx.messageSigningContext.remainingLength == 0)) { + if (!states.ui_started) { ui_191_start(); states.ui_started = true; - } - else - { + } else { ui_191_switch_to_message(); } } - if ((unprocessed_length() == 0) && (tmpCtx.messageSigningContext.remainingLength > 0)) - { + if ((unprocessed_length() == 0) && (tmpCtx.messageSigningContext.remainingLength > 0)) { apdu_reply(0x9000); } } @@ -242,48 +211,37 @@ static void feed_display(void) bool handleSignPersonalMessage(uint8_t p1, uint8_t p2, const uint8_t *const payload, - uint8_t length) -{ + uint8_t length) { const uint8_t *data = payload; - (void)p2; + (void) p2; processed_size = 0; - if (p1 == P1_FIRST) - { - if ((data = first_apdu_data(data, (uint16_t*)&length)) == NULL) - { + if (p1 == P1_FIRST) { + if ((data = first_apdu_data(data, (uint16_t *) &length)) == NULL) { return false; } processed_size = data - payload; - } - else if (p1 != P1_MORE) - { + } else if (p1 != P1_MORE) { PRINTF("Error: Unexpected P1 (%u)!\n", p1); apdu_reply(0x6B00); return false; } - if (!feed_hash(data, length)) - { + if (!feed_hash(data, length)) { return false; } - if (states.sign_state == STATE_191_HASH_DISPLAY) - { + if (states.sign_state == STATE_191_HASH_DISPLAY) { feed_display(); - } - else // hash only + } else // hash only { - if (tmpCtx.messageSigningContext.remainingLength == 0) - { + if (tmpCtx.messageSigningContext.remainingLength == 0) { #ifdef NO_CONSENT io_seproxyhal_touch_signMessage_ok(); #else ui_191_switch_to_sign(); #endif - } - else - { + } else { apdu_reply(0x9000); } } @@ -293,16 +251,11 @@ bool handleSignPersonalMessage(uint8_t p1, /** * Decide whether to show the question to show more of the message or not */ -void question_switcher(void) -{ - if ((states.sign_state == STATE_191_HASH_DISPLAY) - && ((tmpCtx.messageSigningContext.remainingLength > 0) - || (unprocessed_length() > 0))) - { +void question_switcher(void) { + if ((states.sign_state == STATE_191_HASH_DISPLAY) && + ((tmpCtx.messageSigningContext.remainingLength > 0) || (unprocessed_length() > 0))) { ui_191_switch_to_question(); - } - else - { + } else { // Go to Sign / Cancel ui_191_switch_to_sign(); } @@ -311,15 +264,11 @@ void question_switcher(void) /** * The user has decided to skip the rest of the message */ -void skip_rest_of_message(void) -{ +void skip_rest_of_message(void) { states.sign_state = STATE_191_HASH_ONLY; - if (tmpCtx.messageSigningContext.remainingLength > 0) - { + if (tmpCtx.messageSigningContext.remainingLength > 0) { apdu_reply(0x9000); - } - else - { + } else { ui_191_switch_to_sign(); } } @@ -327,11 +276,9 @@ void skip_rest_of_message(void) /** * The user has decided to see the next chunk of the message */ -void continue_displaying_message(void) -{ +void continue_displaying_message(void) { reset_ui_buffer(); - if (unprocessed_length() > 0) - { + if (unprocessed_length() > 0) { feed_display(); } } diff --git a/src_features/signMessage/sign_message.h b/src_features/signMessage/sign_message.h index bb369b5..6d35e49 100644 --- a/src_features/signMessage/sign_message.h +++ b/src_features/signMessage/sign_message.h @@ -1,11 +1,10 @@ #ifndef SIGN_MESSAGE_H_ #define SIGN_MESSAGE_H_ -typedef enum { STATE_191_HASH_DISPLAY = 0, STATE_191_HASH_ONLY } sign_message_state; - - #define UI_191_BUFFER strings.tmp.tmp +typedef enum { STATE_191_HASH_DISPLAY = 0, STATE_191_HASH_ONLY } sign_message_state; + void question_switcher(void); void skip_rest_of_message(void); void continue_displaying_message(void);