Better EIP712 field implementation error handling, including hidden ones

This commit is contained in:
Alexandre Paillier
2022-07-11 09:38:20 +02:00
parent 58d1b40c79
commit cfb45a795b

View File

@@ -130,6 +130,7 @@ void ui_712_next_field(void)
{ {
if (ui_ctx == NULL) if (ui_ctx == NULL)
{ {
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return; return;
} }
if (ui_ctx->structs_to_review > 0) if (ui_ctx->structs_to_review > 0)
@@ -200,6 +201,7 @@ static bool ui_712_format_bool(const uint8_t *const data, uint8_t length)
{ {
if (length != 1) if (length != 1)
{ {
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return false; return false;
} }
if (*data) if (*data)
@@ -282,6 +284,7 @@ static bool ui_712_format_int(const uint8_t *const data,
break; break;
default: default:
PRINTF("Unhandled field typesize\n"); PRINTF("Unhandled field typesize\n");
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return false; return false;
} }
return true; return true;
@@ -309,27 +312,23 @@ bool ui_712_new_field(const void *const field_ptr, const uint8_t *const data,
if (ui_ctx == NULL) if (ui_ctx == NULL)
{ {
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return false; return false;
} }
// Check if this field is supposed to be displayed // Key
// TODO: maybe put it after the big switch case so error handling on value happens if ((key = get_struct_field_keyname(field_ptr, &key_len)) == NULL)
if (!ui_712_field_shown())
{ {
return true; apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return false;
} }
// Key if (!(ui_ctx->field_flags & UI_712_FIELD_NAME_PROVIDED))
if ((key = get_struct_field_keyname(field_ptr, &key_len)) != NULL)
{ {
if (!(ui_ctx->field_flags & UI_712_FIELD_NAME_PROVIDED)) ui_712_set_title(key, key_len);
{
ui_712_set_title(key, key_len);
}
} }
// Value // Value
ui_712_set_value("", 0);
switch (struct_field_type(field_ptr)) switch (struct_field_type(field_ptr))
{ {
case TYPE_SOL_STRING: case TYPE_SOL_STRING:
@@ -365,7 +364,12 @@ bool ui_712_new_field(const void *const field_ptr, const uint8_t *const data,
PRINTF("Unhandled type\n"); PRINTF("Unhandled type\n");
return false; return false;
} }
ui_712_redraw_generic_step();
// Check if this field is supposed to be displayed
if (ui_712_field_shown())
{
ui_712_redraw_generic_step();
}
return true; return true;
} }
@@ -377,6 +381,7 @@ void ui_712_end_sign(void)
{ {
if (ui_ctx == NULL) if (ui_ctx == NULL)
{ {
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return; return;
} }
ui_ctx->end_reached = true; ui_ctx->end_reached = true;