From d1d1aa73e6b370603e345ad1bf2b69cca7aca336 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 6 Jul 2022 10:03:42 +0200 Subject: [PATCH] Made all EIP712 code use the same function for response APDUs --- src_features/signMessageEIP712/commands_712.c | 6 +++--- src_features/signMessageEIP712/commands_712.h | 1 + src_features/signMessageEIP712/field_hash.c | 5 ++--- src_features/signMessageEIP712/ui_logic.c | 6 ++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src_features/signMessageEIP712/commands_712.c b/src_features/signMessageEIP712/commands_712.c index 22feb20..5681767 100644 --- a/src_features/signMessageEIP712/commands_712.c +++ b/src_features/signMessageEIP712/commands_712.c @@ -14,9 +14,9 @@ #include "filtering.h" #include "common_712.h" -static void handle_eip712_return_code(bool ret) +void handle_eip712_return_code(bool success) { - if (ret) + if (success) { apdu_response_code = APDU_RESPONSE_OK; } @@ -25,7 +25,7 @@ static void handle_eip712_return_code(bool ret) // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); - if (!ret) + if (!success) { eip712_context_deinit(); } diff --git a/src_features/signMessageEIP712/commands_712.h b/src_features/signMessageEIP712/commands_712.h index 2814e29..33e7509 100644 --- a/src_features/signMessageEIP712/commands_712.h +++ b/src_features/signMessageEIP712/commands_712.h @@ -26,6 +26,7 @@ bool handle_eip712_struct_def(const uint8_t *const apdu_buf); bool handle_eip712_struct_impl(const uint8_t *const apdu_buf); bool handle_eip712_sign(const uint8_t *const apdu_buf); bool handle_eip712_filtering(const uint8_t *const apdu_buf); +void handle_eip712_return_code(bool success); #endif // HAVE_EIP712_FULL_SUPPORT diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index 6a838ed..22b2f9d 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -13,6 +13,7 @@ #include "utils.h" // u64_from_BE #include "apdu_constants.h" // APDU response codes #include "typed_data.h" +#include "commands_712.h" static s_field_hashing *fh = NULL; @@ -206,9 +207,7 @@ bool field_hash(const uint8_t *data, apdu_response_code = APDU_RESPONSE_INVALID_DATA; return false; } - G_io_apdu_buffer[0] = 0x90; - G_io_apdu_buffer[1] = 0x00; - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); + handle_eip712_return_code(true); } return true; diff --git a/src_features/signMessageEIP712/ui_logic.c b/src_features/signMessageEIP712/ui_logic.c index e6f68aa..9e0ddcb 100644 --- a/src_features/signMessageEIP712/ui_logic.c +++ b/src_features/signMessageEIP712/ui_logic.c @@ -17,6 +17,7 @@ #include "path.h" // path_get_root_type #include "apdu_constants.h" // APDU response codes #include "typed_data.h" +#include "commands_712.h" static t_ui_context *ui_ctx = NULL; @@ -140,10 +141,7 @@ void ui_712_next_field(void) { if (!ui_ctx->end_reached) { - // reply to previous APDU - G_io_apdu_buffer[0] = 0x90; - G_io_apdu_buffer[1] = 0x00; - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); + handle_eip712_return_code(true); } else {