@@ -21,7 +21,8 @@ namespace generic {
21
21
22
22
const uint16_t DB_VERSION = 1 ;
23
23
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))
25
26
#define DB_STORE_OFFSET_PEER_KEYS (DB_STORE_OFFSET_LOCAL_KEYS + sizeof (SecurityEntryKeys_t))
26
27
#define DB_STORE_OFFSET_PEER_IDENTITY (DB_STORE_OFFSET_PEER_KEYS + sizeof (SecurityEntryKeys_t))
27
28
#define DB_STORE_OFFSET_PEER_SIGNING (DB_STORE_OFFSET_PEER_IDENTITY + sizeof (SecurityEntryIdentity_t))
@@ -44,18 +45,13 @@ const uint16_t DB_VERSION = 1;
44
45
#define PAD4 (value ) ((((value - 1 ) / 4 ) * 4 ) + 4 )
45
46
46
47
#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
+ )
59
55
60
56
#define DB_SIZE_STORES \
61
57
(FileSecurityDb::MAX_ENTRIES * DB_SIZE_STORE)
@@ -65,8 +61,7 @@ const uint16_t DB_VERSION = 1;
65
61
#define DB_OFFSET_LOCAL_IDENTITY (DB_OFFSET_RESTORE + sizeof (bool ))
66
62
#define DB_OFFSET_LOCAL_CSRK (DB_OFFSET_LOCAL_IDENTITY + sizeof (SecurityEntryIdentity_t))
67
63
#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 ))
70
65
#define DB_OFFSET_MAX (DB_OFFSET_STORES + DB_SIZE_STORES)
71
66
#define DB_SIZE PAD4 (DB_OFFSET_MAX)
72
67
@@ -288,10 +283,10 @@ void FileSecurityDb::restore() {
288
283
db_read (&_local_csrk, DB_OFFSET_LOCAL_CSRK);
289
284
db_read (&_local_sign_counter, DB_OFFSET_LOCAL_SIGN_COUNT);
290
285
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 */
293
287
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);
295
290
}
296
291
297
292
}
@@ -303,6 +298,7 @@ void FileSecurityDb::sync(entry_handle_t db_handle) {
303
298
}
304
299
305
300
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);
306
302
}
307
303
308
304
void FileSecurityDb::set_restore (bool reload) {
0 commit comments