Skip to content

Commit b99764b

Browse files
author
Chris Brody
committed
Additional safeguard of both versions of SQLiteDatabase.changePassword() against database not opened
1 parent ed51d6d commit b99764b

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,40 @@ public int status(int operation, boolean reset){
8282
return native_status(operation, reset);
8383
}
8484

85+
/**
86+
* Change the password of the open database using sqlite3_rekey().
87+
*
88+
* @param password new database password
89+
*
90+
* @throws SQLiteException if there is an issue changing the password internally
91+
* OR if the database is not open
92+
*
93+
* FUTURE @todo throw IllegalStateException if the database is not open and
94+
* update the test suite
95+
*/
8596
public void changePassword(String password) throws SQLiteException {
86-
native_rekey(password);
97+
if (!isOpen()) {
98+
throw new SQLiteException("database not open");
99+
}
100+
native_rekey(password);
87101
}
88102

103+
/**
104+
* Change the password of the open database using sqlite3_rekey().
105+
*
106+
* @param password new database password (char array)
107+
*
108+
* @throws SQLiteException if there is an issue changing the password internally
109+
* OR if the database is not open
110+
*
111+
* FUTURE @todo throw IllegalStateException if the database is not open and
112+
* update the test suite
113+
*/
89114
public void changePassword(char[] password) throws SQLiteException {
90-
native_rekey(password);
115+
if (!isOpen()) {
116+
throw new SQLiteException("database not open");
117+
}
118+
native_rekey(password);
91119
}
92120

93121
private static void loadICUData(Context context, File workingDir) {
@@ -2655,7 +2683,7 @@ private static ArrayList<Pair<String, String>> getAttachedDbs(SQLiteDatabase dbO
26552683

26562684
private native void native_key(char[] key) throws SQLException;
26572685
private native void native_key(String key) throws SQLException;
2658-
2686+
26592687
private native void native_rekey(String key) throws SQLException;
26602688
private native void native_rekey(char[] key) throws SQLException;
26612689
}

0 commit comments

Comments
 (0)