mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 08:53:08 +00:00
chore: remove feature gates
This commit is contained in:
parent
28a965dff4
commit
810dcc28e9
@ -20,10 +20,9 @@ thiserror = "2"
|
||||
blake2 = "0.10.6"
|
||||
safer-ffi = "0.1.13"
|
||||
zeroize = "1.8.2"
|
||||
storage = { workspace = true, optional = true, features = ["sqlite"] }
|
||||
storage = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
persist = ["storage"]
|
||||
sqlcipher = ["persist", "storage/sqlcipher"]
|
||||
headers = ["safer-ffi/headers"]
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
//! Demonstrates out-of-order message handling with skipped keys persistence.
|
||||
//!
|
||||
//! Run with: cargo run --example out_of_order_demo --features storage
|
||||
//! Run with: cargo run --example out_of_order_demo --features persist
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
use double_ratchets::{
|
||||
InstallationKeyPair, RatchetState, RatchetStorage, StorageConfig, hkdf::DefaultDomain,
|
||||
state::Header,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
println!("=== Out-of-Order Message Handling Demo (skipped - enable 'storage' feature) ===\n");
|
||||
println!("=== Out-of-Order Message Handling Demo ===\n");
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
run_demo();
|
||||
#[cfg(not(feature = "persist"))]
|
||||
println!("(skipped - enable 'persist' feature)");
|
||||
}
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn run_demo() {
|
||||
let mut storage =
|
||||
RatchetStorage::with_config(StorageConfig::InMemory).expect("Failed to create storage");
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
//! Demonstrates SQLite storage for Double Ratchet state persistence.
|
||||
//!
|
||||
//! Run with: cargo run --example storage_demo --features storage
|
||||
//! For SQLCipher: cargo run --example storage_demo --features sqlcipher
|
||||
//! Run with: cargo run --example storage_demo --features persist
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
use double_ratchets::{
|
||||
InstallationKeyPair, RatchetSession, RatchetStorage, StorageConfig, hkdf::PrivateV1Domain,
|
||||
};
|
||||
@ -12,29 +11,28 @@ fn main() {
|
||||
println!("=== Double Ratchet Storage Demo ===\n");
|
||||
|
||||
// Demo 1: In-memory storage (for testing)
|
||||
println!("--- Demo 1: In-Memory Storage (skipped - enable 'storage' feature) ---");
|
||||
#[cfg(feature = "storage")]
|
||||
println!("--- Demo 1: In-Memory Storage ---");
|
||||
#[cfg(feature = "persist")]
|
||||
demo_in_memory();
|
||||
#[cfg(not(feature = "persist"))]
|
||||
println!(" (skipped - enable 'persist' feature)");
|
||||
|
||||
// Demo 2: File-based storage (for local development)
|
||||
println!("\n--- Demo 2: File-Based Storage (skipped - enable 'storage' feature) ---");
|
||||
#[cfg(feature = "storage")]
|
||||
println!("\n--- Demo 2: File-Based Storage ---");
|
||||
#[cfg(feature = "persist")]
|
||||
demo_file_storage();
|
||||
#[cfg(not(feature = "persist"))]
|
||||
println!(" (skipped - enable 'persist' feature)");
|
||||
|
||||
// Demo 3: SQLCipher encrypted storage (for production)
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
{
|
||||
println!("\n--- Demo 3: SQLCipher Encrypted Storage ---");
|
||||
demo_sqlcipher();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "sqlcipher"))]
|
||||
{
|
||||
println!("\n--- Demo 3: SQLCipher (skipped - enable 'sqlcipher' feature) ---");
|
||||
}
|
||||
println!("\n--- Demo 3: SQLCipher Encrypted Storage ---");
|
||||
#[cfg(feature = "persist")]
|
||||
demo_sqlcipher();
|
||||
#[cfg(not(feature = "persist"))]
|
||||
println!(" (skipped - enable 'persist' feature)");
|
||||
}
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn demo_in_memory() {
|
||||
let mut alice_storage =
|
||||
RatchetStorage::with_config(StorageConfig::InMemory).expect("Failed to create storage");
|
||||
@ -43,7 +41,7 @@ fn demo_in_memory() {
|
||||
run_conversation(&mut alice_storage, &mut bob_storage);
|
||||
}
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn demo_file_storage() {
|
||||
ensure_tmp_directory();
|
||||
|
||||
@ -78,7 +76,7 @@ fn demo_file_storage() {
|
||||
let _ = std::fs::remove_file(db_path_bob);
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn demo_sqlcipher() {
|
||||
ensure_tmp_directory();
|
||||
let alice_db_path = "./tmp/double_ratchet_encrypted_alice.db";
|
||||
@ -136,7 +134,7 @@ fn ensure_tmp_directory() {
|
||||
|
||||
/// Simulates a conversation between Alice and Bob.
|
||||
/// Each party saves/loads state from storage for each operation.
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn run_conversation(alice_storage: &mut RatchetStorage, bob_storage: &mut RatchetStorage) {
|
||||
// === Setup: Simulate X3DH key exchange ===
|
||||
let shared_secret = [0x42u8; 32]; // In reality, this comes from X3DH
|
||||
@ -208,7 +206,7 @@ fn run_conversation(alice_storage: &mut RatchetStorage, bob_storage: &mut Ratche
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "storage")]
|
||||
#[cfg(feature = "persist")]
|
||||
fn continue_after_restart(alice_storage: &mut RatchetStorage, bob_storage: &mut RatchetStorage) {
|
||||
// Load persisted states
|
||||
let conv_id = "conv1";
|
||||
|
||||
@ -6,9 +6,4 @@ description = "Shared storage layer for libchat"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "2"
|
||||
rusqlite = { version = "0.35", optional = true, features = ["bundled"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
sqlite = ["rusqlite"]
|
||||
sqlcipher = ["sqlite", "rusqlite/bundled-sqlcipher-vendored-openssl"]
|
||||
rusqlite = { version = "0.35", features = ["bundled-sqlcipher-vendored-openssl"] }
|
||||
|
||||
@ -28,7 +28,6 @@ pub enum StorageError {
|
||||
Transaction(String),
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl From<rusqlite::Error> for StorageError {
|
||||
fn from(e: rusqlite::Error) -> Self {
|
||||
StorageError::Database(e.to_string())
|
||||
|
||||
@ -3,24 +3,16 @@
|
||||
//! This crate provides a common storage abstraction that can be used by
|
||||
//! multiple crates in the libchat workspace (double-ratchets, conversations, etc.).
|
||||
//!
|
||||
//! # Features
|
||||
//!
|
||||
//! - `sqlite`: Enable SQLite-based storage
|
||||
//! - `sqlcipher`: Enable encrypted SQLite storage via SQLCipher
|
||||
//! Uses SQLCipher for encrypted SQLite storage.
|
||||
|
||||
mod error;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
mod sqlite;
|
||||
|
||||
pub use error::StorageError;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub use sqlite::{SqliteDb, StorageConfig};
|
||||
|
||||
// Re-export rusqlite types that domain crates will need
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub use rusqlite::{params, Transaction, Error as RusqliteError};
|
||||
pub use rusqlite::{Error as RusqliteError, Transaction, params};
|
||||
|
||||
/// Trait for types that can be stored and retrieved.
|
||||
///
|
||||
@ -28,7 +20,7 @@ pub use rusqlite::{params, Transaction, Error as RusqliteError};
|
||||
pub trait Storable: Sized {
|
||||
/// The key type used to identify records.
|
||||
type Key;
|
||||
|
||||
|
||||
/// The error type returned by storage operations.
|
||||
type Error: From<StorageError>;
|
||||
}
|
||||
@ -37,7 +29,7 @@ pub trait Storable: Sized {
|
||||
pub trait StorageBackend {
|
||||
/// Initialize the storage (e.g., create tables).
|
||||
fn init(&self) -> Result<(), StorageError>;
|
||||
|
||||
|
||||
/// Execute a batch of SQL statements (for schema migrations).
|
||||
fn execute_batch(&self, sql: &str) -> Result<(), StorageError>;
|
||||
}
|
||||
|
||||
@ -12,8 +12,7 @@ pub enum StorageConfig {
|
||||
InMemory,
|
||||
/// File-based SQLite database.
|
||||
File(String),
|
||||
/// SQLCipher encrypted database (requires `sqlcipher` feature).
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
/// SQLCipher encrypted database.
|
||||
Encrypted {
|
||||
path: String,
|
||||
key: String,
|
||||
@ -34,7 +33,6 @@ impl SqliteDb {
|
||||
let conn = match config {
|
||||
StorageConfig::InMemory => Connection::open_in_memory()?,
|
||||
StorageConfig::File(ref path) => Connection::open(path)?,
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
StorageConfig::Encrypted { ref path, ref key } => {
|
||||
let conn = Connection::open(path)?;
|
||||
conn.pragma_update(None, "key", key)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user