1
0
mirror of https://github.com/CovidBraceletPrj/CovidBracelet.git synced 2024-10-15 02:19:20 +02:00

Add doc comments

This commit is contained in:
Hendrik Sauer 2021-12-08 14:02:42 +01:00 committed by Patrick Rathje
parent 7a0fa5b30c
commit a1e7a83c84
2 changed files with 35 additions and 20 deletions

View File

@ -10,25 +10,14 @@
#include "extract_keys.h"
#define KEY_SIZE 16
#ifndef PROTOBUF_BLOCK_SIZE
#define PROTOBUF_BLOCK_SIZE 0
#endif
// #define EXPORT_BUFFER_SIZE 100000
void process_key(TemporaryExposureKey* key) {
// if (key) {
// if (key->has_key_data) {
// int len = (key->key_data.len) + 1;
// char data[len + 1];
// memcpy(data, key->key_data.data, len - 1);
// data[len] = 0;
// }
// }
// TODO: Implement
}
size_t generate_keys(uint8_t** buffer_pointer, int num_keys) {
TemporaryExposureKeyExport export = TEMPORARY_EXPOSURE_KEY_EXPORT__INIT;
// temporary_exposure_key_export__init(&export);
TemporaryExposureKey** key_ptrs = (TemporaryExposureKey**)k_malloc(sizeof(TemporaryExposureKey*) * num_keys);
if (key_ptrs == NULL) {
printk("Could not allocate memory for pointers\n");
@ -36,13 +25,13 @@ size_t generate_keys(uint8_t** buffer_pointer, int num_keys) {
}
export.batch_num = 1;
export.batch_size = 1;
// TemporaryExposureKey* key_ptrs[num_keys];
uint8_t key_data[KEY_SIZE];
for (int i = 0; i < KEY_SIZE; i++) {
key_data[i] = 0xFF;
}
TemporaryExposureKey key = TEMPORARY_EXPOSURE_KEY__INIT;
// temporary_exposure_key__init(&key);
key.key_data.data = key_data;
key.key_data.len = KEY_SIZE;
key.has_key_data = true;
@ -77,7 +66,6 @@ int unpack_keys(uint8_t* buf, size_t buf_size) {
return -2;
}
printk("Num keys %d\n", export->n_keys);
// Iterate over new keys
for (int i = 0; i < export->n_keys; i++) {
TemporaryExposureKey* key = export->keys[i];

View File

@ -3,12 +3,39 @@
#include "export.pb-c.h"
void process_key(TemporaryExposureKey*);
/**
* @brief Process a key. This function could trigger the comparision between the key and those registered by the ENS.
*
* @param key A pointer to the Exposure key data structure
*/
void process_key(TemporaryExposureKey* key);
size_t generate_keys(uint8_t**, int);
/**
* @brief Generates a protocol buffer containing dummy keys.
*
* @param buffer_pointer A pointer to the pointer which will be used to reference the buffer externally. This will be
* set to the memory area allocated to store the protocol buffer.
* @param num_keys The number of keys that will be generated
* @return size_t The size of the protocol buffer
*/
size_t generate_keys(uint8_t** buffer_pointer, int num_keys);
int unpack_keys(uint8_t*, size_t) ;
/**
* @brief Unpacks the protocol buffer and iterates the `process_key` function over all keys.
*
* @param buf a pointer to the buffer
* @param buf_size the size of the buffer in bytes
* @return int
*/
int unpack_keys(uint8_t* buf, size_t buf_size);
int test_unpacking(int);
/**
* @brief Generates an protocol buffer with a specified number of keys and measures the time to execute `unpack_keys`,
* which unpacks the protocol buffer and iterates `process_key` over the keys.
*
* @param num_keys the number of keys that will be created
* @return int
*/
int test_unpacking(int num_keys);
#endif