refactor: Migrate SQLCipher Android to new API (#4874)
Co-authored-by: Benoit Marty <benoitm@element.io>
This commit is contained in:
parent
7fab4edd41
commit
9248b6cfdf
3 changed files with 5 additions and 8 deletions
|
|
@ -178,7 +178,7 @@ matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose",
|
||||||
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||||
sqldelight-driver-jvm = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
|
sqldelight-driver-jvm = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
|
||||||
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
|
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
|
||||||
sqlcipher = "net.zetetic:android-database-sqlcipher:4.5.4"
|
sqlcipher = "net.zetetic:sqlcipher-android:4.9.0"
|
||||||
sqlite = "androidx.sqlite:sqlite-ktx:2.5.2"
|
sqlite = "androidx.sqlite:sqlite-ktx:2.5.2"
|
||||||
unifiedpush = "org.unifiedpush.android:connector:3.0.10"
|
unifiedpush = "org.unifiedpush.android:connector:3.0.10"
|
||||||
otaliastudios_transcoder = "com.otaliastudios:transcoder:0.11.2"
|
otaliastudios_transcoder = "com.otaliastudios:transcoder:0.11.2"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,3 @@
|
||||||
# If you keep the line number information, uncomment this to
|
# If you keep the line number information, uncomment this to
|
||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-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.** { *; }
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ import app.cash.sqldelight.db.SqlDriver
|
||||||
import app.cash.sqldelight.db.SqlSchema
|
import app.cash.sqldelight.db.SqlSchema
|
||||||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
||||||
import io.element.encrypteddb.passphrase.PassphraseProvider
|
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.
|
* @param passphraseProvider Provides the passphrase needed to use the SQLite database with SQLCipher.
|
||||||
*/
|
*/
|
||||||
class SqlCipherDriverFactory(
|
class SqlCipherDriverFactory(
|
||||||
|
|
@ -29,8 +29,9 @@ class SqlCipherDriverFactory(
|
||||||
* @param context Android [Context], used to instantiate the driver.
|
* @param context Android [Context], used to instantiate the driver.
|
||||||
*/
|
*/
|
||||||
fun create(schema: SqlSchema<QueryResult.Value<Unit>>, name: String, context: Context): SqlDriver {
|
fun create(schema: SqlSchema<QueryResult.Value<Unit>>, name: String, context: Context): SqlDriver {
|
||||||
|
System.loadLibrary("sqlcipher")
|
||||||
val passphrase = passphraseProvider.getPassphrase()
|
val passphrase = passphraseProvider.getPassphrase()
|
||||||
val factory = SupportFactory(passphrase)
|
val factory = SupportOpenHelperFactory(passphrase)
|
||||||
return AndroidSqliteDriver(schema = schema, context = context, name = name, factory = factory)
|
return AndroidSqliteDriver(schema = schema, context = context, name = name, factory = factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue