Don't try to catch exceptions that'll never be thrown

pull/41/head
Alexander Bakker 7 years ago
parent 66ea357f08
commit 964fc72fba

@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -39,8 +39,7 @@ public class CryptoUtils {
public static final int CRYPTO_SCRYPT_r = 8;
public static final int CRYPTO_SCRYPT_p = 1;
public static SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p)
throws NoSuchAlgorithmException, InvalidKeySpecException {
public static SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) {
byte[] bytes = toBytes(password);
byte[] keyBytes = SCrypt.generate(bytes, salt, n, r, p, CRYPTO_KEY_SIZE);
return new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");

@ -49,25 +49,17 @@ public class PasswordSlot extends RawSlot {
}
}
public SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) throws SlotException {
try {
SecretKey key = CryptoUtils.deriveKey(password, salt, n, r, p);
_n = n;
_r = r;
_p = p;
_salt = salt;
return key;
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new SlotException(e);
}
public SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) {
SecretKey key = CryptoUtils.deriveKey(password, salt, n, r, p);
_n = n;
_r = r;
_p = p;
_salt = salt;
return key;
}
public SecretKey deriveKey(char[] password) throws SlotException {
try {
return CryptoUtils.deriveKey(password, _salt, _n, _r, _p);
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
throw new SlotException(e);
}
public SecretKey deriveKey(char[] password) {
return CryptoUtils.deriveKey(password, _salt, _n, _r, _p);
}
@Override

@ -26,7 +26,7 @@ public class PreferencesActivity extends AegisActivity implements PasswordDialog
}
@Override
protected final void onRestoreInstanceState(final Bundle inState) {
protected void onRestoreInstanceState(final Bundle inState) {
// pass the stored result intent back to the fragment
if (inState.containsKey("result")) {
_fragment.setResult(inState.getParcelable("result"));
@ -35,7 +35,7 @@ public class PreferencesActivity extends AegisActivity implements PasswordDialog
}
@Override
protected final void onSaveInstanceState(final Bundle outState) {
protected void onSaveInstanceState(final Bundle outState) {
// save the result intent of the fragment
// this is done so we don't lose anything if the fragment calls recreate on this activity
outState.putParcelable("result", _fragment.getResult());

@ -21,12 +21,8 @@ public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, Se
setPriority();
Params params = args[0];
try {
byte[] salt = CryptoUtils.generateSalt();
return params.Slot.deriveKey(params.Password, salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
} catch (SlotException e) {
return null;
}
byte[] salt = CryptoUtils.generateSalt();
return params.Slot.deriveKey(params.Password, salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
}
@Override

Loading…
Cancel
Save