diff --git a/Cargo.toml b/Cargo.toml index ffd0b83f..93408750 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ keywords = ["database"] default = ["linkage"] bundled = ["sqlite3-sys/bundled"] extension = [] +encryption = [] linkage = ["sqlite3-sys/linkage"] [dependencies.sqlite3-sys] diff --git a/src/connection.rs b/src/connection.rs index b8481a75..83e18e63 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -224,6 +224,42 @@ impl Connection { Ok(()) } + /// Set the encryption key. + #[cfg(feature = "encryption")] + #[inline] + pub fn set_encryption_key>(&self, key: T) -> Result<()> { + unsafe { + ok!( + self.raw.0, + ffi::sqlite3_key_v2( + self.raw.0, + std::ptr::null() as *const c_char, + str_to_cstr!(key.as_ref()).as_ptr() as *const c_void, + key.as_ref().len() as c_int, + ) + ); + } + Ok(()) + } + + /// Change the encryption key. + #[cfg(feature = "encryption")] + #[inline] + pub fn reset_encryption_key>(&self, new_key: T) -> Result<()> { + unsafe { + ok!( + self.raw.0, + ffi::sqlite3_rekey_v2( + self.raw.0, + std::ptr::null() as *const c_char, + str_to_cstr!(new_key.as_ref()).as_ptr() as *const c_void, + new_key.as_ref().len() as c_int, + ) + ); + } + Ok(()) + } + /// Return the number of rows inserted, updated, or deleted by the most recent INSERT, UPDATE, /// or DELETE statement. #[inline]