1
0
Fork 0
This commit is contained in:
cRTrn13 2009-10-15 15:17:15 +00:00
parent d34624e412
commit 1914e3a3d9
2 changed files with 44 additions and 4 deletions

View File

@ -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 *_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;
}
return NULL;
}

View File

@ -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_ */