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