EIP712 code now uses the global apdu response code; error handling improvements

This commit is contained in:
Alexandre Paillier
2022-07-19 11:04:16 +02:00
parent 12b97d91db
commit 0100eed1fd
9 changed files with 207 additions and 127 deletions

View File

@@ -6,6 +6,7 @@
#include "mem.h"
#include "eip712.h"
#include "shared_context.h"
#include "apdu_constants.h" // APDU response codes
typedef enum
{
@@ -32,6 +33,7 @@ static void *field_encode(const uint8_t *const value,
if (length > EIP_712_ENCODED_FIELD_LENGTH) // sanity check
{
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return NULL;
}
if ((padded_value = mem_alloc(EIP_712_ENCODED_FIELD_LENGTH)) != NULL)
@@ -51,6 +53,10 @@ static void *field_encode(const uint8_t *const value,
}
memcpy(&padded_value[start_idx], value, length);
}
else
{
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY;
}
return padded_value;
}
@@ -115,6 +121,7 @@ void *encode_boolean(const bool *const value, uint8_t length)
{
if (length != 1) // sanity check
{
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return NULL;
}
return encode_uint((uint8_t*)value, length);
@@ -131,6 +138,7 @@ void *encode_address(const uint8_t *const value, uint8_t length)
{
if (length != ADDRESS_LENGTH) // sanity check
{
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return NULL;
}
return encode_uint(value, length);