mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-05 16:55:05 -05:00
tidy up code
This commit is contained in:
parent
935274960d
commit
dd27d132be
@ -164,16 +164,8 @@ public class PgpHelper {
|
||||
for (int i = 0; i < signingKeys.size(); ++i) {
|
||||
PGPSecretKey key = signingKeys.get(i);
|
||||
if (key.isMasterKey()) {
|
||||
try {
|
||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
|
||||
.setProvider(PgpMain.BOUNCY_CASTLE_PROVIDER_NAME).build(new char[] {});
|
||||
PGPPrivateKey testKey = key.extractPrivateKey(
|
||||
keyDecryptor);
|
||||
if (testKey != null) {
|
||||
masterKey = key;
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
// all good if this fails, we likely didn't use the right password
|
||||
if (!isSecretKeyPrivateEmpty(key)) {
|
||||
masterKey = key;
|
||||
}
|
||||
} else {
|
||||
usableKeys.add(key);
|
||||
@ -424,8 +416,8 @@ public class PgpHelper {
|
||||
if (testKey != null) {
|
||||
return false;
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
// all good if this fails, we likely didn't use the right password
|
||||
} catch (PGPException e) { //exception if wrong key => not empty
|
||||
return false; //all good if this fails, we likely didn't use the right password
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -493,18 +493,12 @@ public class PgpMain {
|
||||
boolean save = true;
|
||||
|
||||
for (PGPSecretKey testSecretKey : new IterableIterator<PGPSecretKey>(secretKeyRing.getSecretKeys())) {
|
||||
try {
|
||||
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
|
||||
.setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(new char[] {});
|
||||
PGPPrivateKey testKey = testSecretKey.extractPrivateKey(
|
||||
keyDecryptor);
|
||||
if (testKey == null && !testSecretKey.isMasterKey()) {
|
||||
if (!testSecretKey.isMasterKey()) {
|
||||
if (PgpHelper.isSecretKeyPrivateEmpty(testSecretKey)) {
|
||||
// this is bad, something is very wrong...
|
||||
save = false;
|
||||
status = Id.return_value.bad;
|
||||
}
|
||||
} catch (PGPException e) {
|
||||
// all good if this fails, we likely didn't use the right password
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user