mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Add doc comments
This commit is contained in:
parent
7a0fa5b30c
commit
a1e7a83c84
@ -10,25 +10,14 @@
|
|||||||
#include "extract_keys.h"
|
#include "extract_keys.h"
|
||||||
|
|
||||||
#define KEY_SIZE 16
|
#define KEY_SIZE 16
|
||||||
#ifndef PROTOBUF_BLOCK_SIZE
|
|
||||||
#define PROTOBUF_BLOCK_SIZE 0
|
|
||||||
#endif
|
|
||||||
// #define EXPORT_BUFFER_SIZE 100000
|
|
||||||
|
|
||||||
void process_key(TemporaryExposureKey* key) {
|
void process_key(TemporaryExposureKey* key) {
|
||||||
// if (key) {
|
// TODO: Implement
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t generate_keys(uint8_t** buffer_pointer, int num_keys) {
|
size_t generate_keys(uint8_t** buffer_pointer, int num_keys) {
|
||||||
TemporaryExposureKeyExport export = TEMPORARY_EXPOSURE_KEY_EXPORT__INIT;
|
TemporaryExposureKeyExport export = TEMPORARY_EXPOSURE_KEY_EXPORT__INIT;
|
||||||
// temporary_exposure_key_export__init(&export);
|
|
||||||
TemporaryExposureKey** key_ptrs = (TemporaryExposureKey**)k_malloc(sizeof(TemporaryExposureKey*) * num_keys);
|
TemporaryExposureKey** key_ptrs = (TemporaryExposureKey**)k_malloc(sizeof(TemporaryExposureKey*) * num_keys);
|
||||||
if (key_ptrs == NULL) {
|
if (key_ptrs == NULL) {
|
||||||
printk("Could not allocate memory for pointers\n");
|
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_num = 1;
|
||||||
export.batch_size = 1;
|
export.batch_size = 1;
|
||||||
// TemporaryExposureKey* key_ptrs[num_keys];
|
|
||||||
uint8_t key_data[KEY_SIZE];
|
uint8_t key_data[KEY_SIZE];
|
||||||
for (int i = 0; i < KEY_SIZE; i++) {
|
for (int i = 0; i < KEY_SIZE; i++) {
|
||||||
key_data[i] = 0xFF;
|
key_data[i] = 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryExposureKey key = TEMPORARY_EXPOSURE_KEY__INIT;
|
TemporaryExposureKey key = TEMPORARY_EXPOSURE_KEY__INIT;
|
||||||
// temporary_exposure_key__init(&key);
|
|
||||||
key.key_data.data = key_data;
|
key.key_data.data = key_data;
|
||||||
key.key_data.len = KEY_SIZE;
|
key.key_data.len = KEY_SIZE;
|
||||||
key.has_key_data = true;
|
key.has_key_data = true;
|
||||||
@ -77,7 +66,6 @@ int unpack_keys(uint8_t* buf, size_t buf_size) {
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("Num keys %d\n", export->n_keys);
|
|
||||||
// Iterate over new keys
|
// Iterate over new keys
|
||||||
for (int i = 0; i < export->n_keys; i++) {
|
for (int i = 0; i < export->n_keys; i++) {
|
||||||
TemporaryExposureKey* key = export->keys[i];
|
TemporaryExposureKey* key = export->keys[i];
|
||||||
|
@ -3,12 +3,39 @@
|
|||||||
|
|
||||||
#include "export.pb-c.h"
|
#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
|
#endif
|
Loading…
Reference in New Issue
Block a user