Skip to main content

apply_encryption

Function apply_encryption 

Source
pub fn apply_encryption(
    conn: &Connection,
    config: &EncryptionConfig,
) -> Result<(), Error>
Expand description

Applies SQLCipher encryption to a connection.

This function configures a SQLite connection for SQLCipher encryption by:

  1. Setting the encryption key (PRAGMA key) - must be first operation
  2. Pinning SQLCipher 4.x compatibility mode
  3. Forcing in-memory temporary storage to avoid plaintext temp file spill
  4. Validating the key by reading from sqlite_master

§Arguments

  • conn - The SQLite connection to configure
  • config - The encryption configuration containing the key

§Errors

Returns an error if:

  • The key is incorrect for an existing database
  • The database is corrupted
  • The database is not encrypted but a key was provided