refactor: Migrate SQLCipher Android to new API (#4874)

Co-authored-by: Benoit Marty <benoitm@element.io>
This commit is contained in:
夜坂雅
2025-06-23 15:29:44 +08:00
committed by GitHub
parent 7fab4edd41
commit 9248b6cfdf
3 changed files with 5 additions and 8 deletions

View File

@@ -19,7 +19,3 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# Prevent ProGuard from renaming internal SQLCipher classes, which breaks the library.
# From https://github.com/sqlcipher/android-database-sqlcipher#proguard
-keep class net.sqlcipher.** { *; }

View File

@@ -13,10 +13,10 @@ import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlSchema
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import io.element.encrypteddb.passphrase.PassphraseProvider
import net.sqlcipher.database.SupportFactory
import net.zetetic.database.sqlcipher.SupportOpenHelperFactory
/**
* Creates an encrypted version of the [SqlDriver] using SQLCipher's [SupportFactory].
* Creates an encrypted version of the [SqlDriver] using SQLCipher's [SupportOpenHelperFactory].
* @param passphraseProvider Provides the passphrase needed to use the SQLite database with SQLCipher.
*/
class SqlCipherDriverFactory(
@@ -29,8 +29,9 @@ class SqlCipherDriverFactory(
* @param context Android [Context], used to instantiate the driver.
*/
fun create(schema: SqlSchema<QueryResult.Value<Unit>>, name: String, context: Context): SqlDriver {
System.loadLibrary("sqlcipher")
val passphrase = passphraseProvider.getPassphrase()
val factory = SupportFactory(passphrase)
val factory = SupportOpenHelperFactory(passphrase)
return AndroidSqliteDriver(schema = schema, context = context, name = name, factory = factory)
}
}