SqliteKeyStore is the identities table as a KeyStore: every kind (TeamSpeak, a Voelin key, the account record, an unknown kind that passes through) with the account binding of the columns that ADD_ACCOUNT_COLUMNS added. It owns a Store behind a mutex, because a KeyStore is Sync and a connection is not; with_store runs the TeamSpeak methods on the same connection. The trait's provided methods (bound_to, account_record, put_account_record, sign_out) are used as they are. - put is one upsert; a replaced row keeps its name, origin, default flag and creation time, and a blob without a binding unbinds the row. The uid is UNIQUE across kinds, so a uid another kind holds is a backend error that replaces nothing; get and remove are addressed by kind and uid. - The TeamSpeak level stays computed from the key and counter, as before; the level of a blob that is put is not stored. A TeamSpeak row whose JSON was damaged outside this crate lists and reads with level 0. - A TeamSpeak blob is stored only if its JSON is a tsproto identity and its key has the uid the blob names. Without the first one bad row breaks the list of TeamSpeak identities; without the second a blob could replace, by its uid, the key of a different identity. Tests copy the exercise() cases of voelin-identity's tests/storage.rs into the client (with the two deviations of a SQLite store, marked), round-trip bound and synced entries through the table and a reopen with their raw columns, and load a client.db migrated from schema versions 5 and 6 through the key store: kind teamspeak, no binding, JSON byte for byte, origin and default flag kept. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
51 lines
1.8 KiB
Rust
51 lines
1.8 KiB
Rust
//! Local persistence for the client.
|
|
//!
|
|
//! One SQLite database holds identities, bookmarks, settings, contacts
|
|
//! ([`contacts`]) and the chat history ([`chat`]). Passwords and query
|
|
//! credentials never go into the database; they live in a [`Secrets`] store
|
|
//! (the OS keyring with the `keyring` feature).
|
|
//!
|
|
//! The schema is versioned (`PRAGMA user_version`): opening a database runs
|
|
//! the migrations it has not seen, each in one transaction, keeping the data.
|
|
//!
|
|
//! The `identities` table keeps identities of more than one kind. [`Store`]
|
|
//! has the TeamSpeak identities the client has always had; [`SqliteKeyStore`]
|
|
//! is the table as a `voelin_identity::KeyStore`: every kind (TeamSpeak, a
|
|
//! Voelin key, the record of the signed-in account), each with the binding that
|
|
//! says whether it belongs to an account, and the sign-out of that account.
|
|
|
|
pub mod chat;
|
|
pub mod contacts;
|
|
mod keystore;
|
|
mod secrets;
|
|
mod store;
|
|
|
|
pub use chat::{
|
|
ChatCursor, ChatRead, ChatTarget, MessageSource, NewMessage, PageQuery, Reaction, RemoteInfo,
|
|
StoredMessage, SyncState, WriteOutcome, Written,
|
|
};
|
|
pub use contacts::{Contact, ContactSeen, Relation};
|
|
pub use keystore::SqliteKeyStore;
|
|
#[cfg(feature = "keyring")]
|
|
pub use secrets::KeyringSecrets;
|
|
pub use secrets::{MemorySecrets, Secrets};
|
|
pub use store::{
|
|
Bookmark, CachedServerIcon, IdentityEntry, IdentityOrigin, QueryConfig, QueryTransport, Store,
|
|
};
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
#[error("database: {0}")]
|
|
Db(#[from] rusqlite::Error),
|
|
#[error("serialization: {0}")]
|
|
Json(#[from] serde_json::Error),
|
|
#[error("{0} {1} not found")]
|
|
NotFound(&'static str, i64),
|
|
#[error("secret store: {0}")]
|
|
Secrets(String),
|
|
#[error("io: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
}
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|