Small refactoring on EIP712 set_struct_name function

This commit is contained in:
Alexandre Paillier
2022-07-05 11:53:22 +02:00
parent b782a69137
commit cd77ca5152
3 changed files with 7 additions and 7 deletions

View File

@@ -59,7 +59,7 @@ bool handle_eip712_struct_def(const uint8_t *const apdu_buf)
switch (apdu_buf[OFFSET_P2])
{
case P2_NAME:
ret = set_struct_name(apdu_buf);
ret = set_struct_name(apdu_buf[OFFSET_LC], &apdu_buf[OFFSET_CDATA]);
break;
case P2_FIELD:
ret = set_struct_field(apdu_buf);

View File

@@ -286,12 +286,12 @@ static inline const uint8_t *get_struct(const uint8_t *const ptr,
}
//
bool set_struct_name(const uint8_t *const data)
bool set_struct_name(uint8_t length, const uint8_t *const name)
{
uint8_t *length_ptr;
char *name_ptr;
if ((data == NULL) || (eip712_context == NULL))
if ((name == NULL) || (eip712_context == NULL))
{
return false;
}
@@ -304,15 +304,15 @@ bool set_struct_name(const uint8_t *const data)
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY;
return false;
}
*length_ptr = data[OFFSET_LC];
*length_ptr = length;
// copy name
if ((name_ptr = mem_alloc(sizeof(char) * data[OFFSET_LC])) == NULL)
if ((name_ptr = mem_alloc(sizeof(char) * length)) == NULL)
{
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY;
return false;
}
memmove(name_ptr, &data[OFFSET_CDATA], data[OFFSET_LC]);
memmove(name_ptr, name, length);
// initialize number of fields
if ((eip712_context->current_struct_fields_array = mem_alloc(sizeof(uint8_t))) == NULL)

View File

@@ -61,7 +61,7 @@ const uint8_t *get_structs_array(const uint8_t *ptr, uint8_t *const length);
const uint8_t *get_structn(const uint8_t *const ptr,
const char *const name_ptr,
const uint8_t name_length);
bool set_struct_name(const uint8_t *const data);
bool set_struct_name(uint8_t length, const uint8_t *const name);
bool set_struct_field(const uint8_t *const data);
#endif // HAVE_EIP712_FULL_SUPPORT