pub struct Database { /* private fields */ }Implementations§
Source§impl Database
impl Database
pub async fn child_groups( &self, entity: PersistedMlsGroup, ) -> CryptoKeystoreResult<Vec<PersistedMlsGroup>>
pub async fn find_pending_messages_by_conversation_id( &self, conversation_id: &[u8], ) -> CryptoKeystoreResult<Vec<MlsPendingMessage>>
pub async fn remove_pending_messages_by_conversation_id( &self, conversation_id: impl AsRef<[u8]> + Send, ) -> CryptoKeystoreResult<()>
Source§impl Database
These impls control the keystore transaction lifecycle.
impl Database
These impls control the keystore transaction lifecycle.
Sourcepub async fn new_transaction(&self) -> CryptoKeystoreResult<()>
pub async fn new_transaction(&self) -> CryptoKeystoreResult<()>
Waits for the current transaction to be committed or rolled back, then starts a new one.
Sourcepub async fn try_new_immediate_transaction(&self) -> CryptoKeystoreResult<()>
pub async fn try_new_immediate_transaction(&self) -> CryptoKeystoreResult<()>
Start a new transaction if no other transaction is currently in progress.
If a transaction is currently in progress, this will produce a TransactionInProgress error.
pub async fn commit_transaction(&self) -> CryptoKeystoreResult<()>
pub async fn rollback_transaction(&self) -> CryptoKeystoreResult<()>
Sourcepub async fn transactionally<R>(
&self,
operation: impl AsyncFnOnce(&KeystoreTransaction) -> CryptoKeystoreResult<R>,
) -> CryptoKeystoreResult<R>
pub async fn transactionally<R>( &self, operation: impl AsyncFnOnce(&KeystoreTransaction) -> CryptoKeystoreResult<R>, ) -> CryptoKeystoreResult<R>
Do an operation on a keystore transaction on this database.
This is a convenience method abstracting over Self::new_transaction,
Self::commit_transaction, and Self::rollback_transaction.
If the operation succeeds, the transaction is committed. Otherwise, it is rolled back.
Source§impl Database
These impls are convenience methods to modify the keystore transaction.
impl Database
These impls are convenience methods to modify the keystore transaction.
Be aware that we are likely to remove these in the future: WPB-23951
pub async fn save<E>( &self, entity: E, ) -> CryptoKeystoreResult<E::AutoGeneratedFields>
pub async fn remove<E>(&self, id: &E::PrimaryKey) -> CryptoKeystoreResult<()>where
E: Entity + EntityDatabaseMutation,
pub async fn remove_borrowed<E>( &self, id: &E::BorrowedPrimaryKey, ) -> CryptoKeystoreResult<()>
Sourcepub async fn restore<E>(
&self,
id: &E::BorrowedPrimaryKey,
) -> CryptoKeystoreResult<()>
pub async fn restore<E>( &self, id: &E::BorrowedPrimaryKey, ) -> CryptoKeystoreResult<()>
Restore an entity that was deleted in this transaction by removing it from the deleted list. This is idempotent: if the entity doesn’t exist in the deleted list, do nothing.
NOTE: This will only work if the entity has been added in an earlier transaction, because otherwise, removing its id from the deleted list wouldn’t suffice: we’d need to replay its insertion.
Source§impl Database
impl Database
Sourcepub async fn open(
path: &str,
database_key: &DatabaseKey,
) -> CryptoKeystoreResult<Arc<Self>>
pub async fn open( path: &str, database_key: &DatabaseKey, ) -> CryptoKeystoreResult<Arc<Self>>
Open an encrypted Database at the provided location.
When compiled with target_os = "unknown", this opens a database encrypted via
sqlite3-multiple-ciphers using its default encryption mechanism, stored in IndexedDB
via the relaxed-idb shim.
When compiled normally, this opens a database encrypted via sqlcipher at a path in the local filesystem.
Sourcepub fn open_in_memory() -> CryptoKeystoreResult<Arc<Self>>
pub fn open_in_memory() -> CryptoKeystoreResult<Arc<Self>>
Open an in-memory Database.
In-memory databases are never encrypted.
Sourcepub async fn update_key(
&self,
new_key: &DatabaseKey,
) -> CryptoKeystoreResult<()>
pub async fn update_key( &self, new_key: &DatabaseKey, ) -> CryptoKeystoreResult<()>
Change the encryption key for this database.
pub async fn close(self) -> CryptoKeystoreResult<()>
Sourcepub async fn wipe(self) -> CryptoKeystoreResult<()>
pub async fn wipe(self) -> CryptoKeystoreResult<()>
Close and remove this database.
This deletes the database, including its encryption key. Future opens will always succeed with any arbitrary encryption key; they will simply open an empty database.
Sourcepub async fn location(&self) -> Option<String>
pub async fn location(&self) -> Option<String>
Get the location of the database.
Returns None if the database is in-memory.
Sourcepub async fn export_copy(
&self,
destination_path: &str,
) -> CryptoKeystoreResult<()>
pub async fn export_copy( &self, destination_path: &str, ) -> CryptoKeystoreResult<()>
Export a copy of the database to the specified path using VACUUM INTO.
This creates a fully vacuumed and optimized copy of the database. The copy will be encrypted with the same key as the source database.
§Arguments
destination_path- The file path where the database copy should be created
Source§impl Database
impl Database
Sourcepub async fn mls_fetch_key_packages<V: MlsEntity>(
&self,
count: u32,
) -> CryptoKeystoreResult<Vec<V>>
pub async fn mls_fetch_key_packages<V: MlsEntity>( &self, count: u32, ) -> CryptoKeystoreResult<Vec<V>>
Sourcepub async fn mls_group_exists(&self, group_id: impl AsRef<[u8]> + Send) -> bool
pub async fn mls_group_exists(&self, group_id: impl AsRef<[u8]> + Send) -> bool
Checks if the given MLS group id exists in the keystore Note: in case of any error, this will return false
§Arguments
group_id- group/conversation id
Sourcepub async fn mls_group_persist(
&self,
group_id: impl AsRef<[u8]> + Send,
state: &[u8],
parent_group_id: Option<&[u8]>,
) -> CryptoKeystoreResult<()>
pub async fn mls_group_persist( &self, group_id: impl AsRef<[u8]> + Send, state: &[u8], parent_group_id: Option<&[u8]>, ) -> CryptoKeystoreResult<()>
Sourcepub async fn mls_groups_restore(
&self,
) -> CryptoKeystoreResult<HashMap<Vec<u8>, (Option<Vec<u8>>, Vec<u8>)>>
pub async fn mls_groups_restore( &self, ) -> CryptoKeystoreResult<HashMap<Vec<u8>, (Option<Vec<u8>>, Vec<u8>)>>
Loads MlsGroups from the database. It will be returned as a HashMap where the key is
the group/conversation id and the value the group state
§Errors
Any common error that can happen during a database connection. IoError being a common error for example.
Sourcepub async fn mls_group_delete(
&self,
group_id: impl AsRef<[u8]> + Send,
) -> CryptoKeystoreResult<()>
pub async fn mls_group_delete( &self, group_id: impl AsRef<[u8]> + Send, ) -> CryptoKeystoreResult<()>
Deletes MlsGroups from the database.
§Errors
Any common error that can happen during a database connection. IoError being a common error for example.
Sourcepub async fn mls_pending_groups_save(
&self,
group_id: impl AsRef<[u8]> + Send,
mls_group: &[u8],
custom_configuration: &[u8],
parent_group_id: Option<&[u8]>,
) -> CryptoKeystoreResult<()>
pub async fn mls_pending_groups_save( &self, group_id: impl AsRef<[u8]> + Send, mls_group: &[u8], custom_configuration: &[u8], parent_group_id: Option<&[u8]>, ) -> CryptoKeystoreResult<()>
Saves a MlsGroup in a temporary table (typically used in scenarios where the group cannot
be committed until the backend acknowledges it, like external commits)
§Arguments
group_id- group/conversation idmls_group- the group/conversation statecustom_configuration- local group configuration
§Errors
Any common error that can happen during a database connection. IoError being a common error for example.
Sourcepub async fn mls_pending_groups_load(
&self,
group_id: impl AsRef<[u8]> + Send,
) -> CryptoKeystoreResult<Option<(Vec<u8>, Vec<u8>)>>
pub async fn mls_pending_groups_load( &self, group_id: impl AsRef<[u8]> + Send, ) -> CryptoKeystoreResult<Option<(Vec<u8>, Vec<u8>)>>
Sourcepub async fn mls_pending_groups_delete(
&self,
group_id: impl AsRef<[u8]> + Send,
) -> CryptoKeystoreResult<()>
pub async fn mls_pending_groups_delete( &self, group_id: impl AsRef<[u8]> + Send, ) -> CryptoKeystoreResult<()>
Sourcepub async fn save_e2ei_enrollment(
&self,
id: &[u8],
content: &[u8],
) -> CryptoKeystoreResult<()>
pub async fn save_e2ei_enrollment( &self, id: &[u8], content: &[u8], ) -> CryptoKeystoreResult<()>
Persists an enrollment instance
§Arguments
id- hash of the enrollment and unique identifiercontent- serialized enrollment
Sourcepub async fn pop_e2ei_enrollment(
&self,
id: &[u8],
) -> CryptoKeystoreResult<Option<Vec<u8>>>
pub async fn pop_e2ei_enrollment( &self, id: &[u8], ) -> CryptoKeystoreResult<Option<Vec<u8>>>
Fetches and delete the enrollment instance
§Arguments
id- hash of the enrollment and unique identifier
Source§impl Database
impl Database
pub async fn proteus_store_prekey( &self, id: u16, prekey: &[u8], ) -> CryptoKeystoreResult<()>
Trait Implementations§
Source§impl FetchFromDatabase for Database
impl FetchFromDatabase for Database
Source§fn get<'life0, 'life1, 'async_trait, E>(
&'life0 self,
id: &'life1 E::PrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>
fn get<'life0, 'life1, 'async_trait, E>( &'life0 self, id: &'life1 E::PrimaryKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>
E from the database by its primary key.Source§fn get_borrowed<'life0, 'life1, 'async_trait, E>(
&'life0 self,
id: &'life1 <E as BorrowPrimaryKey>::BorrowedPrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>where
E: 'static + EntityGetBorrowed + Clone + Send + Sync + 'async_trait,
E::PrimaryKey: Borrow<E::BorrowedPrimaryKey>,
for<'a> &'a E::BorrowedPrimaryKey: KeyType,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_borrowed<'life0, 'life1, 'async_trait, E>(
&'life0 self,
id: &'life1 <E as BorrowPrimaryKey>::BorrowedPrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<E>>> + Send + 'async_trait>>where
E: 'static + EntityGetBorrowed + Clone + Send + Sync + 'async_trait,
E::PrimaryKey: Borrow<E::BorrowedPrimaryKey>,
for<'a> &'a E::BorrowedPrimaryKey: KeyType,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
E from the database by the borrowed form of its primary key.Source§fn count<'life0, 'async_trait, E>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>
fn count<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>
Es in the database.Source§fn load_all<'life0, 'async_trait, E>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<E>>> + Send + 'async_trait>>
fn load_all<'life0, 'async_trait, E>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<E>>> + Send + 'async_trait>>
Es from the database.Source§fn search<'life0, 'life1, 'async_trait, E, SearchKey>(
&'life0 self,
search_key: &'life1 SearchKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<E>>> + Send + 'async_trait>>
fn search<'life0, 'life1, 'async_trait, E, SearchKey>( &'life0 self, search_key: &'life1 SearchKey, ) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<E>>> + Send + 'async_trait>>
E given a search key.Source§fn get_unique<'a, 'life0, 'async_trait, U>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<U>>> + Send + 'async_trait>>where
U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn get_unique<'a, 'life0, 'async_trait, U>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<U>>> + Send + 'async_trait>>where
U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Source§fn exists<'a, 'life0, 'async_trait, U>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<bool>> + Send + 'async_trait>>where
U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn exists<'a, 'life0, 'async_trait, U>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<bool>> + Send + 'async_trait>>where
U: 'static + UniqueEntityExt + Entity + Clone + Send + Sync + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Source§impl OpenMlsKeyStore for Database
impl OpenMlsKeyStore for Database
Source§type Error = CryptoKeystoreError
type Error = CryptoKeystoreError
OpenMlsKeyStore].Source§fn store<'life0, 'life1, 'life2, 'async_trait, V>(
&'life0 self,
id: &'life1 [u8],
value: &'life2 V,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
fn store<'life0, 'life1, 'life2, 'async_trait, V>( &'life0 self, id: &'life1 [u8], value: &'life2 V, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
Source§fn read<'life0, 'life1, 'async_trait, V>(
&'life0 self,
id: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Option<V>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
V: 'async_trait + MlsEntity,
'life0: 'async_trait,
'life1: 'async_trait,
fn read<'life0, 'life1, 'async_trait, V>(
&'life0 self,
id: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Option<V>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
V: 'async_trait + MlsEntity,
'life0: 'async_trait,
'life1: 'async_trait,
k that implements the
[MlsEntity] trait for deserialization. Read moreSource§fn delete<'life0, 'life1, 'async_trait, V>(
&'life0 self,
id: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
V: 'async_trait + MlsEntity,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait, V>(
&'life0 self,
id: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
V: 'async_trait + MlsEntity,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
k. Read moreSource§impl PreKeyStore for Database
impl PreKeyStore for Database
Auto Trait Implementations§
impl !Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more