Skip to content

Commit

Permalink
Add fromInputStream() methods for OpenPGPKey and OpenPGPCertificate
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Dec 17, 2024
1 parent 9649377 commit efed5a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bouncycastle.openpgp.api.exception.MissingIssuerCertException;
import org.bouncycastle.openpgp.api.util.UTCUtil;
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
import org.bouncycastle.util.io.Streams;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -126,6 +127,25 @@ public static OpenPGPCertificate fromAsciiArmor(
implementation);
}

public static OpenPGPCertificate fromInputStream(InputStream inputStream)
throws IOException
{
return fromInputStream(inputStream, OpenPGPImplementation.getInstance());
}

public static OpenPGPCertificate fromInputStream(InputStream inputStream, OpenPGPImplementation implementation)
throws IOException
{
byte[] bytes = Streams.readAll(inputStream);
return fromBytes(bytes, implementation);
}

public static OpenPGPCertificate fromBytes(byte[] bytes)
throws IOException
{
return fromBytes(bytes, OpenPGPImplementation.getInstance());
}

public static OpenPGPCertificate fromBytes(
byte[] bytes,
OpenPGPImplementation implementation)
Expand Down
20 changes: 20 additions & 0 deletions pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptorBuilderProvider;
import org.bouncycastle.util.io.Streams;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -112,6 +113,25 @@ public static OpenPGPKey fromAsciiArmor(
implementation);
}

public static OpenPGPKey fromInputStream(InputStream inputStream)
throws IOException
{
return fromInputStream(inputStream, OpenPGPImplementation.getInstance());
}

public static OpenPGPKey fromInputStream(InputStream inputStream, OpenPGPImplementation implementation)
throws IOException
{
return fromBytes(Streams.readAll(inputStream), implementation);
}

public static OpenPGPKey fromBytes(
byte[] bytes)
throws IOException
{
return fromBytes(bytes, OpenPGPImplementation.getInstance());
}

public static OpenPGPKey fromBytes(
byte[] bytes,
OpenPGPImplementation implementation)
Expand Down

0 comments on commit efed5a3

Please sign in to comment.