ECKey.decodeFromDER(): Also throws IllegalArgumentException if unexpected class was read.

Fixes a regression that was introduced with commit e5f14e789a.
This commit is contained in:
Andreas Schildbach
2017-08-22 12:01:34 +02:00
parent 9c49fd5692
commit 3ef5f9f2d7

View File

@@ -578,9 +578,12 @@ public class ECKey implements EncryptableItem {
ASN1InputStream decoder = null;
try {
decoder = new ASN1InputStream(bytes);
DLSequence seq = (DLSequence) decoder.readObject();
if (seq == null)
final ASN1Primitive seqObj = decoder.readObject();
if (seqObj == null)
throw new IllegalArgumentException("Reached past end of ASN.1 stream.");
if (!(seqObj instanceof DLSequence))
throw new IllegalArgumentException("Read unexpected class: " + seqObj.getClass().getName());
final DLSequence seq = (DLSequence) seqObj;
ASN1Integer r, s;
try {
r = (ASN1Integer) seq.getObjectAt(0);