Skip to content

Commit 66b02f8

Browse files
committed
OpenPGPKeyReader: Use consistent method name parseKeyOrCertificate()
Added new methods as replacement for mis-named 'parseCertificateOrKey()' methods and deprecated old methods
1 parent 126ac9e commit 66b02f8

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public OpenPGPKeyReader(OpenPGPImplementation implementation, OpenPGPPolicy poli
4949
public OpenPGPCertificate parseCertificate(String armored)
5050
throws IOException
5151
{
52-
OpenPGPCertificate certificate = parseCertificateOrKey(armored);
52+
OpenPGPCertificate certificate = parseKeyOrCertificate(armored);
5353
if (certificate instanceof OpenPGPKey)
5454
{
5555
throw new IOException("Could not parse OpenPGPCertificate: Is OpenPGPKey.");
@@ -67,7 +67,7 @@ public OpenPGPCertificate parseCertificate(String armored)
6767
public OpenPGPCertificate parseCertificate(InputStream inputStream)
6868
throws IOException
6969
{
70-
OpenPGPCertificate certificate = parseCertificateOrKey(inputStream);
70+
OpenPGPCertificate certificate = parseKeyOrCertificate(inputStream);
7171
if (certificate instanceof OpenPGPKey)
7272
{
7373
throw new IOException("Could not parse OpenPGPCertificate: Is OpenPGPKey.");
@@ -85,7 +85,7 @@ public OpenPGPCertificate parseCertificate(InputStream inputStream)
8585
public OpenPGPCertificate parseCertificate(byte[] bytes)
8686
throws IOException
8787
{
88-
OpenPGPCertificate certificate = parseCertificateOrKey(bytes);
88+
OpenPGPCertificate certificate = parseKeyOrCertificate(bytes);
8989
if (certificate instanceof OpenPGPKey)
9090
{
9191
throw new IOException("Could not parse OpenPGPCertificate: Is OpenPGPKey.");
@@ -99,11 +99,14 @@ public OpenPGPCertificate parseCertificate(byte[] bytes)
9999
* @param armored ASCII armored string
100100
* @return parsed certificate or key
101101
* @throws IOException if the key or certificate cannot be parsed
102+
*
103+
* @deprecated use {@link #parseKeyOrCertificate(String)} instead.
102104
*/
105+
@Deprecated
103106
public OpenPGPCertificate parseCertificateOrKey(String armored)
104107
throws IOException
105108
{
106-
return parseCertificateOrKey(Strings.toUTF8ByteArray(armored));
109+
return parseKeyOrCertificate(armored);
107110
}
108111

109112
/**
@@ -112,11 +115,14 @@ public OpenPGPCertificate parseCertificateOrKey(String armored)
112115
* @param inputStream input stream containing the ASCII armored or binary key or certificate
113116
* @return parsed certificate or key
114117
* @throws IOException if the key or certificate cannot be parsed
118+
*
119+
* @deprecated use {@link #parseKeyOrCertificate(InputStream)} instead.
115120
*/
121+
@Deprecated
116122
public OpenPGPCertificate parseCertificateOrKey(InputStream inputStream)
117123
throws IOException
118124
{
119-
return parseCertificateOrKey(Streams.readAll(inputStream));
125+
return parseKeyOrCertificate(inputStream);
120126
}
121127

122128
/**
@@ -125,9 +131,51 @@ public OpenPGPCertificate parseCertificateOrKey(InputStream inputStream)
125131
* @param bytes ASCII armored or binary key or certificate
126132
* @return parsed certificate or key
127133
* @throws IOException if the key or certificate cannot be parsed
134+
*
135+
* @deprecated use {@link #parseKeyOrCertificate(byte[])} instead.
128136
*/
137+
@Deprecated
129138
public OpenPGPCertificate parseCertificateOrKey(byte[] bytes)
130139
throws IOException
140+
{
141+
return parseKeyOrCertificate(bytes);
142+
}
143+
144+
/**
145+
* Parse a single {@link OpenPGPCertificate} or {@link OpenPGPKey} from an ASCII armored string.
146+
*
147+
* @param armored ASCII armored string
148+
* @return parsed certificate or key
149+
* @throws IOException if the key or certificate cannot be parsed
150+
*/
151+
public OpenPGPCertificate parseKeyOrCertificate(String armored)
152+
throws IOException
153+
{
154+
return parseKeyOrCertificate(Strings.toUTF8ByteArray(armored));
155+
}
156+
157+
/**
158+
* Parse a single {@link OpenPGPCertificate} or {@link OpenPGPKey} from an {@link InputStream}.
159+
*
160+
* @param inputStream input stream containing the ASCII armored or binary key or certificate
161+
* @return parsed certificate or key
162+
* @throws IOException if the key or certificate cannot be parsed
163+
*/
164+
public OpenPGPCertificate parseKeyOrCertificate(InputStream inputStream)
165+
throws IOException
166+
{
167+
return parseKeyOrCertificate(Streams.readAll(inputStream));
168+
}
169+
170+
/**
171+
* Parse a single {@link OpenPGPCertificate} or {@link OpenPGPKey} from bytes.
172+
*
173+
* @param bytes ASCII armored or binary key or certificate
174+
* @return parsed certificate or key
175+
* @throws IOException if the key or certificate cannot be parsed
176+
*/
177+
public OpenPGPCertificate parseKeyOrCertificate(byte[] bytes)
178+
throws IOException
131179
{
132180
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
133181
InputStream decoderStream = PGPUtil.getDecoderStream(bIn);

0 commit comments

Comments
 (0)