<commit_before>#include "asf.h"
#include "cdc.h"
#include "keys.h"
//#include "eeprom.h"
#include <string.h>

int main(void)
{
	cpu_irq_enable();

	irq_initialize_vectors();

	sysclk_init();

	cdc_start();

	while (!cdc_opened());

	cdc_write_line("Beginning key store demo.");

	const key_table_t * table = keys_get_table();

	cdc_log_hex("Loading table: ", keys_load_table());
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);


	cdc_log_hex("Resetting table: ", keys_reset_table());
	keys_load_table();
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);

	uint8_t slot;
	uint8_t key[PAGE_SIZE];
	cdc_log_hex_string("Key to store:\n", (void *)key, PAGE_SIZE);
	cdc_log_hex("Looking for key for id=1. ", keys_has_key(1, &slot));

	cdc_log_hex("Storing key for id=1. ", keys_store_key(1, key));
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);

	cdc_log_hex("Looking for key for id=1. ", keys_has_key(1, &slot));
	cdc_log_hex("Key slot: ", slot);
	memset(key, 0xAA, PAGE_SIZE);
	cdc_log_hex_string("Blanked key:\n", (void *)key, PAGE_SIZE);
	keys_read_key(slot, key);
	cdc_log_hex_string("Read key:\n", (void *)key, PAGE_SIZE);

	cdc_write_line("Resetting key.");
	memset(key, 0xAA, PAGE_SIZE);
	cdc_log_hex("Storing key for id=1. ", keys_store_key(1, key));
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);
	memset(key, 0, PAGE_SIZE);
	keys_read_key(slot, key);
	cdc_log_hex_string("Read key:\n", (void *)key, PAGE_SIZE);

	cdc_newline(); cdc_newline();

	cdc_log_hex_string("Key to store:\n", (void *)key, PAGE_SIZE);
	cdc_log_hex("Looking for key for id=2. ", keys_has_key(2, &slot));

	cdc_log_hex("Storing key for id=2. ", keys_store_key(2, key));
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);

	cdc_log_hex("Looking for key for id=2. ", keys_has_key(2, &slot));
	cdc_log_hex("Key slot: ", slot);
	memset(key, 0xAA, PAGE_SIZE);
	cdc_log_hex_string("Blanked key:\n", (void *)key, PAGE_SIZE);
	keys_read_key(slot, key);
	cdc_log_hex_string("Read key:\n", (void *)key, PAGE_SIZE);

	cdc_write_line("Resetting key.");
	memset(key, 0xAA, PAGE_SIZE);
	cdc_log_hex("Storing key for id=2. ", keys_store_key(2, key));
	cdc_log_hex_string("Table:\n", (void *)table, PAGE_SIZE);
	memset(key, 0, PAGE_SIZE);
	keys_read_key(slot, key);
	cdc_log_hex_string("Read key:\n", (void *)key, PAGE_SIZE);

	while (1) {

	}

}<commit_msg>Added thorough stress test to keys demo.<commit_after>#include "asf.h"
#include "cdc.h"
#include "keys.h"
//#include "eeprom.h"
#include <string.h>

int main(void)
{
	cpu_irq_enable();

	irq_initialize_vectors();

	sysclk_init();

	cdc_start();

	while (!cdc_opened());

	cdc_write_line("Beginning key store demo.");

	const key_table_t * table = keys_get_table();

	cdc_log_hex("Loading table: ", keys_load_table());
	cdc_log_hex_string("Table:\n", (void*)table, PAGE_SIZE);


	cdc_log_hex("Resetting table: ", keys_reset_table());
	keys_load_table();
	cdc_log_hex_string("Table:\n", (void*)table, PAGE_SIZE);

	cdc_newline(); cdc_newline();

	uint8_t slot;
	bool has_key;
	uint8_t key[PAGE_SIZE];
	for (uint8_t user = 1; user <= MAX_KEY_SLOTS+1; ++user) {
		slot = 0;
		has_key = false;
		memset(key, 0xA, PAGE_SIZE);
		cdc_log_int("Testing user=", user);
		has_key = keys_has_key(user, &slot);
		cdc_log_string("Has key should be false: ", has_key ? "true" : "false");
		cdc_log_string("Storing key: ", keys_store_key(user, key) == STATUS_OK ? "success" : "failure");
		has_key = keys_has_key(user, &slot);
		cdc_log_string("Has key should be true: ", has_key ? "true" : "false");
		if (has_key) {
			memset(key, 0x0, PAGE_SIZE);
			keys_read_key(slot, key);
			cdc_log_hex_string("Read key:\n", key, PAGE_SIZE);
			cdc_write_line("Storing new key in old slot.");
			memset(key, 0xE, PAGE_SIZE);
			cdc_log_string("Storing key: ", keys_store_key(user, key) == STATUS_OK ? "success" : "failure");
			has_key = keys_has_key(user, &slot);
			cdc_log_string("Has key should be true: ", has_key ? "true" : "false");
			if (has_key) {
				keys_read_key(slot, key);
				cdc_log_hex_string("Read key:\n", key, PAGE_SIZE);
			}
		}
		cdc_newline();
	}

	cdc_newline();

	keys_load_table();
	cdc_log_hex_string("Table:\n", (void*)table, PAGE_SIZE);

	while (1) {

	}

}
{'fraction_non_alphanumeric': 0.17391304347826086, 'fraction_numerical': 0.008506616257088847, 'mean_word_length': 5.7728, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1587162', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1744, 'n_words': 348}