SqlitePib

Struct SqlitePib 

Source
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

Source

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.

Source

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.

Source

pub fn path(&self) -> &Path

Path to the underlying database file.

Source

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.

Source

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.

Source

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).

Source

pub fn has_identity(&self, identity: &Name) -> Result<bool, PibError>

Return true if the named identity is in the PIB.

Source

pub fn delete_identity(&self, identity: &Name) -> Result<(), PibError>

Delete an identity and (via ON DELETE CASCADE) all keys and certificates rooted at it.

Source

pub fn list_identities(&self) -> Result<Vec<Name>, PibError>

List all identities in the PIB, in insertion order.

Source

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.

Source

pub fn get_default_identity(&self) -> Result<Option<Name>, PibError>

Return the current default identity, if one is set.

Source

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).

Source

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.

Source

pub fn delete_key(&self, key_name: &Name) -> Result<(), PibError>

Delete a key and (via cascade) all certificates issued under it.

Source

pub fn list_keys(&self, identity: &Name) -> Result<Vec<Name>, PibError>

List all keys under identity, in insertion order.

Source

pub fn set_default_key(&self, key_name: &Name) -> Result<(), PibError>

Mark key_name as the default key for its parent identity.

Source

pub fn get_default_key(&self, identity: &Name) -> Result<Option<Name>, PibError>

Return the default key for identity, if one is set.

Source

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).

Source

pub fn get_certificate( &self, cert_name: &Name, ) -> Result<Option<Vec<u8>>, PibError>

Return the full Data-wire bytes of cert_name, if present.

Source

pub fn delete_certificate(&self, cert_name: &Name) -> Result<(), PibError>

Delete a certificate by name.

Source

pub fn list_certificates(&self, key_name: &Name) -> Result<Vec<Name>, PibError>

List all certificate names issued under key_name.

Source

pub fn set_default_certificate(&self, cert_name: &Name) -> Result<(), PibError>

Mark cert_name as the default cert for its parent key.

Source

pub fn get_default_certificate( &self, key_name: &Name, ) -> Result<Option<Vec<u8>>, PibError>

Return the default certificate Data-wire for key_name, if any.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V