67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include "keystorage_private.h"
|
|
#include "log.h"
|
|
|
|
static bool
|
|
_test_read_write_pass()
|
|
{
|
|
uint8_t i;
|
|
uint8_t data[KEY_SLOT_MAX_SIZE];
|
|
uint8_t read_buf[KEY_SLOT_MAX_SIZE];
|
|
size_t read_sz;
|
|
|
|
memset(data, 0xAA, sizeof(data));
|
|
|
|
for (i = KEY_SLOT_0; i < KEY_SLOT_MAX; ++i) {
|
|
if (IOTELIC_OK != keystorage_save(i, data, sizeof(data))) {
|
|
LOG("Read/Write. Write error to slot %i", i);
|
|
return false;
|
|
}
|
|
if (IOTELIC_OK != keystorage_load(i, read_buf, sizeof(data), &read_sz)
|
|
|| read_sz != sizeof(data)
|
|
|| 0 != memcmp(data, read_buf, sizeof(data))) {
|
|
LOG("Read/Write. Read error from slot %i", i);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
_test_write_fail()
|
|
{
|
|
uint8_t data[KEY_SLOT_MAX_SIZE + 1];
|
|
|
|
if (IOTELIC_OK == keystorage_save(KEY_SLOT_0, data, sizeof(data))) {
|
|
LOG("Atempt to write data > KEY_SLOT_MAX_SIZE passed. So, it's bug !");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
_test_read_fail()
|
|
{
|
|
uint8_t buf[KEY_SLOT_MAX_SIZE ];
|
|
size_t read_sz;
|
|
|
|
if (IOTELIC_OK == keystorage_load(KEY_SLOT_MAX, buf, sizeof(buf), &read_sz)) {
|
|
LOG("Atempt to read from wrong slot passed. So, it's bug !");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
test_keystorage(void)
|
|
{
|
|
if (!_test_read_write_pass()) return false;
|
|
if (!_test_write_fail()) return false;
|
|
if (!_test_read_fail()) return false;
|
|
|
|
return true;
|
|
}
|