Files
MeshCore/test/fixtures/contact_cache/mocks/Identity.h
T
mikecarper 24f707c7a0 Retry identity startup and harden replay state and permissions
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.
2026-09-15 17:33:50 -07:00

31 lines
853 B
C++

#pragma once
#include "Utils.h"
#include <ed_25519.h>
namespace mesh {
class Identity {
public:
uint8_t pub_key[32] = {};
Identity() = default;
explicit Identity(const uint8_t* key) { memcpy(pub_key, key, 32); }
};
class LocalIdentity : public Identity {
public:
uint8_t private_key[64] = {};
mutable unsigned derivations = 0;
template <typename Reader> bool readFrom(Reader& in) {
return in.read(pub_key, sizeof(pub_key)) == sizeof(pub_key)
&& in.read(private_key, sizeof(private_key)) == sizeof(private_key);
}
size_t writeTo(uint8_t* out, size_t size) const {
if (size < 96) return 0;
memcpy(out, private_key, 64);
memcpy(out + 64, pub_key, 32);
return 96;
}
void calcSharedSecret(uint8_t* out, const uint8_t* peer) const {
++derivations;
ed25519_key_exchange(out, peer, private_key);
}
};
}