Skip to content

Commit efed5a3

Browse files
committed
Add fromInputStream() methods for OpenPGPKey and OpenPGPCertificate
1 parent 9649377 commit efed5a3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPCertificate.java

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.bouncycastle.openpgp.api.exception.MissingIssuerCertException;
1919
import org.bouncycastle.openpgp.api.util.UTCUtil;
2020
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
21+
import org.bouncycastle.util.io.Streams;
2122

2223
import java.io.ByteArrayInputStream;
2324
import java.io.ByteArrayOutputStream;
@@ -126,6 +127,25 @@ public static OpenPGPCertificate fromAsciiArmor(
126127
implementation);
127128
}
128129

130+
public static OpenPGPCertificate fromInputStream(InputStream inputStream)
131+
throws IOException
132+
{
133+
return fromInputStream(inputStream, OpenPGPImplementation.getInstance());
134+
}
135+
136+
public static OpenPGPCertificate fromInputStream(InputStream inputStream, OpenPGPImplementation implementation)
137+
throws IOException
138+
{
139+
byte[] bytes = Streams.readAll(inputStream);
140+
return fromBytes(bytes, implementation);
141+
}
142+
143+
public static OpenPGPCertificate fromBytes(byte[] bytes)
144+
throws IOException
145+
{
146+
return fromBytes(bytes, OpenPGPImplementation.getInstance());
147+
}
148+
129149
public static OpenPGPCertificate fromBytes(
130150
byte[] bytes,
131151
OpenPGPImplementation implementation)

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKey.java

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.bouncycastle.openpgp.PGPUtil;
1515
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
1616
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptorBuilderProvider;
17+
import org.bouncycastle.util.io.Streams;
1718

1819
import java.io.ByteArrayInputStream;
1920
import java.io.ByteArrayOutputStream;
@@ -112,6 +113,25 @@ public static OpenPGPKey fromAsciiArmor(
112113
implementation);
113114
}
114115

116+
public static OpenPGPKey fromInputStream(InputStream inputStream)
117+
throws IOException
118+
{
119+
return fromInputStream(inputStream, OpenPGPImplementation.getInstance());
120+
}
121+
122+
public static OpenPGPKey fromInputStream(InputStream inputStream, OpenPGPImplementation implementation)
123+
throws IOException
124+
{
125+
return fromBytes(Streams.readAll(inputStream), implementation);
126+
}
127+
128+
public static OpenPGPKey fromBytes(
129+
byte[] bytes)
130+
throws IOException
131+
{
132+
return fromBytes(bytes, OpenPGPImplementation.getInstance());
133+
}
134+
115135
public static OpenPGPKey fromBytes(
116136
byte[] bytes,
117137
OpenPGPImplementation implementation)

0 commit comments

Comments
 (0)