Add decoder methods

This commit is contained in:
Paul Schaub 2018-06-26 15:18:01 +02:00
parent b08c34e9c9
commit eadc023940
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 25 additions and 0 deletions

View File

@ -15,7 +15,10 @@
*/
package de.vanitasvitae.crypto.pgpainless.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@ -39,6 +42,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.util.io.Streams;
public class BCUtil {
@ -113,6 +118,26 @@ public class BCUtil {
return removeUnsignedKeysFromKeyRing(collection.getPublicKeyRing(id), id);
}
public static InputStream getPgpDecoderInputStream(byte[] bytes) throws IOException {
return getPgpDecoderInputStream(new ByteArrayInputStream(bytes));
}
public static InputStream getPgpDecoderInputStream(InputStream inputStream) throws IOException {
return PGPUtil.getDecoderStream(inputStream);
}
public static byte[] getDecodedBytes(byte[] bytes) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Streams.pipeAll(getPgpDecoderInputStream(bytes), buffer);
return buffer.toByteArray();
}
public static byte[] getDecodedBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Streams.pipeAll(inputStream, buffer);
return getDecodedBytes(buffer.toByteArray());
}
public static PGPPublicKeyRing removeUnsignedKeysFromKeyRing(PGPPublicKeyRing ring, Long masterKeyId) {
Set<Long> signedKeyIds = new HashSet<>();