Commit 1914e3a3 authored by cRTrn13's avatar cRTrn13

keyfile

parent d34624e4
......@@ -3,11 +3,27 @@
#include "file.h"
#include "../util/macro.h"
uint8_t *_record(KEYFILE *kf, uint8_t type, size_t *rec_len);
uint8_t *keyfile_record(KEYFILE *kf, enum keyfile_types type, uint16_t *entries, size_t *entry_len)
{
size_t pos = 0, len = 0;
while (pos + 4 <= len) {
len = MKINT_BE24(kf->buf + pos + 1);
if (entries) {
*entries = MKINT_BE16(kf->buf + pos + 4);
}
if (entry_len) {
*entry_len = MKINT_BE32(kf->buf + pos + 6);
}
if (kf->buf[pos] == type)
return kf->buf + pos + 10; // only return ptr to first byte of entry
pos += len;
}
uint8_t *_record(KEYFILE *kf, uint8_t type, size_t *rec_len)
{
return NULL;
}
......
......@@ -11,7 +11,31 @@ struct keyfile {
uint8_t *buf;
};
enum keyfile_types {
KF_DK_ARRAY = 0x01,
KF_PK_ARRAY,
KF_HOST_PRIV_KEY,
KF_HOST_CERT,
KF_HOST_NONCE,
KF_HOST_KEY_POINT
};
KEYFILE *keyfile_open(const char *path);
void keyfile_close(KEYFILE *kf);
uint8_t *keyfile_record(KEYFILE *kf, enum keyfile_types type, uint16_t *entries, size_t *entry_len);
/* Keys are stored in a binary file in a record format which is queried from this code
*
* Record format:
* 0 | type
* 1-3 | length
* 4-5 | num entries
* 6-9 | entry length
* 10-(9+entry_length)| entry 1
* .
* .
* length-1 | end
*
*/
#endif /* KEYFILE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment