1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-29 15:52:08 +01:00

SOP: Use new MessageMetadata class

This commit is contained in:
Paul Schaub 2022-11-22 16:27:34 +01:00
parent b36b5413e2
commit 25190fc5df
3 changed files with 11 additions and 7 deletions

View file

@ -69,6 +69,10 @@ public class MessageMetadata {
return resultBuilder.build(); return resultBuilder.build();
} }
public boolean isUsingCleartextSignatureFramework() {
return message.isCleartextSigned();
}
public boolean isEncrypted() { public boolean isEncrypted() {
SymmetricKeyAlgorithm algorithm = getEncryptionAlgorithm(); SymmetricKeyAlgorithm algorithm = getEncryptionAlgorithm();
return algorithm != null && algorithm != SymmetricKeyAlgorithm.NULL; return algorithm != null && algorithm != SymmetricKeyAlgorithm.NULL;

View file

@ -21,7 +21,7 @@ import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.MessageMetadata;
import org.pgpainless.decryption_verification.SignatureVerification; import org.pgpainless.decryption_verification.SignatureVerification;
import org.pgpainless.exception.MalformedOpenPgpMessageException; import org.pgpainless.exception.MalformedOpenPgpMessageException;
import org.pgpainless.exception.MissingDecryptionMethodException; import org.pgpainless.exception.MissingDecryptionMethodException;
@ -136,14 +136,14 @@ public class DecryptImpl implements Decrypt {
public DecryptionResult writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature { public DecryptionResult writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
Streams.pipeAll(decryptionStream, outputStream); Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close(); decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult(); MessageMetadata metadata = decryptionStream.getMetadata();
if (!metadata.isEncrypted()) { if (!metadata.isEncrypted()) {
throw new SOPGPException.BadData("Data is not encrypted."); throw new SOPGPException.BadData("Data is not encrypted.");
} }
List<Verification> verificationList = new ArrayList<>(); List<Verification> verificationList = new ArrayList<>();
for (SignatureVerification signatureVerification : metadata.getVerifiedInbandSignatures()) { for (SignatureVerification signatureVerification : metadata.getVerifiedInlineSignatures()) {
verificationList.add(map(signatureVerification)); verificationList.add(map(signatureVerification));
} }

View file

@ -17,7 +17,7 @@ import org.bouncycastle.util.io.Streams;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.MessageMetadata;
import org.pgpainless.decryption_verification.SignatureVerification; import org.pgpainless.decryption_verification.SignatureVerification;
import org.pgpainless.exception.MalformedOpenPgpMessageException; import org.pgpainless.exception.MalformedOpenPgpMessageException;
import org.pgpainless.exception.MissingDecryptionMethodException; import org.pgpainless.exception.MissingDecryptionMethodException;
@ -63,12 +63,12 @@ public class InlineVerifyImpl implements InlineVerify {
Streams.pipeAll(decryptionStream, outputStream); Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close(); decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult(); MessageMetadata metadata = decryptionStream.getMetadata();
List<Verification> verificationList = new ArrayList<>(); List<Verification> verificationList = new ArrayList<>();
List<SignatureVerification> verifications = metadata.isCleartextSigned() ? List<SignatureVerification> verifications = metadata.isUsingCleartextSignatureFramework() ?
metadata.getVerifiedDetachedSignatures() : metadata.getVerifiedDetachedSignatures() :
metadata.getVerifiedInbandSignatures(); metadata.getVerifiedInlineSignatures();
for (SignatureVerification signatureVerification : verifications) { for (SignatureVerification signatureVerification : verifications) {
verificationList.add(map(signatureVerification)); verificationList.add(map(signatureVerification));