Skip to content

Commit c819857

Browse files
committed
switch to a supported constructor for tests
1 parent 5ba1046 commit c819857

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

app/src/main/java/net/zetetic/tests/support/AES128CipherTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.database.Cursor;
44
import net.sqlcipher.database.SQLiteDatabase;
5+
import net.sqlcipher.database.SQLiteDatabaseHook;
56
import net.sqlcipher.database.SupportFactory;
67
import net.zetetic.ZeteticApplication;
78
import net.zetetic.tests.TestResult;
@@ -13,7 +14,18 @@ public TestResult run() {
1314
TestResult result = new TestResult(getName(), false);
1415

1516
byte[] passphrase = SQLiteDatabase.getBytes(ZeteticApplication.DATABASE_PASSWORD.toCharArray());
16-
SupportFactory factory = new SupportFactory(passphrase, "PRAGMA cipher = 'aes-128-cbc'");
17+
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
18+
@Override
19+
public void preKey(SQLiteDatabase sqLiteDatabase) {
20+
21+
}
22+
23+
@Override
24+
public void postKey(SQLiteDatabase sqLiteDatabase) {
25+
sqLiteDatabase.rawExecSQL("PRAGMA cipher = 'aes-128-cbc'");
26+
}
27+
};
28+
SupportFactory factory = new SupportFactory(passphrase, hook);
1729
SupportSQLiteOpenHelper.Configuration cfg =
1830
SupportSQLiteOpenHelper.Configuration.builder(ZeteticApplication.getInstance())
1931
.name(ZeteticApplication.DATABASE_NAME)

app/src/main/java/net/zetetic/tests/support/MigrateDatabaseFrom1xFormatToCurrentFormat.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.database.Cursor;
44
import net.sqlcipher.database.SQLiteDatabase;
5+
import net.sqlcipher.database.SQLiteDatabaseHook;
56
import net.sqlcipher.database.SupportFactory;
67
import net.zetetic.ZeteticApplication;
78
import net.zetetic.tests.TestResult;
@@ -14,10 +15,21 @@ public TestResult run() {
1415
TestResult result = new TestResult(getName(), false);
1516

1617
try {
17-
File sourceDatabase = ZeteticApplication.getInstance().getDatabasePath(ZeteticApplication.ONE_X_DATABASE);
18+
final File sourceDatabase = ZeteticApplication.getInstance().getDatabasePath(ZeteticApplication.ONE_X_DATABASE);
1819
byte[] passphrase = SQLiteDatabase.getBytes(ZeteticApplication.DATABASE_PASSWORD.toCharArray());
1920
ZeteticApplication.getInstance().extractAssetToDatabaseDirectory(ZeteticApplication.ONE_X_DATABASE);
20-
SupportFactory factory = new SupportFactory(passphrase, "PRAGMA cipher_migrate;");
21+
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
22+
@Override
23+
public void preKey(SQLiteDatabase sqLiteDatabase) {
24+
25+
}
26+
27+
@Override
28+
public void postKey(SQLiteDatabase sqLiteDatabase) {
29+
sqLiteDatabase.rawExecSQL("PRAGMA cipher_migrate;");
30+
}
31+
};
32+
SupportFactory factory = new SupportFactory(passphrase, hook);
2133
SupportSQLiteOpenHelper.Configuration cfg =
2234
SupportSQLiteOpenHelper.Configuration.builder(ZeteticApplication.getInstance())
2335
.name(sourceDatabase.getAbsolutePath())

app/src/main/java/net/zetetic/tests/support/MigrationUserVersion.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ public TestResult run() {
2121

2222
File sourceDatabase = ZeteticApplication.getInstance().getDatabasePath(ZeteticApplication.ONE_X_USER_VERSION_DATABASE);
2323
byte[] passphrase = SQLiteDatabase.getBytes(ZeteticApplication.DATABASE_PASSWORD.toCharArray());
24-
SupportFactory factory = new SupportFactory(passphrase, "PRAGMA cipher_migrate;");
24+
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
25+
@Override
26+
public void preKey(SQLiteDatabase sqLiteDatabase) {
27+
28+
}
29+
30+
@Override
31+
public void postKey(SQLiteDatabase sqLiteDatabase) {
32+
sqLiteDatabase.rawExecSQL("PRAGMA cipher_migrate;");
33+
}
34+
};
35+
SupportFactory factory = new SupportFactory(passphrase, hook);
2536
SupportSQLiteOpenHelper.Configuration cfg =
2637
SupportSQLiteOpenHelper.Configuration.builder(ZeteticApplication.getInstance())
2738
.name(sourceDatabase.getAbsolutePath())

app/src/main/java/net/zetetic/tests/support/VerifyUTF8EncodingForKeyTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ public void onUpgrade(SupportSQLiteDatabase db, int oldVersion,
5757
} catch (SQLiteException ex){}
5858

5959
passphrase = SQLiteDatabase.getBytes(password.toCharArray());
60-
factory = new SupportFactory(passphrase, "PRAGMA cipher_migrate;");
60+
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
61+
@Override
62+
public void preKey(SQLiteDatabase sqLiteDatabase) {
63+
64+
}
65+
66+
@Override
67+
public void postKey(SQLiteDatabase sqLiteDatabase) {
68+
sqLiteDatabase.rawExecSQL("PRAGMA cipher_migrate;");
69+
}
70+
};
71+
factory = new SupportFactory(passphrase, hook);
6172
cfg =
6273
SupportSQLiteOpenHelper.Configuration.builder(ZeteticApplication.getInstance())
6374
.name(sourceDatabaseFile.getAbsolutePath())

0 commit comments

Comments
 (0)