From 810dcc28e951d1eda73d4fc25d55a7a5c5a4d28a Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Wed, 28 Jan 2026 16:56:35 +0800 Subject: [PATCH] chore: remove feature gates --- double-ratchets/Cargo.toml | 3 +- double-ratchets/examples/out_of_order_demo.rs | 12 +++--- double-ratchets/examples/storage_demo.rs | 42 +++++++++---------- storage/Cargo.toml | 7 +--- storage/src/error.rs | 1 - storage/src/lib.rs | 16 ++----- storage/src/sqlite.rs | 4 +- 7 files changed, 34 insertions(+), 51 deletions(-) diff --git a/double-ratchets/Cargo.toml b/double-ratchets/Cargo.toml index 6d28b1b..c46fab4 100644 --- a/double-ratchets/Cargo.toml +++ b/double-ratchets/Cargo.toml @@ -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"] diff --git a/double-ratchets/examples/out_of_order_demo.rs b/double-ratchets/examples/out_of_order_demo.rs index 7217f21..ad882d0 100644 --- a/double-ratchets/examples/out_of_order_demo.rs +++ b/double-ratchets/examples/out_of_order_demo.rs @@ -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"); diff --git a/double-ratchets/examples/storage_demo.rs b/double-ratchets/examples/storage_demo.rs index ef6e7c1..cc2d692 100644 --- a/double-ratchets/examples/storage_demo.rs +++ b/double-ratchets/examples/storage_demo.rs @@ -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"; diff --git a/storage/Cargo.toml b/storage/Cargo.toml index aecff59..40d11d6 100644 --- a/storage/Cargo.toml +++ b/storage/Cargo.toml @@ -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"] } diff --git a/storage/src/error.rs b/storage/src/error.rs index 6e68cf4..1410f85 100644 --- a/storage/src/error.rs +++ b/storage/src/error.rs @@ -28,7 +28,6 @@ pub enum StorageError { Transaction(String), } -#[cfg(feature = "sqlite")] impl From for StorageError { fn from(e: rusqlite::Error) -> Self { StorageError::Database(e.to_string()) diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 6c5e612..bdf30f5 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -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; } @@ -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>; } diff --git a/storage/src/sqlite.rs b/storage/src/sqlite.rs index 7ee22fb..4b0c225 100644 --- a/storage/src/sqlite.rs +++ b/storage/src/sqlite.rs @@ -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)?;