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