CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
GpgRecvStore.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <cstddef>
5
6namespace cdc::mod_gpg {
7
8constexpr uint8_t kGpgRecvFlagVerified = 0x01;
9
19#pragma pack(push, 1)
21 uint8_t curve;
22 char user_id[64];
23 uint8_t pubkey[64];
24 uint8_t pubkey_len;
25 uint8_t fingerprint_v4[20];
26 uint8_t fingerprint_v5[32];
27 uint32_t received_at;
28 uint8_t my_signature[64];
29 uint8_t sig_len;
30 uint8_t flags;
31};
32#pragma pack(pop)
33
34static_assert(sizeof(gpg_recv_key_t) ==
35 (1 + 64 + 64 + 1 + 20 + 32 + 4 + 64 + 1 + 1),
36 "gpg_recv_key_t layout drift");
37
46 char nvs_key[16];
47 uint32_t received_at;
48 uint8_t flags;
49};
50
58class GpgRecvStore {
59public:
61 static constexpr uint8_t kMaxKeys = 128;
62
63 static GpgRecvStore& instance();
64
66 bool addKey(const gpg_recv_key_t& key);
67
69 uint8_t count();
70
77 uint8_t listIndex(gpg_recv_index_entry_t* out, uint8_t max);
78
80 bool getKey(uint8_t index, gpg_recv_key_t* out);
81
83 bool deleteKey(uint8_t index);
84
86 bool setSignature(uint8_t index,
87 const uint8_t* sig, uint8_t sig_len,
88 uint8_t flags);
89
90private:
91 GpgRecvStore() = default;
92 GpgRecvStore(const GpgRecvStore&) = delete;
93 GpgRecvStore& operator=(const GpgRecvStore&) = delete;
94
96 static void deriveKeyName(const uint8_t fp_v4[20], char out[16]);
97
99 bool readByName(const char* nvs_key, gpg_recv_key_t* out);
100
102 bool writeByName(const char* nvs_key, const gpg_recv_key_t& key);
103
105 bool resolveKeyName(uint8_t index, char out[16]);
106};
107
108} // namespace cdc::mod_gpg
uint8_t flags
bool addKey(const gpg_recv_key_t &key)
Persist a new key. Replaces an existing entry if the fingerprint matches.
bool deleteKey(uint8_t index)
Remove one key by sorted index. No-op if index is out of range.
bool setSignature(uint8_t index, const uint8_t *sig, uint8_t sig_len, uint8_t flags)
Attach a cross-signature and flag bits to an existing entry.
bool getKey(uint8_t index, gpg_recv_key_t *out)
Load one key by sorted index (0..count()-1).
static GpgRecvStore & instance()
uint8_t listIndex(gpg_recv_index_entry_t *out, uint8_t max)
Build the sorted index (oldest first).
uint8_t count()
Number of stored keys.
static constexpr uint8_t kMaxKeys
Hard ceiling. Past this addKey rejects further inserts.
constexpr uint8_t kGpgRecvFlagVerified
Definition GpgRecvStore.h:8
Sort entry used to expose a stable ordered index over NVS keys.
char nvs_key[16]
uint8_t flags
uint32_t received_at
One GPG public key received from another badge.