mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 22:12:55 +00:00
Don't try to catch exceptions that'll never be thrown
This commit is contained in:
parent
66ea357f08
commit
964fc72fba
5 changed files with 15 additions and 28 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -24,7 +24,7 @@
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class CryptoUtils {
|
||||||
public static final int CRYPTO_SCRYPT_r = 8;
|
public static final int CRYPTO_SCRYPT_r = 8;
|
||||||
public static final int CRYPTO_SCRYPT_p = 1;
|
public static final int CRYPTO_SCRYPT_p = 1;
|
||||||
|
|
||||||
public static SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p)
|
public static SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) {
|
||||||
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
||||||
byte[] bytes = toBytes(password);
|
byte[] bytes = toBytes(password);
|
||||||
byte[] keyBytes = SCrypt.generate(bytes, salt, n, r, p, CRYPTO_KEY_SIZE);
|
byte[] keyBytes = SCrypt.generate(bytes, salt, n, r, p, CRYPTO_KEY_SIZE);
|
||||||
return new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
|
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 {
|
public SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) {
|
||||||
try {
|
SecretKey key = CryptoUtils.deriveKey(password, salt, n, r, p);
|
||||||
SecretKey key = CryptoUtils.deriveKey(password, salt, n, r, p);
|
_n = n;
|
||||||
_n = n;
|
_r = r;
|
||||||
_r = r;
|
_p = p;
|
||||||
_p = p;
|
_salt = salt;
|
||||||
_salt = salt;
|
return key;
|
||||||
return key;
|
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
|
||||||
throw new SlotException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecretKey deriveKey(char[] password) throws SlotException {
|
public SecretKey deriveKey(char[] password) {
|
||||||
try {
|
return CryptoUtils.deriveKey(password, _salt, _n, _r, _p);
|
||||||
return CryptoUtils.deriveKey(password, _salt, _n, _r, _p);
|
|
||||||
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
|
|
||||||
throw new SlotException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class PreferencesActivity extends AegisActivity implements PasswordDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void onRestoreInstanceState(final Bundle inState) {
|
protected void onRestoreInstanceState(final Bundle inState) {
|
||||||
// pass the stored result intent back to the fragment
|
// pass the stored result intent back to the fragment
|
||||||
if (inState.containsKey("result")) {
|
if (inState.containsKey("result")) {
|
||||||
_fragment.setResult(inState.getParcelable("result"));
|
_fragment.setResult(inState.getParcelable("result"));
|
||||||
|
@ -35,7 +35,7 @@ public class PreferencesActivity extends AegisActivity implements PasswordDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void onSaveInstanceState(final Bundle outState) {
|
protected void onSaveInstanceState(final Bundle outState) {
|
||||||
// save the result intent of the fragment
|
// save the result intent of the fragment
|
||||||
// this is done so we don't lose anything if the fragment calls recreate on this activity
|
// this is done so we don't lose anything if the fragment calls recreate on this activity
|
||||||
outState.putParcelable("result", _fragment.getResult());
|
outState.putParcelable("result", _fragment.getResult());
|
||||||
|
|
|
@ -21,12 +21,8 @@ public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, Se
|
||||||
setPriority();
|
setPriority();
|
||||||
|
|
||||||
Params params = args[0];
|
Params params = args[0];
|
||||||
try {
|
byte[] salt = CryptoUtils.generateSalt();
|
||||||
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.Slot.deriveKey(params.Password, salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
|
|
||||||
} catch (SlotException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue