1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-23 03:54:49 +02:00

Use assert statements to flag impossible NPEs

This commit is contained in:
Paul Schaub 2023-05-03 17:13:29 +02:00
parent d05ffd0451
commit 21ae48d8c1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 8 additions and 1 deletions

View file

@ -544,6 +544,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
for (Tuple<PGPSecretKey, PGPPublicKeyEncryptedData> k : postponedDueToMissingPassphrase) {
PGPSecretKey key = k.getA();
PGPSecretKeyRing keys = getDecryptionKey(key.getKeyID());
assert (keys != null);
keyIds.add(new SubkeyIdentifier(keys, key.getKeyID()));
}
if (!keyIds.isEmpty()) {
@ -556,6 +557,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
PGPSecretKey secretKey = missingPassphrases.getA();
long keyId = secretKey.getKeyID();
PGPSecretKeyRing decryptionKey = getDecryptionKey(keyId);
assert (decryptionKey != null);
SubkeyIdentifier decryptionKeyId = new SubkeyIdentifier(decryptionKey, keyId);
if (hasUnsupportedS2KSpecifier(secretKey, decryptionKeyId)) {
continue;

View file

@ -275,6 +275,7 @@ public class CertifyCertificate {
// We only support certification-capable primary keys
OpenPgpFingerprint fingerprint = info.getFingerprint();
PGPPublicKey certificationPubKey = info.getPublicKey(fingerprint);
assert (certificationPubKey != null);
if (!info.isKeyValidlyBound(certificationPubKey.getKeyID())) {
throw new KeyException.RevokedKeyException(fingerprint);
}

View file

@ -182,7 +182,10 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
}
// We need to unmark this user-id as primary
if (info.getLatestUserIdCertification(otherUserId).getHashedSubPackets().isPrimaryUserID()) {
PGPSignature userIdCertification = info.getLatestUserIdCertification(otherUserId);
assert (userIdCertification != null);
if (userIdCertification.getHashedSubPackets().isPrimaryUserID()) {
addUserId(otherUserId, new SelfSignatureSubpackets.Callback() {
@Override
public void modifyHashedSubpackets(SelfSignatureSubpackets hashedSubpackets) {
@ -601,6 +604,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
}
if (prevUserIdSig.getHashedSubPackets().isPrimaryUserID()) {
assert (primaryUserId != null);
PGPSignature userIdSig = reissueNonPrimaryUserId(secretKeyRingProtector, userId, prevUserIdSig);
secretKeyRing = KeyRingUtils.injectCertification(secretKeyRing, primaryUserId, userIdSig);
}