From cca426dfef66bb4188b25906907291e973e8bff6 Mon Sep 17 00:00:00 2001 From: Italo Sampaio Date: Mon, 14 Oct 2024 20:04:56 -0300 Subject: [PATCH] Added mock_sest_remove to mock_secret_store Added missing function that will be needed for the seed unit tests --- .../src/hal/sgx/test/mock/mock_secret_store.c | 16 ++++++++++++++++ .../src/hal/sgx/test/mock/mock_secret_store.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/firmware/src/hal/sgx/test/mock/mock_secret_store.c b/firmware/src/hal/sgx/test/mock/mock_secret_store.c index 0239b873..ec335678 100644 --- a/firmware/src/hal/sgx/test/mock/mock_secret_store.c +++ b/firmware/src/hal/sgx/test/mock/mock_secret_store.c @@ -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)); } diff --git a/firmware/src/hal/sgx/test/mock/mock_secret_store.h b/firmware/src/hal/sgx/test/mock/mock_secret_store.h index 39e58510..d84918ec 100644 --- a/firmware/src/hal/sgx/test/mock/mock_secret_store.h +++ b/firmware/src/hal/sgx/test/mock/mock_secret_store.h @@ -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 */