Show a generic error if the encryption key is empty
This commit is contained in:
parent
bd12b5a17f
commit
13db26f377
2 changed files with 19 additions and 7 deletions
|
@ -24,9 +24,11 @@
|
|||
package org.shadowice.flocke.andotp.Utilities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.shadowice.flocke.andotp.Database.Entry;
|
||||
import org.shadowice.flocke.andotp.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -43,6 +45,11 @@ public class DatabaseHelper {
|
|||
|
||||
/* Database functions */
|
||||
public static boolean saveDatabase(Context context, ArrayList<Entry> entries, SecretKey encryptionKey) {
|
||||
if (encryptionKey == null) {
|
||||
Toast.makeText(context, R.string.toast_encryption_key_empty, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
String jsonString = entriesToString(entries);
|
||||
|
||||
try {
|
||||
|
@ -58,9 +65,10 @@ public class DatabaseHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static ArrayList<Entry> loadDatabase(Context context, SecretKey encryptionKey){
|
||||
public static ArrayList<Entry> loadDatabase(Context context, SecretKey encryptionKey) {
|
||||
ArrayList<Entry> entries = new ArrayList<>();
|
||||
|
||||
if (encryptionKey != null) {
|
||||
try {
|
||||
byte[] data = FileHelper.readFileToBytes(new File(context.getFilesDir() + "/" + SETTINGS_FILE));
|
||||
data = EncryptionHelper.decrypt(encryptionKey, data);
|
||||
|
@ -69,6 +77,9 @@ public class DatabaseHelper {
|
|||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, R.string.toast_encryption_key_empty, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
<string name="toast_copied_to_clipboard">Copied to clipboard</string>
|
||||
<string name="toast_entry_exists">This entry already exists</string>
|
||||
<string name="toast_invalid_qr_code">Invalid QR Code</string>
|
||||
<string name="toast_encryption_key_empty">Encryption key not loaded</string>
|
||||
|
||||
<!-- Dialogs -->
|
||||
<string name="dialog_title_auth">Authenticate</string>
|
||||
|
|
Loading…
Reference in a new issue