Skip to content

Commit 7404057

Browse files
Adjust GCM test to verify cipher change
1 parent fa531fa commit 7404057

File tree

2 files changed

+64
-88
lines changed

2 files changed

+64
-88
lines changed

.idea/workspace.xml

Lines changed: 43 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/net/zetetic/tests/AES256GCMCipherTest.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import net.sqlcipher.Cursor;
44
import net.sqlcipher.database.SQLiteDatabase;
55
import net.sqlcipher.database.SQLiteDatabaseHook;
6+
import net.sqlcipher.database.SQLiteException;
7+
import net.zetetic.QueryHelper;
68
import net.zetetic.ZeteticApplication;
79

810
import java.io.File;
@@ -27,16 +29,25 @@ public boolean execute(SQLiteDatabase database) {
2729
database.execSQL("insert into t1(a,b) values(?, ?);", new Object[]{"one for the money", "two for the show"});
2830
database.close();
2931

30-
database = SQLiteDatabase.openDatabase(databaseFile.getAbsolutePath(), ZeteticApplication.DATABASE_PASSWORD,
31-
null, SQLiteDatabase.OPEN_READWRITE, hook);
32-
if(database != null){
33-
Cursor cursor = database.rawQuery("select * from t1;", new String[]{});
34-
if(cursor != null){
35-
cursor.moveToFirst();
36-
String a = cursor.getString(0);
37-
String b = cursor.getString(1);
38-
status = "one for the money".equals(a) && "two for the show".equals(b);
39-
cursor.close();
32+
try {
33+
database = SQLiteDatabase.openDatabase(databaseFile.getAbsolutePath(), ZeteticApplication.DATABASE_PASSWORD,
34+
null, SQLiteDatabase.OPEN_READWRITE, null);
35+
return false;
36+
} catch (SQLiteException ex){
37+
38+
database = SQLiteDatabase.openDatabase(databaseFile.getAbsolutePath(), ZeteticApplication.DATABASE_PASSWORD,
39+
null, SQLiteDatabase.OPEN_READWRITE, hook);
40+
if(database != null){
41+
String cipher = QueryHelper.singleValueFromQuery(database, "PRAGMA cipher");
42+
setMessage(String.format("Cipher set to:%s", cipher));
43+
Cursor cursor = database.rawQuery("select * from t1;", new String[]{});
44+
if(cursor != null){
45+
cursor.moveToFirst();
46+
String a = cursor.getString(0);
47+
String b = cursor.getString(1);
48+
status = "one for the money".equals(a) && "two for the show".equals(b);
49+
cursor.close();
50+
}
4051
}
4152
}
4253
return status;

0 commit comments

Comments
 (0)