Skip to content

Commit

Permalink
Merge branch 'kodeschreiber-encryption_v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Apr 24, 2024
2 parents 2bc3e64 + cf40be1 commit bd6595f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ keywords = ["database"]
default = ["linkage"]
bundled = ["sqlite3-sys/bundled"]
extension = []
encryption = []
linkage = ["sqlite3-sys/linkage"]

[dependencies.sqlite3-sys]
Expand Down
36 changes: 36 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,42 @@ impl Connection {
Ok(())
}

/// Set the encryption key.
#[cfg(feature = "encryption")]
#[inline]
pub fn set_encryption_key<T: AsRef<str>>(&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<T: AsRef<str>>(&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]
Expand Down

0 comments on commit bd6595f

Please sign in to comment.