@@ -180,26 +180,11 @@ private void parseSubpackets(BCPGInputStream in)
180
180
SignatureSubpacket p = (SignatureSubpacket )vec .elementAt (i );
181
181
if (p instanceof IssuerKeyID )
182
182
{
183
- try
184
- {
185
- keyID = ((IssuerKeyID ) p ).getKeyID ();
186
- }
187
- catch (IllegalArgumentException e )
188
- {
189
- // Too short key-id
190
- throw new MalformedPacketException ("Malformed IssuerKeyId subpacket." , e );
191
- }
183
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
192
184
}
193
185
else if (p instanceof SignatureCreationTime )
194
186
{
195
- try
196
- {
197
- creationTime = ((SignatureCreationTime ) p ).getTime ().getTime ();
198
- }
199
- catch (IllegalStateException e )
200
- {
201
- throw new MalformedPacketException ("Malformed SignatureCreationTime subpacket." , e );
202
- }
187
+ creationTime = parseCreationTimeOrThrow ((SignatureCreationTime ) p );
203
188
}
204
189
205
190
hashedData [i ] = p ;
@@ -213,14 +198,7 @@ else if (p instanceof SignatureCreationTime)
213
198
SignatureSubpacket p = (SignatureSubpacket )vec .elementAt (i );
214
199
if (p instanceof IssuerKeyID )
215
200
{
216
- try
217
- {
218
- keyID = ((IssuerKeyID ) p ).getKeyID ();
219
- }
220
- catch (IllegalArgumentException e )
221
- {
222
- throw new MalformedPacketException ("Malformed IssuerKeyID subpacket." , e );
223
- }
201
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
224
202
}
225
203
226
204
unhashedData [i ] = p ;
@@ -230,6 +208,45 @@ else if (p instanceof SignatureCreationTime)
230
208
setCreationTime ();
231
209
}
232
210
211
+ private long parseKeyIdOrThrow (IssuerKeyID keyID )
212
+ throws MalformedPacketException
213
+ {
214
+ try
215
+ {
216
+ return keyID .getKeyID ();
217
+ }
218
+ catch (IllegalArgumentException e )
219
+ {
220
+ throw new MalformedPacketException ("Malformed IssuerKeyID subpacket." , e );
221
+ }
222
+ }
223
+
224
+ private long parseKeyIdOrThrow (IssuerFingerprint fingerprint )
225
+ throws MalformedPacketException
226
+ {
227
+ try
228
+ {
229
+ return fingerprint .getKeyID ();
230
+ }
231
+ catch (IllegalArgumentException e )
232
+ {
233
+ throw new MalformedPacketException ("Malformed IssuerFingerprint subpacket." , e );
234
+ }
235
+ }
236
+
237
+ private long parseCreationTimeOrThrow (SignatureCreationTime creationTime )
238
+ throws MalformedPacketException
239
+ {
240
+ try
241
+ {
242
+ return creationTime .getTime ().getTime ();
243
+ }
244
+ catch (IllegalStateException e )
245
+ {
246
+ throw new MalformedPacketException ("Malformed SignatureCreationTime subpacket." , e );
247
+ }
248
+ }
249
+
233
250
private Vector <SignatureSubpacket > readSignatureSubpacketVector (BCPGInputStream in )
234
251
throws IOException
235
252
{
@@ -779,6 +796,7 @@ private void setCreationTime()
779
796
* Therefore, we can also check the unhashed signature subpacket area.
780
797
*/
781
798
private void setIssuerKeyId ()
799
+ throws MalformedPacketException
782
800
{
783
801
if (keyID != 0L )
784
802
{
@@ -790,12 +808,12 @@ private void setIssuerKeyId()
790
808
SignatureSubpacket p = hashedData [idx ];
791
809
if (p instanceof IssuerKeyID )
792
810
{
793
- keyID = ((IssuerKeyID ) p ). getKeyID ( );
811
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
794
812
return ;
795
813
}
796
814
if (p instanceof IssuerFingerprint )
797
815
{
798
- keyID = ((IssuerFingerprint ) p ). getKeyID ( );
816
+ keyID = parseKeyIdOrThrow ((IssuerFingerprint ) p );
799
817
return ;
800
818
}
801
819
}
@@ -805,12 +823,12 @@ private void setIssuerKeyId()
805
823
SignatureSubpacket p = unhashedData [idx ];
806
824
if (p instanceof IssuerKeyID )
807
825
{
808
- keyID = ((IssuerKeyID ) p ). getKeyID ( );
826
+ keyID = parseKeyIdOrThrow ((IssuerKeyID ) p );
809
827
return ;
810
828
}
811
829
if (p instanceof IssuerFingerprint )
812
830
{
813
- keyID = ((IssuerFingerprint ) p ). getKeyID ( );
831
+ keyID = parseKeyIdOrThrow ((IssuerFingerprint ) p );
814
832
return ;
815
833
}
816
834
}
0 commit comments