Get rid of all uses of double brace initialization

The way this feature is implemented in java is absolutely ridiculous
This commit is contained in:
Alexander Bakker 2018-06-06 21:30:24 +02:00
parent c3f94b37c8
commit 3f01a0a3da
15 changed files with 139 additions and 103 deletions

View file

@ -31,9 +31,9 @@ import me.impy.aegis.db.slots.SlotException;
import me.impy.aegis.helpers.FingerprintHelper;
import me.impy.aegis.helpers.FingerprintUiHelper;
import me.impy.aegis.helpers.EditTextHelper;
import me.impy.aegis.ui.tasks.SlotCollectionTask;
import me.impy.aegis.ui.tasks.SlotListTask;
public class AuthActivity extends AegisActivity implements FingerprintUiHelper.Callback, SlotCollectionTask.Callback {
public class AuthActivity extends AegisActivity implements FingerprintUiHelper.Callback, SlotListTask.Callback {
private EditText _textPassword;
private SlotList _slots;
@ -112,10 +112,8 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
}
private <T extends Slot> void trySlots(Class<T> type, Object obj) {
new SlotCollectionTask<>(type, this, this).execute(new SlotCollectionTask.Params(){{
Slots = _slots;
Obj = obj;
}});
SlotListTask.Params params = new SlotListTask.Params(_slots, obj);
new SlotListTask<>(type, this, this).execute(params);
}
private void setKey(MasterKey key) {

View file

@ -115,10 +115,8 @@ public class IntroActivity extends AppIntro implements DerivationTask.Callback {
if (newFragment == _endSlide && cryptType != CustomAuthenticationSlide.CRYPT_TYPE_NONE) {
_passwordSlot = new PasswordSlot();
new DerivationTask(this, this).execute(new DerivationTask.Params() {{
Slot = _passwordSlot;
Password = _authenticatedSlide.getPassword();
}});
DerivationTask.Params params = new DerivationTask.Params(_passwordSlot, _authenticatedSlide.getPassword());
new DerivationTask(this, this).execute(params);
} else if (oldFragment == _authenticationSlide && newFragment != _endSlide) {
// skip to the last slide if no encryption will be used
if (cryptType == CustomAuthenticationSlide.CRYPT_TYPE_NONE) {

View file

@ -60,10 +60,7 @@ public class PasswordDialogFragment extends SlotDialogFragment {
getListener().onSlotResult(slot, cipher);
dialog.dismiss();
});
task.execute(new DerivationTask.Params() {{
Slot = slot;
Password = password;
}});
task.execute(new DerivationTask.Params(slot, password));
});
});

View file

@ -21,7 +21,7 @@ public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, Se
Params params = args[0];
byte[] salt = CryptoUtils.generateSalt();
return params.Slot.deriveKey(params.Password, salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
return params.getSlot().deriveKey(params.getPassword(), salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
}
@Override
@ -31,8 +31,21 @@ public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, Se
}
public static class Params {
public PasswordSlot Slot;
public char[] Password;
private PasswordSlot _slot;
private char[] _password;
public Params(PasswordSlot slot, char[] password) {
_slot = slot;
_password = password;
}
public PasswordSlot getSlot() {
return _slot;
}
public char[] getPassword() {
return _password;
}
}
public interface Callback {

View file

@ -13,36 +13,37 @@ import me.impy.aegis.db.slots.SlotList;
import me.impy.aegis.db.slots.SlotException;
import me.impy.aegis.db.slots.SlotIntegrityException;
public class SlotCollectionTask<T extends Slot> extends ProgressDialogTask<SlotCollectionTask.Params, MasterKey> {
public class SlotListTask<T extends Slot> extends ProgressDialogTask<SlotListTask.Params, MasterKey> {
private Callback _cb;
private Class<T> _type;
public SlotCollectionTask(Class<T> type, Context context, Callback cb) {
public SlotListTask(Class<T> type, Context context, Callback cb) {
super(context, "Decrypting database");
_cb = cb;
_type = type;
}
@Override
protected MasterKey doInBackground(SlotCollectionTask.Params... args) {
protected MasterKey doInBackground(SlotListTask.Params... args) {
setPriority();
Params params = args[0];
SlotList slots = params.getSlots();
try {
if (!params.Slots.has(_type)) {
if (!slots.has(_type)) {
throw new RuntimeException();
}
MasterKey masterKey = null;
for (Slot slot : params.Slots.findAll(_type)) {
for (Slot slot : slots.findAll(_type)) {
try {
if (slot instanceof PasswordSlot) {
char[] password = (char[])params.Obj;
char[] password = (char[])params.getObj();
SecretKey key = ((PasswordSlot)slot).deriveKey(password);
Cipher cipher = slot.createDecryptCipher(key);
masterKey = slot.getKey(cipher);
} else if (slot instanceof FingerprintSlot) {
masterKey = slot.getKey((Cipher)params.Obj);
masterKey = slot.getKey((Cipher)params.getObj());
} else {
throw new RuntimeException();
}
@ -71,8 +72,21 @@ public class SlotCollectionTask<T extends Slot> extends ProgressDialogTask<SlotC
}
public static class Params {
public SlotList Slots;
public Object Obj;
private SlotList _slots;
private Object _obj;
public Params(SlotList slots, Object obj) {
_slots = slots;
_obj = obj;
}
public SlotList getSlots() {
return _slots;
}
public Object getObj() {
return _obj;
}
}
public interface Callback {