pub struct Database { /* private fields */ }Expand description
An open Citadel database (Send + Sync).
Exclusively locks the database file for its lifetime.
Implementations§
Source§impl Database
impl Database
Sourcepub fn sql_cache_get<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>
pub fn sql_cache_get<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>
Fetch a typed entry from the shared SQL cache.
Returns None if the key is missing or stored under a different type.
Sourcepub fn sql_cache_insert<T: Any + Send + Sync>(&self, key: String, value: Arc<T>)
pub fn sql_cache_insert<T: Any + Send + Sync>(&self, key: String, value: Arc<T>)
Insert (or overwrite) a typed entry in the shared SQL cache.
Sourcepub fn sql_cache_invalidate_prefix(&self, prefix: &str) -> usize
pub fn sql_cache_invalidate_prefix(&self, prefix: &str) -> usize
Remove every entry whose key starts with prefix.
Returns the number of entries removed.
Sourcepub fn sql_cache_len(&self) -> usize
pub fn sql_cache_len(&self) -> usize
Total number of cache entries (test/diagnostics helper).
Sourcepub fn sql_cache_handle(&self) -> SqlCacheHandle
pub fn sql_cache_handle(&self) -> SqlCacheHandle
Cloneable handle to the shared cache.
Sourcepub fn begin_read(&self) -> ReadTxn<'_>
pub fn begin_read(&self) -> ReadTxn<'_>
Begin a read-only transaction with snapshot isolation.
Sourcepub fn begin_write(&self) -> Result<WriteTxn<'_>>
pub fn begin_write(&self) -> Result<WriteTxn<'_>>
Begin a read-write transaction. Only one can be active at a time.
pub fn data_path(&self) -> &Path
pub fn key_path(&self) -> &Path
Sourcepub fn file_id(&self) -> u64
pub fn file_id(&self) -> u64
Database file identifier from the file header. citadel-mem binds the region key store to this value so a mismatched sidecar is rejected.
Sourcepub fn region_keys_enabled(&self) -> bool
pub fn region_keys_enabled(&self) -> bool
Whether per-region cryptographic erasure keys are available.
true only when the database was opened with enable_region_keys(true).
Sourcepub fn wrap_region_key(&self, rck: &[u8; 32]) -> Result<[u8; 40]>
pub fn wrap_region_key(&self, rck: &[u8; 32]) -> Result<[u8; 40]>
Wrap a region’s random content key (RCK) under the region KEK (AES-256-KW). The 40-byte result is the sole copy of the RCK; citadel-mem stores it in the sidecar key store and overwrites it in place to erase the region.
Sourcepub fn unwrap_region_key(&self, wrapped: &[u8; 40]) -> Result<[u8; 32]>
pub fn unwrap_region_key(&self, wrapped: &[u8; 40]) -> Result<[u8; 32]>
Unwrap a region content key. Fails if the slot was erased (zeroed wrap).
Sourcepub fn region_store_mac_key(&self) -> Result<[u8; 32]>
pub fn region_store_mac_key(&self) -> Result<[u8; 32]>
HMAC key authenticating the region key store’s header and slots (torn-write detection only; RCK secrecy is protected by AES-KW).
Sourcepub fn region_store_path(&self) -> PathBuf
pub fn region_store_path(&self) -> PathBuf
Path to the sidecar region key store, {key_path} with the
citadel-regions extension. Pure path math; valid even when region keys
are disabled (the file only exists once an encrypted region is created).
Sourcepub fn region_store_allocate_write(
&self,
region_id: u64,
wrapped: &[u8; 40],
) -> Result<(u32, u64)>
pub fn region_store_allocate_write( &self, region_id: u64, wrapped: &[u8; 40], ) -> Result<(u32, u64)>
Allocate a slot and store the wrapped RCK (fsync’d); returns (slot, gen).
Sourcepub fn region_store_slot(&self, slot: u32) -> Result<SlotRecord>
pub fn region_store_slot(&self, slot: u32) -> Result<SlotRecord>
The authoritative record of region key slot.
Sourcepub fn region_store_tombstone(&self, slot: u32, region_id: u64) -> Result<()>
pub fn region_store_tombstone(&self, slot: u32, region_id: u64) -> Result<()>
Cryptographically erase region key slot (no-op if already erased).
Sourcepub fn region_store_live_owners(&self) -> Result<Vec<(u32, u64)>>
pub fn region_store_live_owners(&self) -> Result<Vec<(u32, u64)>>
(slot, region_id) for every LIVE region key slot.
Sourcepub fn atom_store_path(&self) -> PathBuf
pub fn atom_store_path(&self) -> PathBuf
Path to the sidecar per-atom key store, {key_path} with the citadel-atomkeys
extension. Pure path math; the file only exists once an encrypted atom is written.
Sourcepub fn atom_store_allocate_write(
&self,
atom_id: u64,
wrapped: &[u8; 40],
) -> Result<(u32, u64)>
pub fn atom_store_allocate_write( &self, atom_id: u64, wrapped: &[u8; 40], ) -> Result<(u32, u64)>
Allocate a slot and store one atom’s wrapped ACK (fsync’d); returns (slot, gen).
Sourcepub fn atom_store_allocate_batch(
&self,
items: &[(u64, [u8; 40])],
) -> Result<Vec<(u32, u64)>>
pub fn atom_store_allocate_batch( &self, items: &[(u64, [u8; 40])], ) -> Result<Vec<(u32, u64)>>
Allocate and durably write a batch of (atom_id, wrapped) ACKs with ONE fsync;
returns (slot, gen) per item in order.
Sourcepub fn atom_store_slot(&self, slot: u32) -> Result<SlotRecord>
pub fn atom_store_slot(&self, slot: u32) -> Result<SlotRecord>
The authoritative record of atom key slot (its wrapped ACK and state).
Sourcepub fn atom_store_tombstone(&self, slot: u32, atom_id: u64) -> Result<()>
pub fn atom_store_tombstone(&self, slot: u32, atom_id: u64) -> Result<()>
Cryptographically erase atom key slot (no-op if already erased).
Sourcepub fn atom_store_tombstone_batch(&self, items: &[(u32, u64)]) -> Result<()>
pub fn atom_store_tombstone_batch(&self, items: &[(u32, u64)]) -> Result<()>
Erase a batch of atom key slots with two fsyncs total (not 2N). Items are (slot, atom_id).
Sourcepub fn atom_store_live_wrapped(&self) -> Result<FxHashMap<u64, [u8; 40]>>
pub fn atom_store_live_wrapped(&self) -> Result<FxHashMap<u64, [u8; 40]>>
Every LIVE atom key’s atom_id -> wrapped ACK, in one whole-file pass.
Sourcepub fn atom_store_live_owners(&self) -> Result<Vec<(u32, u64)>>
pub fn atom_store_live_owners(&self) -> Result<Vec<(u32, u64)>>
(slot, atom_id) for every LIVE atom key slot.
Sourcepub fn reader_count(&self) -> usize
pub fn reader_count(&self) -> usize
Number of currently active readers.
Sourcepub fn change_passphrase(
&self,
old_passphrase: &[u8],
new_passphrase: &[u8],
) -> Result<()>
pub fn change_passphrase( &self, old_passphrase: &[u8], new_passphrase: &[u8], ) -> Result<()>
Change the database passphrase (re-wraps REK, no page re-encryption).
pub fn integrity_check(&self) -> Result<IntegrityReport>
Sourcepub fn backup(&self, dest_path: &Path) -> Result<()>
pub fn backup(&self, dest_path: &Path) -> Result<()>
Create a hot backup via MVCC snapshot. Also copies the key file.
Sourcepub fn export_key_backup(
&self,
db_passphrase: &[u8],
backup_passphrase: &[u8],
dest_path: &Path,
) -> Result<()>
pub fn export_key_backup( &self, db_passphrase: &[u8], backup_passphrase: &[u8], dest_path: &Path, ) -> Result<()>
Export an encrypted key backup for disaster recovery.
Requires the current database passphrase. The backup can later restore
access via restore_key_from_backup if the database passphrase is lost.
Sourcepub fn restore_key_from_backup(
backup_path: &Path,
backup_passphrase: &[u8],
new_db_passphrase: &[u8],
db_path: &Path,
) -> Result<()>
pub fn restore_key_from_backup( backup_path: &Path, backup_passphrase: &[u8], new_db_passphrase: &[u8], db_path: &Path, ) -> Result<()>
Restore a key file from an encrypted backup (static - no Database needed).
Unwraps the REK using backup_passphrase, then creates a new key file
protected by new_db_passphrase.
Source§impl Database
impl Database
Sourcepub fn audit_log_path(&self) -> Option<PathBuf>
pub fn audit_log_path(&self) -> Option<PathBuf>
Path to the audit log file, if audit logging is enabled.
Sourcepub fn verify_audit_log(&self) -> Result<AuditVerifyResult>
pub fn verify_audit_log(&self) -> Result<AuditVerifyResult>
Verify the audit log’s HMAC chain integrity.
Source§impl Database
impl Database
Sourcepub fn sync_to(&self, addr: &str, sync_key: &SyncKey) -> Result<SyncOutcome>
pub fn sync_to(&self, addr: &str, sync_key: &SyncKey) -> Result<SyncOutcome>
Push local named tables to a remote peer.
Sourcepub fn handle_sync(
&self,
stream: TcpStream,
sync_key: &SyncKey,
) -> Result<SyncOutcome>
pub fn handle_sync( &self, stream: TcpStream, sync_key: &SyncKey, ) -> Result<SyncOutcome>
Handle an incoming sync session from a remote peer.