Skip to content

Commit

Permalink
Different initialization pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Oct 18, 2024
1 parent 701438c commit 1309fd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::sqlcipher::*;
use crate::sqlite::*;
use aes::cipher::{block_padding::NoPadding, BlockDecryptMut, BlockEncryptMut, KeyIvInit};
use core::ffi::{c_char, c_int, c_uchar, c_void};
use core::mem;
use hmac::{Hmac, Mac};
use pbkdf2::pbkdf2_hmac;
use rand_core::{OsRng, RngCore};
Expand Down Expand Up @@ -186,13 +185,12 @@ extern "C" fn cipher(
}

#[no_mangle]
pub extern "C" fn signal_register_crypto_provider() -> c_int {
pub extern "C" fn signal_crypto_provider_setup(provider: *mut SqlCipherProvider) -> c_int {
if provider.is_null() {
return SQLITE_ERROR;
}

unsafe {
// sqlcipher_register_provider expects provider to be allocated with
// `sqlcipher_malloc` because it will `sqlitecipher_free` it when the
// database is closed.
let provider =
sqlcipher_malloc(mem::size_of::<SqlCipherProvider>() as u64) as *mut SqlCipherProvider;
provider.write(SqlCipherProvider {
activate,
deactivate,
Expand All @@ -212,6 +210,6 @@ pub extern "C" fn signal_register_crypto_provider() -> c_int {
fips_status,
get_provider_version,
});
sqlcipher_register_provider(provider)
}
SQLITE_OK
}
5 changes: 0 additions & 5 deletions src/sqlcipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,3 @@ pub struct SqlCipherProvider {
pub fips_status: extern "C" fn(ctx: *mut c_void) -> c_int,
pub get_provider_version: extern "C" fn(ctx: *mut c_void) -> *const c_char,
}

extern "C" {
pub fn sqlcipher_malloc(size: u64) -> *mut c_void;
pub fn sqlcipher_register_provider(provider: *mut SqlCipherProvider) -> c_int;
}

0 comments on commit 1309fd4

Please sign in to comment.