SealiteDriver

An SQLiteDriver whose every connection is SQLCipher-encrypted with a SealiteKey.

val driver = SealiteKey.raw(dek).use { SealiteDriver(it) } // closes the temporary key
dek.fill(0)
val db = Room.databaseBuilder<AppDatabase>(name = path).setDriver(driver).build()
// shutdown: db.close(), then driver.close()

The driver keeps its own copy of key (Room opens pool connections lazily) and wipes it in close; the caller may close its own key right after construction. A connection is returned only after the key was applied and the database verified: a wrong key, a plaintext database, or a build that somehow linked a plain SQLite, fails open with a SealiteException (not an androidx.sqlite.SQLiteException); pass it (or the exception Room wraps it in) to Sealite.errorOf to get the SealiteError. Room's corruption recovery (allowDataLossOnRecovery) reacts only to SQLiteException, so it never deletes the database over a wrong key. Plain SQLite failures (I/O, a damaged page under the right key) stay SQLiteException.

A damaged file reports SealiteError.WRONG_KEY too, because an encrypted file is indistinguishable from random bytes: never delete the database yourself on WRONG_KEY.

Parameters

key

the key every connection is opened with; copied, so the caller may close its own.

config

how the file is read and written; the SQLCipher 4 defaults unless the file says otherwise.

Constructors

Link copied to clipboard
constructor(key: SealiteKey, config: SealiteConfig)
constructor(key: SealiteKey)

A driver with SealiteConfig.DEFAULT (SQLCipher 4).

Properties

Link copied to clipboard
@get:JvmName(name = "hasConnectionPool")
open override val hasConnectionPool: Boolean

Room keeps its own connection pool, as it does for the bundled driver.

Functions

Link copied to clipboard
open override fun close()

Wipes the driver's key. Close every connection (the RoomDatabase) first.

Link copied to clipboard
open override fun open(fileName: String): SQLiteConnection

fun open(fileName: String, flags: Int): SQLiteConnection

Opens with explicit SQLITE_OPEN_* flags.