support cipher and encryption key URI options

This commit is contained in:
William Souza
2025-08-30 10:29:41 -03:00
parent e1b5f2d948
commit b1114734d3
2 changed files with 12 additions and 0 deletions

View File

@@ -1277,6 +1277,12 @@ impl Connection {
std::fs::set_permissions(&opts.path, perms.permissions())?;
}
let conn = db.connect()?;
if let Some(cipher) = opts.cipher {
let _ = conn.pragma_update("cipher", format!("'{cipher}'"));
}
if let Some(hexkey) = opts.hexkey {
let _ = conn.pragma_update("hexkey", format!("'{hexkey}'"));
}
Ok((io, conn))
}

View File

@@ -740,6 +740,10 @@ pub struct OpenOptions<'a> {
pub cache: CacheMode,
/// immutable=1|0 specifies that the database is stored on read-only media
pub immutable: bool,
// The encryption cipher
pub cipher: Option<String>,
// The encryption key in hex format
pub hexkey: Option<String>,
}
pub const MEMORY_PATH: &str = ":memory:";
@@ -890,6 +894,8 @@ fn parse_query_params(query: &str, opts: &mut OpenOptions) -> Result<()> {
"cache" => opts.cache = decoded_value.as_str().into(),
"immutable" => opts.immutable = decoded_value == "1",
"vfs" => opts.vfs = Some(decoded_value),
"cipher" => opts.cipher = Some(decoded_value),
"hexkey" => opts.hexkey = Some(decoded_value),
_ => {}
}
}