Skip to content

Commit 8693881

Browse files
author
gefeili
committed
Fix the bug in SignaturePacket
1 parent 913790c commit 8693881

File tree

1 file changed

+8
-60
lines changed

1 file changed

+8
-60
lines changed

pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ else if (p instanceof SignatureCreationTime)
197197

198198
unhashedData[i] = p;
199199
}
200+
201+
setIssuerKeyId();
202+
setCreationTime();
200203
}
201204

202205
private Vector<SignatureSubpacket> readSignatureSubpacketVector(BCPGInputStream in)
@@ -211,77 +214,22 @@ private Vector<SignatureSubpacket> readSignatureSubpacketVector(BCPGInputStream
211214
{
212215
hashedLength = StreamUtil.read2OctetLength(in);
213216
}
214-
byte[] hashed = new byte[hashedLength];
217+
byte[] hashed = new byte[hashedLength];
215218

216219
in.readFully(hashed);
217220

218221
//
219222
// read the signature sub packet data.
220223
//
221-
SignatureSubpacket sub;
222-
SignatureSubpacketInputStream sIn = new SignatureSubpacketInputStream(
223-
new ByteArrayInputStream(hashed));
224-
225-
Vector<SignatureSubpacket> vec = new Vector<SignatureSubpacket>();
226-
while ((sub = sIn.readPacket()) != null)
227-
{
228-
vec.addElement(sub);
229-
}
230-
231-
hashedData = new SignatureSubpacket[vec.size()];
232-
233-
for (int i = 0; i != hashedData.length; i++)
234-
{
235-
SignatureSubpacket p = vec.elementAt(i);
236-
if (p instanceof IssuerKeyID)
237-
{
238-
keyID = ((IssuerKeyID)p).getKeyID();
239-
}
240-
else if (p instanceof SignatureCreationTime)
241-
{
242-
creationTime = ((SignatureCreationTime)p).getTime().getTime();
243-
}
244-
245-
hashedData[i] = p;
246-
}
224+
SignatureSubpacket sub;
225+
SignatureSubpacketInputStream sIn = new SignatureSubpacketInputStream(
226+
new ByteArrayInputStream(hashed));
247227

248-
int unhashedLength;
249-
if (version == VERSION_6)
250-
{
251-
unhashedLength = StreamUtil.read4OctetLength(in);
252-
}
253-
else
254-
{
255-
unhashedLength = StreamUtil.read2OctetLength(in);
256-
}
257-
byte[] unhashed = new byte[unhashedLength];
258-
259-
in.readFully(unhashed);
260-
261-
sIn = new SignatureSubpacketInputStream(
262-
new ByteArrayInputStream(unhashed));
263-
264-
vec.removeAllElements();
228+
Vector<SignatureSubpacket> vec = new Vector<SignatureSubpacket>();
265229
while ((sub = sIn.readPacket()) != null)
266230
{
267231
vec.addElement(sub);
268232
}
269-
270-
unhashedData = new SignatureSubpacket[vec.size()];
271-
272-
for (int i = 0; i != unhashedData.length; i++)
273-
{
274-
SignatureSubpacket p = vec.elementAt(i);
275-
if (p instanceof IssuerKeyID)
276-
{
277-
keyID = ((IssuerKeyID)p).getKeyID();
278-
}
279-
280-
unhashedData[i] = p;
281-
}
282-
283-
setIssuerKeyId();
284-
setCreationTime();
285233
return vec;
286234
}
287235

0 commit comments

Comments
 (0)