mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-10 06:11:08 +01:00
Further sourcing of PGPObjectFactory from ImplementationProvider
This commit is contained in:
parent
60f7a9d9ec
commit
a66b45c3d2
9 changed files with 35 additions and 49 deletions
|
|
@ -37,7 +37,6 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|||
import org.bouncycastle.openpgp.PGPSessionKey;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
|
||||
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
|
||||
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
|
||||
|
|
@ -59,9 +58,9 @@ import org.pgpainless.key.SubkeyIdentifier;
|
|||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.signature.SignatureUtils;
|
||||
import org.pgpainless.signature.consumer.DetachedSignatureCheck;
|
||||
import org.pgpainless.signature.consumer.OnePassSignatureCheck;
|
||||
import org.pgpainless.signature.SignatureUtils;
|
||||
import org.pgpainless.util.CRCingArmoredInputStreamWrapper;
|
||||
import org.pgpainless.util.PGPUtilWrapper;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
|
@ -85,8 +84,6 @@ public final class DecryptionStreamFactory {
|
|||
|
||||
private static final PGPContentVerifierBuilderProvider verifierBuilderProvider =
|
||||
ImplementationFactory.getInstance().getPGPContentVerifierBuilderProvider();
|
||||
private static final KeyFingerPrintCalculator keyFingerprintCalculator =
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
private IntegrityProtectedInputStream integrityProtectedEncryptedInputStream;
|
||||
|
||||
|
||||
|
|
@ -150,7 +147,7 @@ public final class DecryptionStreamFactory {
|
|||
}
|
||||
}
|
||||
|
||||
objectFactory = new PGPObjectFactory(decoderStream, keyFingerprintCalculator);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decoderStream);
|
||||
// Parse OpenPGP message
|
||||
inputStream = processPGPPackets(objectFactory, 1);
|
||||
} catch (EOFException e) {
|
||||
|
|
@ -162,7 +159,7 @@ public final class DecryptionStreamFactory {
|
|||
LOGGER.debug("The message appears to not be an OpenPGP message. This is probably data signed with detached signatures?");
|
||||
bufferedIn.reset();
|
||||
decoderStream = bufferedIn;
|
||||
objectFactory = new PGPObjectFactory(decoderStream, keyFingerprintCalculator);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decoderStream);
|
||||
inputStream = wrapInVerifySignatureStream(bufferedIn, objectFactory);
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().contains("invalid armor") || e.getMessage().contains("invalid header encountered")) {
|
||||
|
|
@ -170,7 +167,7 @@ public final class DecryptionStreamFactory {
|
|||
LOGGER.debug("The message is apparently not armored.");
|
||||
bufferedIn.reset();
|
||||
decoderStream = bufferedIn;
|
||||
objectFactory = new PGPObjectFactory(decoderStream, keyFingerprintCalculator);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decoderStream);
|
||||
inputStream = wrapInVerifySignatureStream(bufferedIn, objectFactory);
|
||||
} else {
|
||||
throw e;
|
||||
|
|
@ -219,13 +216,13 @@ public final class DecryptionStreamFactory {
|
|||
if (sessionKey != null) {
|
||||
integrityProtectedEncryptedInputStream = decryptWithProvidedSessionKey(pgpEncryptedDataList, sessionKey);
|
||||
InputStream decodedDataStream = PGPUtil.getDecoderStream(integrityProtectedEncryptedInputStream);
|
||||
PGPObjectFactory factory = new PGPObjectFactory(decodedDataStream, keyFingerprintCalculator);
|
||||
PGPObjectFactory factory = ImplementationFactory.getInstance().getPGPObjectFactory(decodedDataStream);
|
||||
return processPGPPackets(factory, ++depth);
|
||||
}
|
||||
|
||||
InputStream decryptedDataStream = decryptSessionKey(pgpEncryptedDataList);
|
||||
InputStream decodedDataStream = PGPUtil.getDecoderStream(decryptedDataStream);
|
||||
PGPObjectFactory factory = new PGPObjectFactory(decodedDataStream, keyFingerprintCalculator);
|
||||
PGPObjectFactory factory = ImplementationFactory.getInstance().getPGPObjectFactory(decodedDataStream);
|
||||
return processPGPPackets(factory, ++depth);
|
||||
}
|
||||
|
||||
|
|
@ -269,7 +266,7 @@ public final class DecryptionStreamFactory {
|
|||
|
||||
InputStream inflatedDataStream = pgpCompressedData.getDataStream();
|
||||
InputStream decodedDataStream = PGPUtil.getDecoderStream(inflatedDataStream);
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(decodedDataStream, keyFingerprintCalculator);
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decodedDataStream);
|
||||
|
||||
return processPGPPackets(objectFactory, ++depth);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import org.bouncycastle.openpgp.PGPOnePassSignatureList;
|
|||
import org.bouncycastle.openpgp.PGPPBEEncryptedData;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
|
||||
|
|
@ -101,8 +100,7 @@ public final class MessageInspector {
|
|||
}
|
||||
|
||||
private static void processMessage(InputStream dataIn, EncryptionInfo info) throws PGPException, IOException {
|
||||
KeyFingerPrintCalculator calculator = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(dataIn, calculator);
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(dataIn);
|
||||
|
||||
Object next;
|
||||
while ((next = objectFactory.nextObject()) != null) {
|
||||
|
|
@ -131,7 +129,8 @@ public final class MessageInspector {
|
|||
if (next instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressed = (PGPCompressedData) next;
|
||||
InputStream decompressed = compressed.getDataStream();
|
||||
objectFactory = new PGPObjectFactory(PGPUtil.getDecoderStream(decompressed), calculator);
|
||||
InputStream decoded = PGPUtil.getDecoderStream(decompressed);
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decoded);
|
||||
}
|
||||
|
||||
if (next instanceof PGPLiteralData) {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public final class ClearsignedMessageUtil {
|
|||
out.close();
|
||||
}
|
||||
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(in, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(in);
|
||||
PGPSignatureList signatures = (PGPSignatureList) objectFactory.nextObject();
|
||||
|
||||
return signatures;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class PGPKeyRingCollection {
|
|||
public PGPKeyRingCollection(@Nonnull InputStream in, boolean isSilent) throws IOException, PGPException {
|
||||
// Double getDecoderStream because of #96
|
||||
InputStream decoderStream = ArmorUtils.getDecoderStream(in);
|
||||
PGPObjectFactory pgpFact = new PGPObjectFactory(decoderStream, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory pgpFact = ImplementationFactory.getInstance().getPGPObjectFactory(decoderStream);
|
||||
Object obj;
|
||||
|
||||
List<PGPSecretKeyRing> secretKeyRings = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -108,9 +108,8 @@ public class KeyRingReader {
|
|||
* @return public key ring
|
||||
*/
|
||||
public static PGPPublicKeyRing readPublicKeyRing(@Nonnull InputStream inputStream, int maxIterations) throws IOException {
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream),
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream));
|
||||
int i = 0;
|
||||
Object next;
|
||||
do {
|
||||
|
|
@ -146,9 +145,8 @@ public class KeyRingReader {
|
|||
*/
|
||||
public static PGPPublicKeyRingCollection readPublicKeyRingCollection(@Nonnull InputStream inputStream, int maxIterations)
|
||||
throws IOException, PGPException {
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream),
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream));
|
||||
|
||||
List<PGPPublicKeyRing> rings = new ArrayList<>();
|
||||
int i = 0;
|
||||
|
|
@ -191,9 +189,7 @@ public class KeyRingReader {
|
|||
*/
|
||||
public static PGPSecretKeyRing readSecretKeyRing(@Nonnull InputStream inputStream, int maxIterations) throws IOException {
|
||||
InputStream decoderStream = ArmorUtils.getDecoderStream(inputStream);
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(
|
||||
decoderStream,
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(decoderStream);
|
||||
int i = 0;
|
||||
Object next;
|
||||
do {
|
||||
|
|
@ -230,9 +226,8 @@ public class KeyRingReader {
|
|||
public static PGPSecretKeyRingCollection readSecretKeyRingCollection(@Nonnull InputStream inputStream,
|
||||
int maxIterations)
|
||||
throws IOException, PGPException {
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream),
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
|
||||
ArmorUtils.getDecoderStream(inputStream));
|
||||
|
||||
List<PGPSecretKeyRing> rings = new ArrayList<>();
|
||||
int i = 0;
|
||||
|
|
|
|||
|
|
@ -238,16 +238,14 @@ public final class SignatureUtils {
|
|||
public static List<PGPSignature> readSignatures(InputStream inputStream, int maxIterations) throws IOException, PGPException {
|
||||
List<PGPSignature> signatures = new ArrayList<>();
|
||||
InputStream pgpIn = ArmorUtils.getDecoderStream(inputStream);
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(
|
||||
pgpIn, ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(pgpIn);
|
||||
|
||||
int i = 0;
|
||||
Object nextObject;
|
||||
while (i++ < maxIterations && (nextObject = objectFactory.nextObject()) != null) {
|
||||
if (nextObject instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressedData = (PGPCompressedData) nextObject;
|
||||
objectFactory = new PGPObjectFactory(compressedData.getDataStream(),
|
||||
ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(compressedData.getDataStream());
|
||||
}
|
||||
|
||||
if (nextObject instanceof PGPSignatureList) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue