Make the dependencies mandatory in the typehash function

This commit is contained in:
Alexandre Paillier
2022-05-02 17:27:24 +02:00
parent 6c14bfa476
commit ad030cdb6a
3 changed files with 15 additions and 24 deletions

View File

@@ -248,7 +248,7 @@ static bool path_update(void)
}
cx_keccak_init((cx_hash_t*)hash_ctx, 256); // initialize it
// get the struct typehash
if ((thash_ptr = type_hash(structs_array, typename, typename_len, true)) == NULL)
if ((thash_ptr = type_hash(structs_array, typename, typename_len)) == NULL)
{
return false;
}
@@ -297,7 +297,7 @@ bool path_set_root(const char *const struct_name, uint8_t name_length)
return false;
}
cx_keccak_init((cx_hash_t*)hash_ctx, 256); // init hash
if ((thash_ptr = type_hash(structs_array, struct_name, name_length, true)) == NULL)
if ((thash_ptr = type_hash(structs_array, struct_name, name_length)) == NULL)
{
return false;
}

View File

@@ -267,42 +267,34 @@ static bool get_struct_dependencies(const void *const structs_array,
*/
const uint8_t *type_hash(const void *const structs_array,
const char *const struct_name,
const uint8_t struct_name_length,
bool with_deps)
const uint8_t struct_name_length)
{
const void *const struct_ptr = get_structn(structs_array,
struct_name,
struct_name_length);
uint8_t deps_count;
uint8_t deps_count = 0;
void **deps;
uint8_t *hash_ptr;
cx_keccak_init((cx_hash_t*)&global_sha3, 256); // init hash
if (with_deps)
// get list of structs (own + dependencies), properly ordered
deps = mem_alloc(0); // get where the first elem will be
if (get_struct_dependencies(structs_array, &deps_count, deps, struct_ptr) == false)
{
deps_count = 0;
// get list of structs (own + dependencies), properly ordered
deps = mem_alloc(0); // get where the first elem will be
if (get_struct_dependencies(structs_array, &deps_count, deps, struct_ptr) == false)
{
return NULL;
}
sort_dependencies(deps_count, deps);
return NULL;
}
sort_dependencies(deps_count, deps);
if (encode_and_hash_type(struct_ptr) == false)
{
return NULL;
}
if (with_deps)
// loop over each struct and generate string
for (int idx = 0; idx < deps_count; ++idx)
{
// loop over each struct and generate string
for (int idx = 0; idx < deps_count; ++idx)
{
encode_and_hash_type(*deps);
deps += 1;
}
mem_dealloc(sizeof(void*) * deps_count);
encode_and_hash_type(*deps);
deps += 1;
}
mem_dealloc(sizeof(void*) * deps_count);
#ifdef DEBUG
PRINTF("\n");
#endif

View File

@@ -5,7 +5,6 @@
const uint8_t *type_hash(const void *const structs_array,
const char *const struct_name,
const uint8_t struct_name_length,
bool with_deps);
const uint8_t struct_name_length);
#endif // TYPE_HASH_H_