@@ -181,26 +181,11 @@ private void parseSubpackets(BCPGInputStream in)
181
181
SignatureSubpacket p = (SignatureSubpacket )vec .elementAt (i );
182
182
if (p instanceof IssuerKeyID )
183
183
{
184
- try
185
- {
186
- keyID = ((IssuerKeyID ) p ).getKeyID ();
187
- }
188
- catch (IllegalArgumentException e )
189
- {
190
- // Too short key-id
191
- throw new MalformedPacketException ("Malformed IssuerKeyId subpacket." , e );
192
- }
184
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
193
185
}
194
186
else if (p instanceof SignatureCreationTime )
195
187
{
196
- try
197
- {
198
- creationTime = ((SignatureCreationTime ) p ).getTime ().getTime ();
199
- }
200
- catch (IllegalStateException e )
201
- {
202
- throw new MalformedPacketException ("Malformed SignatureCreationTime subpacket." , e );
203
- }
188
+ creationTime = parseCreationTimeOrThrow ((SignatureCreationTime ) p );
204
189
}
205
190
206
191
hashedData [i ] = p ;
@@ -214,14 +199,7 @@ else if (p instanceof SignatureCreationTime)
214
199
SignatureSubpacket p = (SignatureSubpacket )vec .elementAt (i );
215
200
if (p instanceof IssuerKeyID )
216
201
{
217
- try
218
- {
219
- keyID = ((IssuerKeyID ) p ).getKeyID ();
220
- }
221
- catch (IllegalArgumentException e )
222
- {
223
- throw new MalformedPacketException ("Malformed IssuerKeyID subpacket." , e );
224
- }
202
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
225
203
}
226
204
227
205
unhashedData [i ] = p ;
@@ -231,6 +209,45 @@ else if (p instanceof SignatureCreationTime)
231
209
setCreationTime ();
232
210
}
233
211
212
+ private long parseKeyIdOrThrow (IssuerKeyID keyID )
213
+ throws MalformedPacketException
214
+ {
215
+ try
216
+ {
217
+ return keyID .getKeyID ();
218
+ }
219
+ catch (IllegalArgumentException e )
220
+ {
221
+ throw new MalformedPacketException ("Malformed IssuerKeyID subpacket." , e );
222
+ }
223
+ }
224
+
225
+ private long parseKeyIdOrThrow (IssuerFingerprint fingerprint )
226
+ throws MalformedPacketException
227
+ {
228
+ try
229
+ {
230
+ return fingerprint .getKeyID ();
231
+ }
232
+ catch (IllegalArgumentException e )
233
+ {
234
+ throw new MalformedPacketException ("Malformed IssuerFingerprint subpacket." , e );
235
+ }
236
+ }
237
+
238
+ private long parseCreationTimeOrThrow (SignatureCreationTime creationTime )
239
+ throws MalformedPacketException
240
+ {
241
+ try
242
+ {
243
+ return creationTime .getTime ().getTime ();
244
+ }
245
+ catch (IllegalStateException e )
246
+ {
247
+ throw new MalformedPacketException ("Malformed SignatureCreationTime subpacket." , e );
248
+ }
249
+ }
250
+
234
251
private Vector <SignatureSubpacket > readSignatureSubpacketVector (BCPGInputStream in )
235
252
throws IOException
236
253
{
@@ -814,6 +831,7 @@ private void setCreationTime()
814
831
* Therefore, we can also check the unhashed signature subpacket area.
815
832
*/
816
833
private void setIssuerKeyId ()
834
+ throws MalformedPacketException
817
835
{
818
836
if (keyID != 0L )
819
837
{
@@ -825,12 +843,12 @@ private void setIssuerKeyId()
825
843
SignatureSubpacket p = hashedData [idx ];
826
844
if (p instanceof IssuerKeyID )
827
845
{
828
- keyID = ((IssuerKeyID ) p ). getKeyID ( );
846
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
829
847
return ;
830
848
}
831
849
if (p instanceof IssuerFingerprint )
832
850
{
833
- keyID = ((IssuerFingerprint ) p ). getKeyID ( );
851
+ keyID = parseKeyIdOrThrow ((IssuerFingerprint ) p );
834
852
return ;
835
853
}
836
854
}
@@ -840,12 +858,12 @@ private void setIssuerKeyId()
840
858
SignatureSubpacket p = unhashedData [idx ];
841
859
if (p instanceof IssuerKeyID )
842
860
{
843
- keyID = ((IssuerKeyID ) p ). getKeyID ( );
861
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
844
862
return ;
845
863
}
846
864
if (p instanceof IssuerFingerprint )
847
865
{
848
- keyID = ((IssuerFingerprint ) p ). getKeyID ( );
866
+ keyID = parseKeyIdOrThrow ((IssuerFingerprint ) p );
849
867
return ;
850
868
}
851
869
}
0 commit comments