//! 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::{FallbackSecrets, KeyringSecrets}; pub use secrets::{MemorySecrets, Secrets}; pub use store::{ Bookmark, CachedServerIcon, IdentityEntry, IdentityOrigin, QueryConfig, QueryTransport, Store, }; /// How the JSON of a stored TeamSpeak identity is wrong: the category of the /// reader's complaint and nothing of the text, which holds a private key. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum IdentityDamage { /// The text is not JSON. Malformed, /// The text ends before the JSON does. CutShort, /// The JSON is not that of an identity: a field is missing or of another /// type, or the key does not import. NotAnIdentity, /// The text could not be read. Unreadable, } impl std::fmt::Display for IdentityDamage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Self::Malformed => "malformed", Self::CutShort => "cut short", Self::NotAnIdentity => "not an identity", Self::Unreadable => "unreadable", }) } } #[derive(Debug, thiserror::Error)] pub enum Error { #[error("database: {0}")] Db(#[from] rusqlite::Error), #[error("serialization: {0}")] Json(#[from] serde_json::Error), /// The JSON of a stored TeamSpeak identity cannot be read, which only damage /// outside the client can cause. It says how the text is wrong and where, and /// never what it holds: the text is a private key, and the message of the /// JSON reader quotes the value it refuses (`tsproto` reports a key that does /// not import as an invalid value, the key string and all), so that message is /// not kept, not here and not in a log line. #[error( "the stored TeamSpeak identity cannot be read: {damage} at line {line}, column {column}" )] Identity { damage: IdentityDamage, line: usize, column: usize }, #[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 = std::result::Result;