1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-10 18:59:39 +02:00

Checkstyle issues

This commit is contained in:
Paul Schaub 2025-07-30 13:25:09 +02:00
parent fed6cbcd6e
commit 4b179d750a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 59 additions and 57 deletions

View file

@ -139,11 +139,12 @@ class OpenPgpMessageInputStream(
// Comsume packets, potentially stepping into nested layers
layer@ while (run {
packet = try {
pIn.nextPacketTag()
} catch (e: NoSuchElementException) {
throw MalformedOpenPgpMessageException(e.message)
}
packet =
try {
pIn.nextPacketTag()
} catch (e: NoSuchElementException) {
throw MalformedOpenPgpMessageException(e.message)
}
packet
} != null) {
@ -210,25 +211,24 @@ class OpenPgpMessageInputStream(
syntaxVerifier.next(InputSymbol.LITERAL_DATA)
val literalData = packetInputStream!!.readLiteralData()
val streamEncoding = try {
StreamEncoding.requireFromCode(literalData.format)
} catch (e: NoSuchElementException) {
throw PGPException("Invalid stream encoding format encountered: ${literalData.format}; ${e.message}")
}
val streamEncoding =
try {
StreamEncoding.requireFromCode(literalData.format)
} catch (e: NoSuchElementException) {
throw PGPException(
"Invalid stream encoding format encountered: ${literalData.format}; ${e.message}")
}
val fileName = try {
literalData.fileName
} catch (e: IllegalArgumentException) {
// Non UTF8
throw PGPException("Cannot decode literal data filename: ${e.message}")
}
val fileName =
try {
literalData.fileName
} catch (e: IllegalArgumentException) {
// Non UTF8
throw PGPException("Cannot decode literal data filename: ${e.message}")
}
// Extract Metadata
layerMetadata.child =
LiteralData(
fileName,
literalData.modificationTime,
streamEncoding)
layerMetadata.child = LiteralData(fileName, literalData.modificationTime, streamEncoding)
nestedInputStream = literalData.inputStream
}
@ -238,17 +238,15 @@ class OpenPgpMessageInputStream(
signatures.enterNesting()
val compressedData = packetInputStream!!.readCompressedData()
val compAlg = try {
CompressionAlgorithm.requireFromId(compressedData.algorithm)
} catch (e: NoSuchElementException) {
throw PGPException(e.message)
}
val compAlg =
try {
CompressionAlgorithm.requireFromId(compressedData.algorithm)
} catch (e: NoSuchElementException) {
throw PGPException(e.message)
}
// Extract Metadata
val compressionLayer =
CompressedData(
compAlg,
layerMetadata.depth + 1)
val compressionLayer = CompressedData(compAlg, layerMetadata.depth + 1)
LOGGER.debug(
"Compressed Data Packet (${compressionLayer.algorithm}) at depth ${layerMetadata.depth} encountered.")
@ -347,7 +345,9 @@ class OpenPgpMessageInputStream(
"Symmetrically Encrypted Data Packet at depth ${layerMetadata.depth} encountered.")
syntaxVerifier.next(InputSymbol.ENCRYPTED_DATA)
val encDataList = packetInputStream!!.readEncryptedDataList()
if (!encDataList.isIntegrityProtected && !encDataList.isEmpty && !encDataList.get(0).isAEAD) {
if (!encDataList.isIntegrityProtected &&
!encDataList.isEmpty &&
!encDataList.get(0).isAEAD) {
LOGGER.warn("Symmetrically Encrypted Data Packet is not integrity-protected.")
if (!options.isIgnoreMDCErrors()) {
throw MessageNotIntegrityProtectedException()
@ -569,13 +569,14 @@ class OpenPgpMessageInputStream(
pkesk: PGPPublicKeyEncryptedData
): Boolean {
try {
val decrypted = try {
pkesk.getDataStream(decryptorFactory)
} catch (e: ClassCastException) {
throw PGPException(e.message)
} catch (e: IllegalArgumentException) {
throw PGPException(e.message)
}
val decrypted =
try {
pkesk.getDataStream(decryptorFactory)
} catch (e: ClassCastException) {
throw PGPException(e.message)
} catch (e: IllegalArgumentException) {
throw PGPException(e.message)
}
val sessionKey = SessionKey(pkesk.getSessionKey(decryptorFactory))
throwIfUnacceptable(sessionKey.algorithm)

View file

@ -165,13 +165,13 @@ class SignatureUtils {
// having them compressed,
// except for an attacker who is trying to exploit flaws in the decompression
// algorithm.
// Therefore, we ignore compressed data packets without attempting decompression.
// Therefore, we ignore compressed data packets without attempting
// decompression.
if (nextObject is PGPCompressedData) {
// getInputStream() does not do decompression, contrary to getDataStream().
Streams.drain(
(nextObject as PGPCompressedData)
.inputStream
) // Skip packet without decompressing
.inputStream) // Skip packet without decompressing
}
if (nextObject is PGPSignatureList) {

View file

@ -247,7 +247,8 @@ class ArmorUtils {
.add(OpenPgpFingerprint.of(publicKey).prettyPrint())
// Primary / First User ID
(primary ?: first)?.let {
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }
headerMap
.getOrPut(HEADER_COMMENT) { mutableSetOf() }
.add(it.replace("\n", "\\n").replace("\r", "\\r"))
}
// X-1 further identities

View file

@ -6,13 +6,13 @@ package org.pgpainless.bouncycastle.fuzzing
import com.code_intelligence.jazzer.api.FuzzedDataProvider
import com.code_intelligence.jazzer.junit.FuzzTest
import java.io.EOFException
import java.io.IOException
import org.bouncycastle.bcpg.ArmoredInputException
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.openpgp.PGPUtil
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory
import java.io.EOFException
import java.io.IOException
class PGPObjectFactoryFuzzingTest {