From 24a251fbc2a96ce7889b4947fb94bc9f3c470a8b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 30 Jul 2025 13:25:09 +0200 Subject: [PATCH] Checkstyle issues --- .../OpenPgpMessageInputStream.kt | 78 ++++++++++--------- .../pgpainless/signature/SignatureUtils.kt | 6 +- .../fuzzing/PGPObjectFactoryFuzzingTest.kt | 4 +- .../kotlin/org/pgpainless/sop/ArmorImpl.kt | 4 +- .../kotlin/org/pgpainless/sop/DecryptImpl.kt | 9 +-- 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt index fa69b1db..af6034bb 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt @@ -145,11 +145,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) { @@ -212,25 +213,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 } @@ -240,17 +240,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.") @@ -356,7 +354,10 @@ class OpenPgpMessageInputStream( } - 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() @@ -619,13 +620,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) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/SignatureUtils.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/SignatureUtils.kt index dcad42fd..642d96e4 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/SignatureUtils.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/SignatureUtils.kt @@ -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) { diff --git a/pgpainless-core/src/test/kotlin/org/pgpainless/bouncycastle/fuzzing/PGPObjectFactoryFuzzingTest.kt b/pgpainless-core/src/test/kotlin/org/pgpainless/bouncycastle/fuzzing/PGPObjectFactoryFuzzingTest.kt index 05216f44..9a578c4f 100644 --- a/pgpainless-core/src/test/kotlin/org/pgpainless/bouncycastle/fuzzing/PGPObjectFactoryFuzzingTest.kt +++ b/pgpainless-core/src/test/kotlin/org/pgpainless/bouncycastle/fuzzing/PGPObjectFactoryFuzzingTest.kt @@ -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 { diff --git a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/ArmorImpl.kt b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/ArmorImpl.kt index a4e65a3c..a9a2ea96 100644 --- a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/ArmorImpl.kt +++ b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/ArmorImpl.kt @@ -5,6 +5,7 @@ package org.pgpainless.sop import java.io.BufferedOutputStream +import java.io.IOException import java.io.InputStream import java.io.OutputStream import kotlin.jvm.Throws @@ -15,7 +16,6 @@ import org.pgpainless.util.ArmoredOutputStreamFactory import sop.Ready import sop.exception.SOPGPException import sop.operation.Armor -import java.io.IOException /** Implementation of the `armor` operation using PGPainless. */ class ArmorImpl(private val api: PGPainless) : Armor { @@ -28,13 +28,13 @@ class ArmorImpl(private val api: PGPainless) : Armor { val bufferedOutputStream = BufferedOutputStream(outputStream) // Determine the nature of the given data + val openPgpIn = OpenPGPAnimalSnifferInputStream(data).apply { try { inspectBuffer() } catch (e: IOException) { // ignore } - reset() } if (openPgpIn.isAsciiArmored) { diff --git a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/DecryptImpl.kt b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/DecryptImpl.kt index 64720ca1..d7ea4209 100644 --- a/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/DecryptImpl.kt +++ b/pgpainless-sop/src/main/kotlin/org/pgpainless/sop/DecryptImpl.kt @@ -4,11 +4,13 @@ package org.pgpainless.sop -import org.bouncycastle.bcpg.UnsupportedPacketVersionException import java.io.IOException import java.io.InputStream import java.io.OutputStream import java.util.* +import java.util.zip.ZipException +import kotlin.NoSuchElementException +import org.bouncycastle.bcpg.UnsupportedPacketVersionException import org.bouncycastle.openpgp.PGPException import org.bouncycastle.util.io.Streams import org.pgpainless.PGPainless @@ -23,8 +25,6 @@ import sop.ReadyWithResult import sop.SessionKey import sop.exception.SOPGPException import sop.operation.Decrypt -import java.util.zip.ZipException -import kotlin.NoSuchElementException /** Implementation of the `decrypt` operation using PGPainless. */ class DecryptImpl(private val api: PGPainless) : Decrypt { @@ -57,8 +57,7 @@ class DecryptImpl(private val api: PGPainless) : Decrypt { throw SOPGPException.BadData(e) } catch (e: ModificationDetectionException) { throw SOPGPException.BadData(e) - } - finally { + } finally { // Forget passphrases after decryption protector.clear() }