Fix mixup of EnableEncryptionListener and SetPasswordListener logic

I somehow managed to mix the logic of these two up
pull/120/head
Alexander Bakker 7 years ago
parent 9827fbc4ff
commit 1b09c7bb69

@ -445,18 +445,26 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
private class SetPasswordListener implements Dialogs.SlotListener { private class SetPasswordListener implements Dialogs.SlotListener {
@Override @Override
public void onSlotResult(Slot slot, Cipher cipher) { public void onSlotResult(Slot slot, Cipher cipher) {
DatabaseFileCredentials creds = new DatabaseFileCredentials(); DatabaseFileCredentials creds = _db.getCredentials();
SlotList slots = creds.getSlots();
try { try {
// encrypt the master key for this slot
slot.setKey(creds.getKey(), cipher); slot.setKey(creds.getKey(), cipher);
creds.getSlots().add(slot);
_db.enableEncryption(creds); // remove the old master password slot
} catch (DatabaseManagerException | SlotException e) { PasswordSlot oldSlot = creds.getSlots().find(PasswordSlot.class);
slots.remove(oldSlot);
// add the new master password slot
slots.add(slot);
} catch (SlotException e) {
onException(e); onException(e);
return; return;
} }
updateEncryptionPreferences(); _db.setCredentials(creds);
saveDatabase();
} }
@Override @Override
@ -495,26 +503,18 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
private class EnableEncryptionListener implements Dialogs.SlotListener { private class EnableEncryptionListener implements Dialogs.SlotListener {
@Override @Override
public void onSlotResult(Slot slot, Cipher cipher) { public void onSlotResult(Slot slot, Cipher cipher) {
DatabaseFileCredentials creds = _db.getCredentials(); DatabaseFileCredentials creds = new DatabaseFileCredentials();
SlotList slots = creds.getSlots();
try { try {
// encrypt the master key for this slot
slot.setKey(creds.getKey(), cipher); slot.setKey(creds.getKey(), cipher);
creds.getSlots().add(slot);
// remove the old master password slot _db.enableEncryption(creds);
PasswordSlot oldSlot = creds.getSlots().find(PasswordSlot.class); } catch (DatabaseManagerException | SlotException e) {
slots.remove(oldSlot);
// add the new master password slot
slots.add(slot);
} catch (SlotException e) {
onException(e); onException(e);
return; return;
} }
_db.setCredentials(creds); updateEncryptionPreferences();
saveDatabase();
} }
@Override @Override

Loading…
Cancel
Save