Skip to content

Commit 08cb7ae

Browse files
fix not writing flags in the file
flags kept with the rest of data for each entry
1 parent 84ff831 commit 08cb7ae

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

features/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace generic {
2121

2222
const uint16_t DB_VERSION = 1;
2323

24-
#define DB_STORE_OFFSET_LOCAL_KEYS (0)
24+
#define DB_STORE_OFFSET_FLAGS (0)
25+
#define DB_STORE_OFFSET_LOCAL_KEYS (DB_STORE_OFFSET_FLAGS + sizeof(SecurityDistributionFlags_t))
2526
#define DB_STORE_OFFSET_PEER_KEYS (DB_STORE_OFFSET_LOCAL_KEYS + sizeof(SecurityEntryKeys_t))
2627
#define DB_STORE_OFFSET_PEER_IDENTITY (DB_STORE_OFFSET_PEER_KEYS + sizeof(SecurityEntryKeys_t))
2728
#define DB_STORE_OFFSET_PEER_SIGNING (DB_STORE_OFFSET_PEER_IDENTITY + sizeof(SecurityEntryIdentity_t))
@@ -44,18 +45,13 @@ const uint16_t DB_VERSION = 1;
4445
#define PAD4(value) ((((value - 1) / 4) * 4) + 4)
4546

4647
#define DB_SIZE_STORE \
47-
PAD4(sizeof(SecurityEntryKeys_t) + \
48-
sizeof(SecurityEntryKeys_t) + \
49-
sizeof(SecurityEntryIdentity_t) + \
50-
sizeof(SecurityEntrySigning_t) + \
51-
sizeof(sign_count_t))
52-
53-
/* without the size of the file offset as we don't store it */
54-
#define DB_SIZE_ENTRY \
55-
(sizeof(SecurityDistributionFlags_t) + sizeof(sign_count_t))
56-
57-
#define DB_SIZE_ENTRIES \
58-
(FileSecurityDb::MAX_ENTRIES * DB_SIZE_ENTRY)
48+
PAD4( \
49+
sizeof(SecurityDistributionFlags_t) + \
50+
sizeof(SecurityEntryKeys_t) + \
51+
sizeof(SecurityEntryKeys_t) + \
52+
sizeof(SecurityEntryIdentity_t) + \
53+
sizeof(SecurityEntrySigning_t) \
54+
)
5955

6056
#define DB_SIZE_STORES \
6157
(FileSecurityDb::MAX_ENTRIES * DB_SIZE_STORE)
@@ -65,8 +61,7 @@ const uint16_t DB_VERSION = 1;
6561
#define DB_OFFSET_LOCAL_IDENTITY (DB_OFFSET_RESTORE + sizeof(bool))
6662
#define DB_OFFSET_LOCAL_CSRK (DB_OFFSET_LOCAL_IDENTITY + sizeof(SecurityEntryIdentity_t))
6763
#define DB_OFFSET_LOCAL_SIGN_COUNT (DB_OFFSET_LOCAL_CSRK + sizeof(csrk_t))
68-
#define DB_OFFSET_ENTRIES (DB_OFFSET_LOCAL_SIGN_COUNT + sizeof(sign_count_t))
69-
#define DB_OFFSET_STORES (DB_OFFSET_ENTRIES + DB_SIZE_ENTRIES)
64+
#define DB_OFFSET_STORES (DB_OFFSET_LOCAL_SIGN_COUNT + sizeof(sign_count_t))
7065
#define DB_OFFSET_MAX (DB_OFFSET_STORES + DB_SIZE_STORES)
7166
#define DB_SIZE PAD4(DB_OFFSET_MAX)
7267

@@ -288,10 +283,10 @@ void FileSecurityDb::restore() {
288283
db_read(&_local_csrk, DB_OFFSET_LOCAL_CSRK);
289284
db_read(&_local_sign_counter, DB_OFFSET_LOCAL_SIGN_COUNT);
290285

291-
fseek(_db_file, DB_OFFSET_ENTRIES, SEEK_SET);
292-
/* we read the entries partially and fill the offsets ourselves*/
286+
/* read flags and sign counters */
293287
for (size_t i = 0; i < get_entry_count(); i++) {
294-
fread(&_entries[i], DB_SIZE_ENTRY, 1, _db_file);
288+
db_read(&_entries[i].flags, _entries[i].file_offset + DB_STORE_OFFSET_FLAGS);
289+
db_read(&_entries[i].peer_sign_counter, _entries[i].file_offset + DB_STORE_OFFSET_PEER_SIGNING_COUNT);
295290
}
296291

297292
}
@@ -303,6 +298,7 @@ void FileSecurityDb::sync(entry_handle_t db_handle) {
303298
}
304299

305300
db_write(&entry->peer_sign_counter, entry->file_offset + DB_STORE_OFFSET_PEER_SIGNING_COUNT);
301+
db_write(&entry->flags, entry->file_offset + DB_STORE_OFFSET_FLAGS);
306302
}
307303

308304
void FileSecurityDb::set_restore(bool reload) {

0 commit comments

Comments
 (0)