-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:io'; | ||
import 'package:drift/native.dart'; | ||
import 'package:sqlite3/sqlite3.dart'; | ||
|
||
// #docregion setup | ||
import 'dart:ffi'; | ||
import 'package:sqlite3/open.dart'; | ||
|
||
// call this method before using drift | ||
void setupSqlCipher() { | ||
open.overrideFor( | ||
OperatingSystem.android, () => DynamicLibrary.open('libsqlcipher.so')); | ||
} | ||
// #enddocregion setup | ||
|
||
// #docregion check_cipher | ||
bool _debugCheckHasCipher(Database database) { | ||
return database.select('PRAGMA cipher_version;').isNotEmpty; | ||
} | ||
// #enddocregion check_cipher | ||
|
||
void databases() { | ||
final myDatabaseFile = File('/dev/null'); | ||
|
||
// #docregion encrypted1 | ||
NativeDatabase( | ||
myDatabaseFile, | ||
setup: (rawDb) { | ||
rawDb.execute("PRAGMA key = 'passphrase';"); | ||
}, | ||
); | ||
// #enddocregion encrypted1 | ||
|
||
// #docregion encrypted2 | ||
NativeDatabase( | ||
myDatabaseFile, | ||
setup: (rawDb) { | ||
assert(_debugCheckHasCipher(rawDb)); | ||
rawDb.execute("PRAGMA key = 'passphrase';"); | ||
}, | ||
); | ||
// #enddocregion encrypted2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters