Skip to content

Commit 8f90875

Browse files
reset entry now remove old keys
1 parent 23c6a69 commit 8f90875

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

features/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ const uint16_t DB_VERSION = 1;
4040

4141
#define DB_STORE_OFFSET_PEER_SIGNING_COUNT (DB_STORE_OFFSET_PEER_SIGNING + sizeof(csrk_t))
4242

43+
/* make size multiple of 4 */
44+
#define PAD4(value) ((((value - 1) / 4) * 4) + 4)
45+
4346
#define DB_SIZE_STORE \
44-
(sizeof(SecurityEntryKeys_t) + \
47+
PAD4(sizeof(SecurityEntryKeys_t) + \
4548
sizeof(SecurityEntryKeys_t) + \
4649
sizeof(SecurityEntryIdentity_t) + \
4750
sizeof(SecurityEntrySigning_t) + \
@@ -65,8 +68,7 @@ const uint16_t DB_VERSION = 1;
6568
#define DB_OFFSET_ENTRIES (DB_OFFSET_LOCAL_SIGN_COUNT + sizeof(sign_count_t))
6669
#define DB_OFFSET_STORES (DB_OFFSET_ENTRIES + DB_SIZE_ENTRIES)
6770
#define DB_OFFSET_MAX (DB_OFFSET_STORES + DB_SIZE_STORES)
68-
/* make size multiple of 4 */
69-
#define DB_SIZE ((((DB_OFFSET_MAX - 1) / 4) * 4) + 4)
71+
#define DB_SIZE PAD4(DB_OFFSET_MAX)
7072

7173
typedef SecurityDb::entry_handle_t entry_handle_t;
7274

@@ -311,6 +313,14 @@ void FileSecurityDb::reset_entry(entry_handle_t db_entry) {
311313
if (!entry) {
312314
return;
313315
}
316+
317+
fseek(_db_file, entry->file_offset, SEEK_SET);
318+
const uint32_t zero = 0;
319+
size_t count = DB_SIZE_STORE / 4;
320+
while (count--) {
321+
fwrite(&zero, sizeof(zero), 1, _db_file);
322+
}
323+
314324
entry->flags = SecurityDistributionFlags_t();
315325
entry->peer_sign_counter = 0;
316326
}

0 commit comments

Comments
 (0)