mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
Improve readability of DecryptionStreamFactory
This commit is contained in:
parent
90e0f74aea
commit
ba0e5eb3fe
1 changed files with 12 additions and 8 deletions
|
@ -87,6 +87,13 @@ public final class DecryptionStreamFactory {
|
||||||
private final Map<OpenPgpV4Fingerprint, OnePassSignature> verifiableOnePassSignatures = new HashMap<>();
|
private final Map<OpenPgpV4Fingerprint, OnePassSignature> verifiableOnePassSignatures = new HashMap<>();
|
||||||
private IntegrityProtectedInputStream integrityProtectedEncryptedInputStream;
|
private IntegrityProtectedInputStream integrityProtectedEncryptedInputStream;
|
||||||
|
|
||||||
|
public static DecryptionStream create(@Nonnull InputStream inputStream,
|
||||||
|
@Nonnull ConsumerOptions options)
|
||||||
|
throws PGPException, IOException {
|
||||||
|
DecryptionStreamFactory factory = new DecryptionStreamFactory(options);
|
||||||
|
return factory.parseOpenPGPDataAndCreateDecryptionStream(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
public DecryptionStreamFactory(ConsumerOptions options) {
|
public DecryptionStreamFactory(ConsumerOptions options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
initializeDetachedSignatures(options.getDetachedSignatures());
|
initializeDetachedSignatures(options.getDetachedSignatures());
|
||||||
|
@ -111,12 +118,9 @@ public final class DecryptionStreamFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DecryptionStream create(@Nonnull InputStream inputStream,
|
private DecryptionStream parseOpenPGPDataAndCreateDecryptionStream(InputStream inputStream) throws IOException, PGPException {
|
||||||
@Nonnull ConsumerOptions options)
|
|
||||||
throws PGPException, IOException {
|
|
||||||
BufferedInputStream bufferedIn = new BufferedInputStream(inputStream);
|
BufferedInputStream bufferedIn = new BufferedInputStream(inputStream);
|
||||||
bufferedIn.mark(200);
|
bufferedIn.mark(200);
|
||||||
DecryptionStreamFactory factory = new DecryptionStreamFactory(options);
|
|
||||||
|
|
||||||
InputStream decoderStream = PGPUtil.getDecoderStream(bufferedIn);
|
InputStream decoderStream = PGPUtil.getDecoderStream(bufferedIn);
|
||||||
decoderStream = CRCingArmoredInputStreamWrapper.possiblyWrap(decoderStream);
|
decoderStream = CRCingArmoredInputStreamWrapper.possiblyWrap(decoderStream);
|
||||||
|
@ -135,7 +139,7 @@ public final class DecryptionStreamFactory {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse OpenPGP message
|
// Parse OpenPGP message
|
||||||
inputStream = factory.processPGPPackets(objectFactory, 1);
|
inputStream = processPGPPackets(objectFactory, 1);
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@ public final class DecryptionStreamFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DecryptionStream(inputStream, options, factory.resultBuilder, factory.integrityProtectedEncryptedInputStream,
|
return new DecryptionStream(inputStream, options, resultBuilder, integrityProtectedEncryptedInputStream,
|
||||||
(decoderStream instanceof ArmoredInputStream) ? decoderStream : null);
|
(decoderStream instanceof ArmoredInputStream) ? decoderStream : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +191,7 @@ public final class DecryptionStreamFactory {
|
||||||
private InputStream processPGPEncryptedDataList(PGPEncryptedDataList pgpEncryptedDataList, int depth)
|
private InputStream processPGPEncryptedDataList(PGPEncryptedDataList pgpEncryptedDataList, int depth)
|
||||||
throws PGPException, IOException {
|
throws PGPException, IOException {
|
||||||
LOGGER.debug("Depth {}: Encountered PGPEncryptedDataList", depth);
|
LOGGER.debug("Depth {}: Encountered PGPEncryptedDataList", depth);
|
||||||
InputStream decryptedDataStream = decrypt(pgpEncryptedDataList);
|
InputStream decryptedDataStream = decryptSessionKey(pgpEncryptedDataList);
|
||||||
InputStream decodedDataStream = PGPUtil.getDecoderStream(decryptedDataStream);
|
InputStream decodedDataStream = PGPUtil.getDecoderStream(decryptedDataStream);
|
||||||
PGPObjectFactory factory = new PGPObjectFactory(decodedDataStream, keyFingerprintCalculator);
|
PGPObjectFactory factory = new PGPObjectFactory(decodedDataStream, keyFingerprintCalculator);
|
||||||
return processPGPPackets(factory, ++depth);
|
return processPGPPackets(factory, ++depth);
|
||||||
|
@ -230,7 +234,7 @@ public final class DecryptionStreamFactory {
|
||||||
objectFactory, verifiableOnePassSignatures, options, resultBuilder);
|
objectFactory, verifiableOnePassSignatures, options, resultBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream decrypt(@Nonnull PGPEncryptedDataList encryptedDataList)
|
private InputStream decryptSessionKey(@Nonnull PGPEncryptedDataList encryptedDataList)
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
Iterator<PGPEncryptedData> encryptedDataIterator = encryptedDataList.getEncryptedDataObjects();
|
Iterator<PGPEncryptedData> encryptedDataIterator = encryptedDataList.getEncryptedDataObjects();
|
||||||
if (!encryptedDataIterator.hasNext()) {
|
if (!encryptedDataIterator.hasNext()) {
|
||||||
|
|
Loading…
Reference in a new issue