Database schema
Vault uses a single SQLite table:
| Column | Type | Description |
|---|---|---|
label | TEXT PRIMARY KEY | Human-readable key name, e.g. "default-rsa" |
type | TEXT | Key algorithm identifier. See key types below. |
data | TEXT | Key material. PEM string for RSA; empty string for PQC stubs. |
Key types
| Value | Description |
|---|---|
"rsa" | PEM-encoded RSA private key produced by Crypto::generate_rsa() |
"dilithium" | Planned post-quantum key (Dilithium). Currently stored as an empty string — pqc_generate() is a stub. |
Constructor
Vault(const std::string& path)
Opens (or creates) the SQLite database file at the given path. The constructor calls sqlite3_open internally.
Filesystem path to the SQLite database file, e.g.
"vault.db". The file is created if it does not exist.Methods
void init()
Creates the keys table if it does not already exist. Must be called once before any store_key or get_key calls.
Parameters: None
Returns: void
void store_key(const std::string& label, const std::string& type, const std::string& data)
Inserts or replaces a key record. Uses INSERT OR REPLACE INTO keys VALUES(...) semantics — if a key with the same label already exists, it is overwritten.
Unique name for the key, e.g.
"default-rsa" or "default-pq". Acts as the primary key.Algorithm identifier. Use
"rsa" for RSA keys or "dilithium" for post-quantum keys.Key material as a string. For RSA keys, pass the PEM-encoded private key returned by
Crypto::generate_rsa(). For PQC keys, pass an empty string (the current stub produces no key material).void
std::string get_key(const std::string& label)
Retrieves the data column for the key with the given label. Executes SELECT data FROM keys WHERE label=<label>.
The label used when the key was stored.
std::string — the stored key data (PEM string for RSA). Returns an empty string "" if no key with that label exists.
Complete example
This mirrors the startup sequence inpkcs11-daemon/daemon.cpp: