mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-26 03:53:41 +00:00
Read identities up to three times before allowing replacement, publish only complete reads, and require new startup keys to be saved with bounded retries. Use authoritative replay-file metadata throughout persistence and clock recovery. Validate setperm input before narrowing or mutating roles, and add production-path regression coverage.
33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#if defined(ESP32) || defined(RP2040_PLATFORM)
|
|
#include <FS.h>
|
|
#define FILESYSTEM fs::FS
|
|
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
|
#include <Adafruit_LittleFS.h>
|
|
#define FILESYSTEM Adafruit_LittleFS
|
|
|
|
using namespace Adafruit_LittleFS_Namespace;
|
|
#endif
|
|
#include <Identity.h>
|
|
|
|
class IdentityStore {
|
|
FILESYSTEM* _fs;
|
|
const char* _dir;
|
|
public:
|
|
static constexpr unsigned IO_ATTEMPTS = 3;
|
|
IdentityStore(FILESYSTEM& fs, const char* dir): _fs(&fs), _dir(dir) { }
|
|
|
|
void begin() {
|
|
if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); } }
|
|
// Recover an interrupted non-replacing rename before deciding this is a
|
|
// fresh identity. False means the previous image must remain protected.
|
|
bool recover(const char* name);
|
|
bool load(const char *name, mesh::LocalIdentity& id);
|
|
bool load(const char *name, mesh::LocalIdentity& id, char display_name[], int max_name_sz);
|
|
bool save(const char *name, const mesh::LocalIdentity& id);
|
|
// Startup must not run with a new identity that was never made durable.
|
|
bool saveWithRetry(const char *name, const mesh::LocalIdentity& id);
|
|
bool save(const char *name, const mesh::LocalIdentity& id, const char display_name[]);
|
|
};
|