mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-05 20:15:59 +01:00
Add comments
This commit is contained in:
parent
d5fcb3bc29
commit
d94fa6b74b
2 changed files with 13 additions and 3 deletions
|
@ -116,6 +116,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
/**
|
/**
|
||||||
* Create an {@link OpenPgpMessageInputStream} suitable for decryption and verification of
|
* Create an {@link OpenPgpMessageInputStream} suitable for decryption and verification of
|
||||||
* OpenPGP messages and signatures.
|
* OpenPGP messages and signatures.
|
||||||
|
* This factory method takes a custom {@link Policy} instead of using the global policy object.
|
||||||
*
|
*
|
||||||
* @param inputStream underlying input stream containing the OpenPGP message
|
* @param inputStream underlying input stream containing the OpenPGP message
|
||||||
* @param options options for consuming the message
|
* @param options options for consuming the message
|
||||||
|
@ -161,7 +162,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
armorIn, options, metadata, policy);
|
armorIn, options, metadata, policy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("Huh?");
|
throw new AssertionError("Cannot deduce type of data.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +213,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
|
// Binary OpenPGP Message
|
||||||
case standard:
|
case standard:
|
||||||
// tee out packet bytes for signature verification
|
// tee out packet bytes for signature verification
|
||||||
packetInputStream = new TeeBCPGInputStream(BCPGInputStream.wrap(inputStream), this.signatures);
|
packetInputStream = new TeeBCPGInputStream(BCPGInputStream.wrap(inputStream), this.signatures);
|
||||||
|
@ -220,6 +222,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
consumePackets();
|
consumePackets();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Cleartext Signature Framework (probably signed message)
|
||||||
case cleartext_signed:
|
case cleartext_signed:
|
||||||
resultBuilder.setCleartextSigned();
|
resultBuilder.setCleartextSigned();
|
||||||
MultiPassStrategy multiPassStrategy = options.getMultiPassStrategy();
|
MultiPassStrategy multiPassStrategy = options.getMultiPassStrategy();
|
||||||
|
@ -235,6 +238,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
nestedInputStream = new TeeInputStream(multiPassStrategy.getMessageInputStream(), this.signatures);
|
nestedInputStream = new TeeInputStream(multiPassStrategy.getMessageInputStream(), this.signatures);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Non-OpenPGP Data (e.g. detached signature verification)
|
||||||
case non_openpgp:
|
case non_openpgp:
|
||||||
packetInputStream = null;
|
packetInputStream = null;
|
||||||
nestedInputStream = new TeeInputStream(inputStream, this.signatures);
|
nestedInputStream = new TeeInputStream(inputStream, this.signatures);
|
||||||
|
@ -265,7 +269,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop: // we break this when we go deeper.
|
loop: // we break this when we enter nested packets and later resume
|
||||||
while ((nextPacket = packetInputStream.nextPacketTag()) != null) {
|
while ((nextPacket = packetInputStream.nextPacketTag()) != null) {
|
||||||
signatures.nextPacket(nextPacket);
|
signatures.nextPacket(nextPacket);
|
||||||
switch (nextPacket) {
|
switch (nextPacket) {
|
||||||
|
@ -296,6 +300,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
case SED:
|
case SED:
|
||||||
case SEIPD:
|
case SEIPD:
|
||||||
if (processEncryptedData()) {
|
if (processEncryptedData()) {
|
||||||
|
// Successfully decrypted, enter nested content
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +341,12 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
LOGGER.debug("Literal Data Packet at depth " + metadata.depth + " encountered");
|
LOGGER.debug("Literal Data Packet at depth " + metadata.depth + " encountered");
|
||||||
syntaxVerifier.next(InputSymbol.LiteralData);
|
syntaxVerifier.next(InputSymbol.LiteralData);
|
||||||
PGPLiteralData literalData = packetInputStream.readLiteralData();
|
PGPLiteralData literalData = packetInputStream.readLiteralData();
|
||||||
|
// Extract Metadata
|
||||||
this.metadata.setChild(new MessageMetadata.LiteralData(
|
this.metadata.setChild(new MessageMetadata.LiteralData(
|
||||||
literalData.getFileName(),
|
literalData.getFileName(),
|
||||||
literalData.getModificationTime(),
|
literalData.getModificationTime(),
|
||||||
StreamEncoding.requireFromCode(literalData.getFormat())));
|
StreamEncoding.requireFromCode(literalData.getFormat())));
|
||||||
|
|
||||||
nestedInputStream = literalData.getDataStream();
|
nestedInputStream = literalData.getDataStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,9 +354,11 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
syntaxVerifier.next(InputSymbol.CompressedData);
|
syntaxVerifier.next(InputSymbol.CompressedData);
|
||||||
signatures.enterNesting();
|
signatures.enterNesting();
|
||||||
PGPCompressedData compressedData = packetInputStream.readCompressedData();
|
PGPCompressedData compressedData = packetInputStream.readCompressedData();
|
||||||
|
// Extract Metadata
|
||||||
MessageMetadata.CompressedData compressionLayer = new MessageMetadata.CompressedData(
|
MessageMetadata.CompressedData compressionLayer = new MessageMetadata.CompressedData(
|
||||||
CompressionAlgorithm.fromId(compressedData.getAlgorithm()),
|
CompressionAlgorithm.fromId(compressedData.getAlgorithm()),
|
||||||
metadata.depth + 1);
|
metadata.depth + 1);
|
||||||
|
|
||||||
LOGGER.debug("Compressed Data Packet (" + compressionLayer.algorithm + ") at depth " + metadata.depth + " encountered");
|
LOGGER.debug("Compressed Data Packet (" + compressionLayer.algorithm + ") at depth " + metadata.depth + " encountered");
|
||||||
InputStream decompressed = compressedData.getDataStream();
|
InputStream decompressed = compressedData.getDataStream();
|
||||||
nestedInputStream = new OpenPgpMessageInputStream(decompressed, options, compressionLayer, policy);
|
nestedInputStream = new OpenPgpMessageInputStream(decompressed, options, compressionLayer, policy);
|
||||||
|
@ -374,6 +383,7 @@ public class OpenPgpMessageInputStream extends DecryptionStream {
|
||||||
LOGGER.debug("Unsupported Signature at depth " + metadata.depth + " encountered.", e);
|
LOGGER.debug("Unsupported Signature at depth " + metadata.depth + " encountered.", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long keyId = SignatureUtils.determineIssuerKeyId(signature);
|
long keyId = SignatureUtils.determineIssuerKeyId(signature);
|
||||||
if (isSigForOPS) {
|
if (isSigForOPS) {
|
||||||
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key " +
|
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key " +
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class PDA {
|
||||||
private State state;
|
private State state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Default constructor which initializes the PDA to work with the {@link OpenPgpMessageSyntax}.
|
||||||
*/
|
*/
|
||||||
public PDA() {
|
public PDA() {
|
||||||
this(new OpenPgpMessageSyntax(), State.OpenPgpMessage, terminus, msg);
|
this(new OpenPgpMessageSyntax(), State.OpenPgpMessage, terminus, msg);
|
||||||
|
|
Loading…
Reference in a new issue