1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-05 11:51:09 +01:00

Checkstyle issues

This commit is contained in:
Paul Schaub 2025-07-30 13:25:09 +02:00
parent 1b1ebc3f43
commit 24a251fbc2
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
5 changed files with 51 additions and 50 deletions

View file

@ -145,7 +145,8 @@ class OpenPgpMessageInputStream(
// Comsume packets, potentially stepping into nested layers // Comsume packets, potentially stepping into nested layers
layer@ while (run { layer@ while (run {
packet = try { packet =
try {
pIn.nextPacketTag() pIn.nextPacketTag()
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
throw MalformedOpenPgpMessageException(e.message) throw MalformedOpenPgpMessageException(e.message)
@ -212,13 +213,16 @@ class OpenPgpMessageInputStream(
syntaxVerifier.next(InputSymbol.LITERAL_DATA) syntaxVerifier.next(InputSymbol.LITERAL_DATA)
val literalData = packetInputStream!!.readLiteralData() val literalData = packetInputStream!!.readLiteralData()
val streamEncoding = try { val streamEncoding =
try {
StreamEncoding.requireFromCode(literalData.format) StreamEncoding.requireFromCode(literalData.format)
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
throw PGPException("Invalid stream encoding format encountered: ${literalData.format}; ${e.message}") throw PGPException(
"Invalid stream encoding format encountered: ${literalData.format}; ${e.message}")
} }
val fileName = try { val fileName =
try {
literalData.fileName literalData.fileName
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
// Non UTF8 // Non UTF8
@ -226,11 +230,7 @@ class OpenPgpMessageInputStream(
} }
// Extract Metadata // Extract Metadata
layerMetadata.child = layerMetadata.child = LiteralData(fileName, literalData.modificationTime, streamEncoding)
LiteralData(
fileName,
literalData.modificationTime,
streamEncoding)
nestedInputStream = literalData.inputStream nestedInputStream = literalData.inputStream
} }
@ -240,17 +240,15 @@ class OpenPgpMessageInputStream(
signatures.enterNesting() signatures.enterNesting()
val compressedData = packetInputStream!!.readCompressedData() val compressedData = packetInputStream!!.readCompressedData()
val compAlg = try { val compAlg =
try {
CompressionAlgorithm.requireFromId(compressedData.algorithm) CompressionAlgorithm.requireFromId(compressedData.algorithm)
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
throw PGPException(e.message) throw PGPException(e.message)
} }
// Extract Metadata // Extract Metadata
val compressionLayer = val compressionLayer = CompressedData(compAlg, layerMetadata.depth + 1)
CompressedData(
compAlg,
layerMetadata.depth + 1)
LOGGER.debug( LOGGER.debug(
"Compressed Data Packet (${compressionLayer.algorithm}) at depth ${layerMetadata.depth} encountered.") "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.") LOGGER.warn("Symmetrically Encrypted Data Packet is not integrity-protected.")
if (!options.isIgnoreMDCErrors()) { if (!options.isIgnoreMDCErrors()) {
throw MessageNotIntegrityProtectedException() throw MessageNotIntegrityProtectedException()
@ -619,7 +620,8 @@ class OpenPgpMessageInputStream(
pkesk: PGPPublicKeyEncryptedData pkesk: PGPPublicKeyEncryptedData
): Boolean { ): Boolean {
try { try {
val decrypted = try { val decrypted =
try {
pkesk.getDataStream(decryptorFactory) pkesk.getDataStream(decryptorFactory)
} catch (e: ClassCastException) { } catch (e: ClassCastException) {
throw PGPException(e.message) throw PGPException(e.message)

View file

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

View file

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

View file

@ -5,6 +5,7 @@
package org.pgpainless.sop package org.pgpainless.sop
import java.io.BufferedOutputStream import java.io.BufferedOutputStream
import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -15,7 +16,6 @@ import org.pgpainless.util.ArmoredOutputStreamFactory
import sop.Ready import sop.Ready
import sop.exception.SOPGPException import sop.exception.SOPGPException
import sop.operation.Armor import sop.operation.Armor
import java.io.IOException
/** Implementation of the `armor` operation using PGPainless. */ /** Implementation of the `armor` operation using PGPainless. */
class ArmorImpl(private val api: PGPainless) : Armor { class ArmorImpl(private val api: PGPainless) : Armor {
@ -28,13 +28,13 @@ class ArmorImpl(private val api: PGPainless) : Armor {
val bufferedOutputStream = BufferedOutputStream(outputStream) val bufferedOutputStream = BufferedOutputStream(outputStream)
// Determine the nature of the given data // Determine the nature of the given data
val openPgpIn = OpenPGPAnimalSnifferInputStream(data).apply { val openPgpIn = OpenPGPAnimalSnifferInputStream(data).apply {
try { try {
inspectBuffer() inspectBuffer()
} catch (e: IOException) { } catch (e: IOException) {
// ignore // ignore
} }
reset()
} }
if (openPgpIn.isAsciiArmored) { if (openPgpIn.isAsciiArmored) {

View file

@ -4,11 +4,13 @@
package org.pgpainless.sop package org.pgpainless.sop
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.* import java.util.*
import java.util.zip.ZipException
import kotlin.NoSuchElementException
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
import org.bouncycastle.openpgp.PGPException import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.util.io.Streams import org.bouncycastle.util.io.Streams
import org.pgpainless.PGPainless import org.pgpainless.PGPainless
@ -23,8 +25,6 @@ import sop.ReadyWithResult
import sop.SessionKey import sop.SessionKey
import sop.exception.SOPGPException import sop.exception.SOPGPException
import sop.operation.Decrypt import sop.operation.Decrypt
import java.util.zip.ZipException
import kotlin.NoSuchElementException
/** Implementation of the `decrypt` operation using PGPainless. */ /** Implementation of the `decrypt` operation using PGPainless. */
class DecryptImpl(private val api: PGPainless) : Decrypt { class DecryptImpl(private val api: PGPainless) : Decrypt {
@ -57,8 +57,7 @@ class DecryptImpl(private val api: PGPainless) : Decrypt {
throw SOPGPException.BadData(e) throw SOPGPException.BadData(e)
} catch (e: ModificationDetectionException) { } catch (e: ModificationDetectionException) {
throw SOPGPException.BadData(e) throw SOPGPException.BadData(e)
} } finally {
finally {
// Forget passphrases after decryption // Forget passphrases after decryption
protector.clear() protector.clear()
} }