1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-29 15:52:08 +01: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) { for (Tuple<PGPSecretKey, PGPPublicKeyEncryptedData> k : postponedDueToMissingPassphrase) {
PGPSecretKey key = k.getA(); PGPSecretKey key = k.getA();
PGPSecretKeyRing keys = getDecryptionKey(key.getKeyID()); PGPSecretKeyRing keys = getDecryptionKey(key.getKeyID());
assert (keys != null);
keyIds.add(new SubkeyIdentifier(keys, key.getKeyID())); keyIds.add(new SubkeyIdentifier(keys, key.getKeyID()));
} }
if (!keyIds.isEmpty()) { if (!keyIds.isEmpty()) {
@ -556,6 +557,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
PGPSecretKey secretKey = missingPassphrases.getA(); PGPSecretKey secretKey = missingPassphrases.getA();
long keyId = secretKey.getKeyID(); long keyId = secretKey.getKeyID();
PGPSecretKeyRing decryptionKey = getDecryptionKey(keyId); PGPSecretKeyRing decryptionKey = getDecryptionKey(keyId);
assert (decryptionKey != null);
SubkeyIdentifier decryptionKeyId = new SubkeyIdentifier(decryptionKey, keyId); SubkeyIdentifier decryptionKeyId = new SubkeyIdentifier(decryptionKey, keyId);
if (hasUnsupportedS2KSpecifier(secretKey, decryptionKeyId)) { if (hasUnsupportedS2KSpecifier(secretKey, decryptionKeyId)) {
continue; continue;

View file

@ -275,6 +275,7 @@ public class CertifyCertificate {
// We only support certification-capable primary keys // We only support certification-capable primary keys
OpenPgpFingerprint fingerprint = info.getFingerprint(); OpenPgpFingerprint fingerprint = info.getFingerprint();
PGPPublicKey certificationPubKey = info.getPublicKey(fingerprint); PGPPublicKey certificationPubKey = info.getPublicKey(fingerprint);
assert (certificationPubKey != null);
if (!info.isKeyValidlyBound(certificationPubKey.getKeyID())) { if (!info.isKeyValidlyBound(certificationPubKey.getKeyID())) {
throw new KeyException.RevokedKeyException(fingerprint); 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 // 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() { addUserId(otherUserId, new SelfSignatureSubpackets.Callback() {
@Override @Override
public void modifyHashedSubpackets(SelfSignatureSubpackets hashedSubpackets) { public void modifyHashedSubpackets(SelfSignatureSubpackets hashedSubpackets) {
@ -601,6 +604,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
if (prevUserIdSig.getHashedSubPackets().isPrimaryUserID()) { if (prevUserIdSig.getHashedSubPackets().isPrimaryUserID()) {
assert (primaryUserId != null);
PGPSignature userIdSig = reissueNonPrimaryUserId(secretKeyRingProtector, userId, prevUserIdSig); PGPSignature userIdSig = reissueNonPrimaryUserId(secretKeyRingProtector, userId, prevUserIdSig);
secretKeyRing = KeyRingUtils.injectCertification(secretKeyRing, primaryUserId, userIdSig); secretKeyRing = KeyRingUtils.injectCertification(secretKeyRing, primaryUserId, userIdSig);
} }