Skip to main content

Crate weirdnet_storage

Crate weirdnet_storage 

Source
Expand description

General storage for SQLite databases encrypted with SQLCipher.

Schema-free and brand-free: callers supply their migrations, name their database in error messages and register the tables they sync.

Key boundary: the caller owns every key. This crate only applies a raw 32-byte key it is handed (zeroizing the literals it builds); it never derives, wraps, stores, recovers or exports one, and never sees a password.

Re-exports§

pub use rusqlite;

Modules§

files
Private folders and files for opaque bytes (key files, settings, exports): folders 0700, files 0600 on Unix. Other platforms keep their default permissions.
sync
A row change log for keeping copies of a database in step.

Enums§

StorageError

Functions§

apply_key
Apply a raw key (PRAGMA key = "x'…'"); SQLCipher’s own logging stays off stderr.
begin
Open a savepoint (SAVEPOINT name).
encrypt_plaintext_in_place
Encrypt an existing plaintext SQLite file in place with key.
has_cipher
Whether this SQLite is SQLCipher (a key would otherwise be ignored).
migrate
Apply migrations[..upto] not yet recorded in schema_version, all in one transaction (any failure leaves the database as it was). applied(tx, i) runs right after migration i (0-based) and before it is recorded: data upgrades and seed rows go there.
open
Open (creating if needed, with a private parent folder and a file that is 0600 from the start) and verify the key. what names the database in the wrong-key error. A file this call created is removed again if opening fails.
open_foreign_readonly
Open someone else’s SQLite file read-only (URIs allowed), with their SQLCipher passphrase if it has one. The passphrase goes to SQLCipher as given; nothing is derived here and the key is not checked.
open_in_memory
A private in-memory database (tests, scratch work).
open_readonly
Open an existing database read-only (no writes, no migrations) and verify the key.
quote_ident
Quote an SQL identifier ("name", inner quotes doubled).
rekey
Re-encrypt an open, keyed database with a new raw key (PRAGMA rekey).
release
Keep everything since begin (RELEASE name).
rollback
Undo everything since begin and close the savepoint.
savepoint
Run f all-or-nothing: released when it returns Ok, rolled back when it returns Err (the rollback’s own failure is ignored so f’s error is the one returned).
schema_version
The highest applied migration (schema_version).
snapshot_to
Copy an open database to dest with SQLite’s online backup, keyed with key (an encrypted source stays encrypted). dest is replaced, private from creation, and removed again if the copy fails.
table_exists
Whether a table exists.

Type Aliases§

RawKey
A raw SQLCipher key (the caller’s data-encryption key). Applied as-is, never derived.
Result