Skip to content

Commit

Permalink
Added mock_sest_remove to mock_secret_store
Browse files Browse the repository at this point in the history
Added missing function that will be needed for the seed unit tests
  • Loading branch information
italo-sampaio committed Oct 14, 2024
1 parent ecb7756 commit cca426d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions firmware/src/hal/sgx/test/mock/mock_secret_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ uint8_t mock_sest_read(char *key, uint8_t *dest, size_t dest_length) {
return 0;
}

bool mock_sest_remove(char *key) {
for (size_t i = 0; i < g_mock_secret_store.num_registers; i++) {
if (strcmp(g_mock_secret_store.registers[i].key, key) == 0) {
free(g_mock_secret_store.registers[i].key);
free(g_mock_secret_store.registers[i].secret);
for (size_t j = i; j < g_mock_secret_store.num_registers - 1; j++) {
g_mock_secret_store.registers[j] =
g_mock_secret_store.registers[j + 1];
}
g_mock_secret_store.num_registers--;
return true;
}
}
return false;
}

void mock_sest_init() {
memset(&g_mock_secret_store, 0, sizeof(g_mock_secret_store));
}
Expand Down
9 changes: 9 additions & 0 deletions firmware/src/hal/sgx/test/mock/mock_secret_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ bool mock_sest_write(char *key, uint8_t *secret, size_t secret_length);
*/
uint8_t mock_sest_read(char *key, uint8_t *dest, size_t dest_length);

/**
* @brief Mock implementation of sest_remove
*
* @param key the key for the secret
*
* @returns whether the secret was successfully removed
*/
bool mock_sest_remove(char *key);

/**
* @brief Resets the mock secret store to its initial state
*/
Expand Down

0 comments on commit cca426d

Please sign in to comment.