CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
GpgSelfCertStore.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6namespace cdc::mod_gpg {
7
9constexpr size_t kGpgSelfCertSigMax = 160;
10
20#pragma pack(push, 1)
22 uint8_t issuer_fp_v4[20];
23 char issuer_uid[64];
24 uint32_t received_at;
25 uint16_t sig_pkt_len;
27};
28#pragma pack(pop)
29
30static_assert(sizeof(gpg_self_cert_t) ==
31 (20 + 64 + 4 + 2 + kGpgSelfCertSigMax),
32 "gpg_self_cert_t layout drift");
33
38 char nvs_key[16];
39 uint32_t received_at;
40};
41
48class GpgSelfCertStore {
49public:
51 static constexpr uint8_t kMaxCerts = 16;
52
53 static GpgSelfCertStore& instance();
54
56 bool addCert(const gpg_self_cert_t& cert);
57
59 uint8_t count();
60
67 uint8_t listIndex(gpg_self_cert_index_entry_t* out, uint8_t max);
68
70 bool getCert(uint8_t index, gpg_self_cert_t* out);
71
73 bool deleteCert(uint8_t index);
74
75private:
76 GpgSelfCertStore() = default;
77 GpgSelfCertStore(const GpgSelfCertStore&) = delete;
78 GpgSelfCertStore& operator=(const GpgSelfCertStore&) = delete;
79
80 static void deriveKeyName(const uint8_t issuer_fp_v4[20], char out[16]);
81 bool readByName(const char* nvs_key, gpg_self_cert_t* out);
82 bool writeByName(const char* nvs_key, const gpg_self_cert_t& cert);
83 bool resolveKeyName(uint8_t index, char out[16]);
84};
85
86} // namespace cdc::mod_gpg
uint8_t count()
Number of stored certifications.
static GpgSelfCertStore & instance()
uint8_t listIndex(gpg_self_cert_index_entry_t *out, uint8_t max)
Build the sorted index (oldest first).
bool getCert(uint8_t index, gpg_self_cert_t *out)
Load one certification by sorted index (0..count()-1).
bool deleteCert(uint8_t index)
Remove one certification by sorted index. No-op if out of range.
static constexpr uint8_t kMaxCerts
Hard ceiling. Past this addCert rejects further inserts.
bool addCert(const gpg_self_cert_t &cert)
Persist a certification. Replaces an existing entry from the same issuer.
constexpr size_t kGpgSelfCertSigMax
Maximum length of a stored certification signature packet body (Tag 2).
Sort entry exposing a stable ordered index over the NVS blobs.
uint32_t received_at
char nvs_key[16]
One third-party certification received over the badge's own key.
uint8_t sig_pkt[kGpgSelfCertSigMax]
char issuer_uid[64]
Issuer user-id (display only).
uint32_t received_at
Receive timestamp (RTC).
uint16_t sig_pkt_len
Length of sig_pkt.
uint8_t issuer_fp_v4[20]
Issuer (signer) v4 fingerprint.