pub struct SqlitePib { /* private fields */ }Expand description
SQLite-backed PIB, wire-compatible with ndn-cxx pib-sqlite3.
All public methods take &self and serialise through an internal
Mutex<Connection>. SQLite handles its own concurrency control, but
rusqlite::Connection is not Sync so we wrap it.
Implementations§
Source§impl SqlitePib
impl SqlitePib
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, PibError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, PibError>
Open or create a pib.db at path, initialising the schema if
absent. Equivalent to ndn-cxx’s PibSqlite3(location) constructor
when location points at a directory; here we expect the full
file path.
Sourcepub fn open_default() -> Result<Self, PibError>
pub fn open_default() -> Result<Self, PibError>
Open the default PIB at $HOME/.ndn/pib.db, mirroring
PibSqlite3() with an empty location argument. Honours
TEST_HOME first (for parity with ndn-cxx test harnesses), then
HOME, then the current working directory.
Sourcepub fn get_tpm_locator(&self) -> Result<Option<String>, PibError>
pub fn get_tpm_locator(&self) -> Result<Option<String>, PibError>
Return the TPM locator string the PIB was last associated with,
e.g. "tpm-file:" or "tpm-file:/custom/path". None if no
locator has ever been set on this DB.
Sourcepub fn set_tpm_locator(&self, locator: &str) -> Result<(), PibError>
pub fn set_tpm_locator(&self, locator: &str) -> Result<(), PibError>
Set the TPM locator string. Mirrors ndn-cxx’s update-then-insert
dance (no SQLite UPSERT was available when the schema was
designed): try UPDATE, and if no row was affected, INSERT.
Sourcepub fn add_identity(&self, identity: &Name) -> Result<(), PibError>
pub fn add_identity(&self, identity: &Name) -> Result<(), PibError>
Add identity to the PIB. Idempotent: re-adding an existing
identity is a no-op (the unique index on identity would otherwise
reject it).
Sourcepub fn has_identity(&self, identity: &Name) -> Result<bool, PibError>
pub fn has_identity(&self, identity: &Name) -> Result<bool, PibError>
Return true if the named identity is in the PIB.
Sourcepub fn delete_identity(&self, identity: &Name) -> Result<(), PibError>
pub fn delete_identity(&self, identity: &Name) -> Result<(), PibError>
Delete an identity and (via ON DELETE CASCADE) all keys and
certificates rooted at it.
Sourcepub fn list_identities(&self) -> Result<Vec<Name>, PibError>
pub fn list_identities(&self) -> Result<Vec<Name>, PibError>
List all identities in the PIB, in insertion order.
Sourcepub fn set_default_identity(&self, identity: &Name) -> Result<(), PibError>
pub fn set_default_identity(&self, identity: &Name) -> Result<(), PibError>
Mark identity as the default. The trigger
identity_default_update_trigger clears the previous default in
the same operation, so callers do not need to do it manually.
Sourcepub fn get_default_identity(&self) -> Result<Option<Name>, PibError>
pub fn get_default_identity(&self) -> Result<Option<Name>, PibError>
Return the current default identity, if one is set.
Sourcepub fn add_key(
&self,
identity: &Name,
key_name: &Name,
key_bits: &[u8],
) -> Result<(), PibError>
pub fn add_key( &self, identity: &Name, key_name: &Name, key_bits: &[u8], ) -> Result<(), PibError>
Add a key under an existing identity. The identity must already
exist; ndn-cxx’s addKey adds it implicitly via a subquery, so
we do the same here. key_bits is the raw public-key bytes (for
ndn-cxx-issued keys this is a DER SubjectPublicKeyInfo).
Sourcepub fn get_key_bits(&self, key_name: &Name) -> Result<Option<Vec<u8>>, PibError>
pub fn get_key_bits(&self, key_name: &Name) -> Result<Option<Vec<u8>>, PibError>
Return the raw key_bits (public-key BLOB) for a key, if present.
Sourcepub fn delete_key(&self, key_name: &Name) -> Result<(), PibError>
pub fn delete_key(&self, key_name: &Name) -> Result<(), PibError>
Delete a key and (via cascade) all certificates issued under it.
Sourcepub fn list_keys(&self, identity: &Name) -> Result<Vec<Name>, PibError>
pub fn list_keys(&self, identity: &Name) -> Result<Vec<Name>, PibError>
List all keys under identity, in insertion order.
Sourcepub fn set_default_key(&self, key_name: &Name) -> Result<(), PibError>
pub fn set_default_key(&self, key_name: &Name) -> Result<(), PibError>
Mark key_name as the default key for its parent identity.
Sourcepub fn get_default_key(&self, identity: &Name) -> Result<Option<Name>, PibError>
pub fn get_default_key(&self, identity: &Name) -> Result<Option<Name>, PibError>
Return the default key for identity, if one is set.
Sourcepub fn add_certificate(
&self,
key_name: &Name,
cert_name: &Name,
cert_data: &[u8],
) -> Result<(), PibError>
pub fn add_certificate( &self, key_name: &Name, cert_name: &Name, cert_data: &[u8], ) -> Result<(), PibError>
Add a certificate under an existing key. The key must already exist (we don’t auto-create it; ndn-cxx fails the foreign key constraint here too).
Sourcepub fn get_certificate(
&self,
cert_name: &Name,
) -> Result<Option<Vec<u8>>, PibError>
pub fn get_certificate( &self, cert_name: &Name, ) -> Result<Option<Vec<u8>>, PibError>
Return the full Data-wire bytes of cert_name, if present.
Sourcepub fn delete_certificate(&self, cert_name: &Name) -> Result<(), PibError>
pub fn delete_certificate(&self, cert_name: &Name) -> Result<(), PibError>
Delete a certificate by name.
Sourcepub fn list_certificates(&self, key_name: &Name) -> Result<Vec<Name>, PibError>
pub fn list_certificates(&self, key_name: &Name) -> Result<Vec<Name>, PibError>
List all certificate names issued under key_name.