mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-04 16:45:43 +01:00
Make the packing and unpacking work
This commit is contained in:
parent
a50b6746c0
commit
8f532ac7e4
@ -9,7 +9,7 @@
|
||||
#include "extract_keys.h"
|
||||
|
||||
|
||||
#define KEY_SIZE 8
|
||||
#define KEY_SIZE 16
|
||||
#ifndef PROTOBUF_BLOCK_SIZE
|
||||
#define PROTOBUF_BLOCK_SIZE 0
|
||||
#endif
|
||||
@ -31,28 +31,30 @@ void process_key(TemporaryExposureKey* key) {
|
||||
}
|
||||
|
||||
size_t generate_keys(uint8_t** buffer_pointer, size_t max_size, int num_keys) {
|
||||
TemporaryExposureKeyExport export = {};
|
||||
temporary_exposure_key_export__init(&export);
|
||||
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");
|
||||
return 0;
|
||||
}
|
||||
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(&key);
|
||||
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;
|
||||
for (int i = 0; i < num_keys; i++) {
|
||||
key_ptrs[i] = &key;
|
||||
}
|
||||
export.keys = key_ptrs;
|
||||
export.n_keys = num_keys;
|
||||
export.keys = key_ptrs;
|
||||
size_t required_buffer = temporary_exposure_key_export__get_packed_size(&export);
|
||||
uint8_t* buffer = (uint8_t*) k_malloc(required_buffer);
|
||||
if (buffer == NULL) {
|
||||
@ -62,7 +64,7 @@ size_t generate_keys(uint8_t** buffer_pointer, size_t max_size, int num_keys) {
|
||||
*buffer_pointer = buffer;
|
||||
if (buffer != NULL) {
|
||||
size_t buf_size = temporary_exposure_key_export__pack(&export, buffer);
|
||||
free(key_ptrs);
|
||||
k_free(key_ptrs);
|
||||
return buf_size;
|
||||
} else {
|
||||
printk("Buffer too small to serialize %d keys. %d bytes necessary\n", num_keys, required_buffer);
|
||||
@ -78,7 +80,9 @@ int unpack_keys(uint8_t* buf, size_t buf_size) {
|
||||
printk("error unpacking incoming message\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printk("Buffer %s\n", buf);
|
||||
printk("Batch num: %d, batch size: %d\n", export->batch_num, export->batch_size);
|
||||
printk("Number of keys: %d\n", export->n_keys);
|
||||
// Iterate over new keys
|
||||
for (int i = 0; i < export->n_keys; i++) {
|
||||
TemporaryExposureKey* key = export->keys[i];
|
||||
|
Loading…
Reference in New Issue
Block a user