Now initializes a path in memory
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "eip712.h"
|
||||
#include "mem.h"
|
||||
#include "sol_typenames.h"
|
||||
#include "path.h"
|
||||
|
||||
uint8_t *typenames_array;
|
||||
uint8_t *structs_array;
|
||||
@@ -21,9 +22,16 @@ bool init_eip712_context(void)
|
||||
if (init_sol_typenames() == false)
|
||||
return false;
|
||||
|
||||
if (init_path() == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// set types pointer
|
||||
if ((structs_array = mem_alloc(sizeof(uint8_t))) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// create len(types)
|
||||
*structs_array = 0;
|
||||
|
||||
@@ -60,6 +60,10 @@ void *encode_integer(const uint8_t *const value, uint16_t length)
|
||||
{
|
||||
uint8_t *padded_value;
|
||||
|
||||
if (length > 32) // sanity check
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// 0-pad the value to 32 bytes
|
||||
if ((padded_value = mem_alloc(EIP_712_ENCODED_FIELD_LENGTH)) != NULL)
|
||||
{
|
||||
@@ -93,7 +97,7 @@ void *encode_string(const char *const value, uint16_t length)
|
||||
*/
|
||||
void *encode_bool(const bool *const value, uint16_t length)
|
||||
{
|
||||
if (length != 1)
|
||||
if (length != 1) // sanity check
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -109,7 +113,7 @@ void *encode_bool(const bool *const value, uint16_t length)
|
||||
*/
|
||||
void *encode_address(const uint8_t *const value, uint16_t length)
|
||||
{
|
||||
if (length != ADDRESS_LENGTH)
|
||||
if (length != ADDRESS_LENGTH) // sanity check
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -258,6 +258,7 @@ bool set_struct_name(const uint8_t *const data)
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Split this function
|
||||
bool set_struct_field(const uint8_t *const data)
|
||||
{
|
||||
uint8_t data_idx = OFFSET_DATA;
|
||||
|
||||
@@ -9,6 +9,8 @@ const uint8_t *field_hash(const void *const structs_array,
|
||||
(void)structs_array;
|
||||
(void)data;
|
||||
(void)data_length;
|
||||
// get field by path
|
||||
encode_integer(data, data_length);
|
||||
// path += 1
|
||||
return NULL;
|
||||
}
|
||||
|
||||
22
src_features/signMessageEIP712/path.c
Normal file
22
src_features/signMessageEIP712/path.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "path.h"
|
||||
#include "mem.h"
|
||||
#include "context.h"
|
||||
|
||||
uint8_t *path_indexes;
|
||||
|
||||
/**
|
||||
* Allocates the the path indexes in memory and sets them all to 0 with a count of 1.
|
||||
*/
|
||||
bool init_path(void)
|
||||
{
|
||||
// + 1 for the used index count
|
||||
if ((path_indexes = mem_alloc(sizeof(uint8_t) * (MAX_PATH_DEPTH + 1))) != NULL)
|
||||
{
|
||||
// set all to 0
|
||||
explicit_bzero(path_indexes + 1, sizeof(uint8_t) * MAX_PATH_DEPTH);
|
||||
*path_indexes = 1; // init count at 1, so the default path will be 0
|
||||
}
|
||||
return path_indexes != NULL;
|
||||
}
|
||||
12
src_features/signMessageEIP712/path.h
Normal file
12
src_features/signMessageEIP712/path.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef PATH_H_
|
||||
#define PATH_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_PATH_DEPTH 16
|
||||
|
||||
extern uint8_t *path_indexes;
|
||||
|
||||
bool init_path(void);
|
||||
|
||||
#endif // PATH_H_
|
||||
Reference in New Issue
Block a user