mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Add decoder methods
This commit is contained in:
parent
b08c34e9c9
commit
eadc023940
1 changed files with 25 additions and 0 deletions
|
@ -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<>();
|
||||
|
|
Loading…
Reference in a new issue