diff --git a/bindings/javascript/src/lib.rs b/bindings/javascript/src/lib.rs index 711c00b8a..40097eff5 100644 --- a/bindings/javascript/src/lib.rs +++ b/bindings/javascript/src/lib.rs @@ -569,7 +569,7 @@ impl turso_core::DatabaseStorage for DatabaseFile { fn read_page( &self, page_idx: usize, - _encryption_ctx: Option<&turso_core::PerConnEncryptionContext>, + _encryption_ctx: Option<&turso_core::EncryptionContext>, c: turso_core::Completion, ) -> turso_core::Result { let r = c.as_read(); @@ -586,7 +586,7 @@ impl turso_core::DatabaseStorage for DatabaseFile { &self, page_idx: usize, buffer: Arc, - _encryption_ctx: Option<&turso_core::PerConnEncryptionContext>, + _encryption_ctx: Option<&turso_core::EncryptionContext>, c: turso_core::Completion, ) -> turso_core::Result { let size = buffer.len(); @@ -599,7 +599,7 @@ impl turso_core::DatabaseStorage for DatabaseFile { first_page_idx: usize, page_size: usize, buffers: Vec>, - _encryption_ctx: Option<&turso_core::PerConnEncryptionContext>, + _encryption_ctx: Option<&turso_core::EncryptionContext>, c: turso_core::Completion, ) -> turso_core::Result { let pos = first_page_idx.saturating_sub(1) * page_size; diff --git a/core/lib.rs b/core/lib.rs index 8ef042dc1..5ba3a4faa 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -75,7 +75,7 @@ use std::{ }; #[cfg(feature = "fs")] use storage::database::DatabaseFile; -pub use storage::encryption::{EncryptionKey, PerConnEncryptionContext}; +pub use storage::encryption::{EncryptionKey, EncryptionContext}; use storage::page_cache::DumbLruPageCache; use storage::pager::{AtomicDbState, DbState}; use storage::sqlite3_ondisk::PageSize; diff --git a/core/storage/database.rs b/core/storage/database.rs index e2b27b302..d608558fc 100644 --- a/core/storage/database.rs +++ b/core/storage/database.rs @@ -1,5 +1,5 @@ use crate::error::LimboError; -use crate::storage::encryption::PerConnEncryptionContext; +use crate::storage::encryption::EncryptionContext; use crate::{io::Completion, Buffer, CompletionError, Result}; use std::sync::Arc; use tracing::{instrument, Level}; @@ -15,14 +15,14 @@ pub trait DatabaseStorage: Send + Sync { fn read_page( &self, page_idx: usize, - encryption_ctx: Option<&PerConnEncryptionContext>, + encryption_ctx: Option<&EncryptionContext>, c: Completion, ) -> Result; fn write_page( &self, page_idx: usize, buffer: Arc, - encryption_ctx: Option<&PerConnEncryptionContext>, + encryption_ctx: Option<&EncryptionContext>, c: Completion, ) -> Result; fn write_pages( @@ -30,7 +30,7 @@ pub trait DatabaseStorage: Send + Sync { first_page_idx: usize, page_size: usize, buffers: Vec>, - encryption_ctx: Option<&PerConnEncryptionContext>, + encryption_ctx: Option<&EncryptionContext>, c: Completion, ) -> Result; fn sync(&self, c: Completion) -> Result; @@ -59,7 +59,7 @@ impl DatabaseStorage for DatabaseFile { fn read_page( &self, page_idx: usize, - encryption_ctx: Option<&PerConnEncryptionContext>, + encryption_ctx: Option<&EncryptionContext>, c: Completion, ) -> Result { let r = c.as_read(); @@ -111,7 +111,7 @@ impl DatabaseStorage for DatabaseFile { &self, page_idx: usize, buffer: Arc, - encryption_ctx: Option<&PerConnEncryptionContext>, + encryption_ctx: Option<&EncryptionContext>, c: Completion, ) -> Result { let buffer_size = buffer.len(); @@ -135,7 +135,7 @@ impl DatabaseStorage for DatabaseFile { first_page_idx: usize, page_size: usize, buffers: Vec>, - encryption_key: Option<&PerConnEncryptionContext>, + encryption_key: Option<&EncryptionContext>, c: Completion, ) -> Result { assert!(first_page_idx > 0); @@ -187,7 +187,7 @@ impl DatabaseFile { fn encrypt_buffer( page_idx: usize, buffer: Arc, - ctx: &PerConnEncryptionContext, + ctx: &EncryptionContext, ) -> Arc { let encrypted_data = ctx.encrypt_page(buffer.as_slice(), page_idx).unwrap(); Arc::new(Buffer::new(encrypted_data.to_vec())) diff --git a/core/storage/encryption.rs b/core/storage/encryption.rs index 8c8f7bd44..97836d3d1 100644 --- a/core/storage/encryption.rs +++ b/core/storage/encryption.rs @@ -113,12 +113,12 @@ impl std::fmt::Debug for Cipher { } #[derive(Clone)] -pub struct PerConnEncryptionContext { +pub struct EncryptionContext { cipher_mode: CipherMode, cipher: Cipher, } -impl PerConnEncryptionContext { +impl EncryptionContext { pub fn new(key: &EncryptionKey) -> Result { let cipher_mode = CipherMode::Aes256Gcm; let required_size = cipher_mode.required_key_size(); @@ -281,7 +281,7 @@ mod tests { }; let key = EncryptionKey::from_string("alice and bob use encryption on database"); - let ctx = PerConnEncryptionContext::new(&key).unwrap(); + let ctx = EncryptionContext::new(&key).unwrap(); let page_id = 42; let encrypted = ctx.encrypt_page(&page_data, page_id).unwrap(); diff --git a/core/storage/pager.rs b/core/storage/pager.rs index ca9f32cf9..4512b93c7 100644 --- a/core/storage/pager.rs +++ b/core/storage/pager.rs @@ -29,7 +29,7 @@ use super::page_cache::{CacheError, CacheResizeResult, DumbLruPageCache, PageCac use super::sqlite3_ondisk::begin_write_btree_page; use super::wal::CheckpointMode; use crate::storage::encryption::{ - EncryptionKey, PerConnEncryptionContext, ENCRYPTION_METADATA_SIZE, + EncryptionKey, EncryptionContext, ENCRYPTION_METADATA_SIZE, }; /// SQLite's default maximum page count @@ -493,7 +493,7 @@ pub struct Pager { header_ref_state: RefCell, #[cfg(not(feature = "omit_autovacuum"))] btree_create_vacuum_full_state: Cell, - pub(crate) encryption_ctx: RefCell>, + pub(crate) encryption_ctx: RefCell>, } #[derive(Debug, Clone)] @@ -1137,7 +1137,7 @@ impl Pager { page_idx: usize, page: PageRef, allow_empty_read: bool, - encryption_key: Option<&PerConnEncryptionContext>, + encryption_key: Option<&EncryptionContext>, ) -> Result { sqlite3_ondisk::begin_read_page( self.db_file.clone(), @@ -2112,7 +2112,7 @@ impl Pager { } pub fn set_encryption_context(&self, key: &EncryptionKey) { - let encryption_ctx = PerConnEncryptionContext::new(key).unwrap(); + let encryption_ctx = EncryptionContext::new(key).unwrap(); self.encryption_ctx.replace(Some(encryption_ctx.clone())); let Some(wal) = self.wal.as_ref() else { return }; wal.borrow_mut().set_encryption_context(encryption_ctx) diff --git a/core/storage/sqlite3_ondisk.rs b/core/storage/sqlite3_ondisk.rs index d1a37615d..8ec4c861f 100644 --- a/core/storage/sqlite3_ondisk.rs +++ b/core/storage/sqlite3_ondisk.rs @@ -59,7 +59,7 @@ use crate::storage::btree::offset::{ use crate::storage::btree::{payload_overflow_threshold_max, payload_overflow_threshold_min}; use crate::storage::buffer_pool::BufferPool; use crate::storage::database::DatabaseStorage; -use crate::storage::encryption::PerConnEncryptionContext; +use crate::storage::encryption::EncryptionContext; use crate::storage::pager::Pager; use crate::storage::wal::READMARK_NOT_USED; use crate::types::{RawSlice, RefValue, SerialType, SerialTypeKind, TextRef, TextSubtype}; @@ -870,7 +870,7 @@ pub fn begin_read_page( page: PageRef, page_idx: usize, allow_empty_read: bool, - encryption_key: Option<&PerConnEncryptionContext>, + encryption_key: Option<&EncryptionContext>, ) -> Result { tracing::trace!("begin_read_btree_page(page_idx = {})", page_idx); let buf = buffer_pool.get_page(); @@ -965,7 +965,7 @@ pub fn write_pages_vectored( pager: &Pager, batch: BTreeMap>, done_flag: Arc, - encryption_key: Option<&PerConnEncryptionContext>, + encryption_key: Option<&EncryptionContext>, ) -> Result> { if batch.is_empty() { done_flag.store(true, Ordering::Relaxed); diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 0a903f4b3..3b07d80f8 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -17,7 +17,7 @@ use super::sqlite3_ondisk::{self, checksum_wal, WalHeader, WAL_MAGIC_BE, WAL_MAG use crate::fast_lock::SpinLock; use crate::io::{clock, File, IO}; use crate::result::LimboResult; -use crate::storage::encryption::PerConnEncryptionContext; +use crate::storage::encryption::EncryptionContext; use crate::storage::sqlite3_ondisk::{ begin_read_wal_frame, begin_read_wal_frame_raw, finish_read_page, prepare_wal_frame, write_pages_vectored, PageSize, WAL_FRAME_HEADER_SIZE, WAL_HEADER_SIZE, @@ -297,7 +297,7 @@ pub trait Wal: Debug { /// Return unique set of pages changed **after** frame_watermark position and until current WAL session max_frame_no fn changed_pages_after(&self, frame_watermark: u64) -> Result>; - fn set_encryption_context(&mut self, ctx: PerConnEncryptionContext); + fn set_encryption_context(&mut self, ctx: EncryptionContext); #[cfg(debug_assertions)] fn as_any(&self) -> &dyn std::any::Any; @@ -568,7 +568,7 @@ pub struct WalFile { /// Manages locks needed for checkpointing checkpoint_guard: Option, - encryption_ctx: RefCell>, + encryption_ctx: RefCell>, } impl fmt::Debug for WalFile { @@ -1374,7 +1374,7 @@ impl Wal for WalFile { self } - fn set_encryption_context(&mut self, ctx: PerConnEncryptionContext) { + fn set_encryption_context(&mut self, ctx: EncryptionContext) { self.encryption_ctx.replace(Some(ctx)); } }