Merge 'Prevent setting of encryption keys if already set' from Gaurav Sarma

Fixes https://github.com/tursodatabase/turso/issues/2883
<img width="867" height="128" alt="Screenshot 2025-09-05 at 10 44 18 PM"
src="https://github.com/user-attachments/assets/54a659ba-
cfe1-4622-939b-c7c31362ee5a" />

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>
Reviewed-by: Avinash Sajjanshetty (@avinassh)

Closes #2914
This commit is contained in:
Jussi Saurio
2025-09-08 09:49:55 +03:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -2060,6 +2060,11 @@ impl Connection {
};
tracing::trace!("setting encryption ctx for connection");
let pager = self.pager.borrow();
if pager.is_encryption_ctx_set() {
return Err(LimboError::InvalidArgument(
"cannot reset encryption attributes if already set in the session".to_string(),
));
}
pager.set_encryption_context(cipher_mode, key)
}
}

View File

@@ -2163,6 +2163,10 @@ impl Pager {
Ok(IOResult::Done(f(header)))
}
pub fn is_encryption_ctx_set(&self) -> bool {
self.io_ctx.borrow_mut().encryption_context().is_some()
}
pub fn set_encryption_context(
&self,
cipher_mode: CipherMode,