From 1309fd4dabfb7ebfad3fb07f09d28e1db57c1a4c Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 18 Oct 2024 15:04:24 -0700 Subject: [PATCH] Different initialization pattern --- src/lib.rs | 14 ++++++-------- src/sqlcipher.rs | 5 ----- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8ba5889..6def862 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -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::() as u64) as *mut SqlCipherProvider; provider.write(SqlCipherProvider { activate, deactivate, @@ -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 } diff --git a/src/sqlcipher.rs b/src/sqlcipher.rs index 6f330a4..a6dee67 100644 --- a/src/sqlcipher.rs +++ b/src/sqlcipher.rs @@ -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; -}