ECDSASignature.decodeFromDER(): Now throws IllegalArgumentException if something with the input bytes is wrong. RuntimeException is bad!

This commit is contained in:
Andreas Schildbach 2017-06-26 13:23:52 +02:00
parent 0eabd240a6
commit e5f14e789a
2 changed files with 4 additions and 4 deletions

View file

@ -574,13 +574,13 @@ public class ECKey implements EncryptableItem {
}
}
public static ECDSASignature decodeFromDER(byte[] bytes) {
public static ECDSASignature decodeFromDER(byte[] bytes) throws IllegalArgumentException {
ASN1InputStream decoder = null;
try {
decoder = new ASN1InputStream(bytes);
DLSequence seq = (DLSequence) decoder.readObject();
if (seq == null)
throw new RuntimeException("Reached past end of ASN.1 stream.");
throw new IllegalArgumentException("Reached past end of ASN.1 stream.");
ASN1Integer r, s;
try {
r = (ASN1Integer) seq.getObjectAt(0);
@ -592,7 +592,7 @@ public class ECKey implements EncryptableItem {
// Thus, we always use the positive versions. See: http://r6.ca/blog/20111119T211504Z.html
return new ECDSASignature(r.getPositiveValue(), s.getPositiveValue());
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
} finally {
if (decoder != null)
try { decoder.close(); } catch (IOException x) {}

View file

@ -183,7 +183,7 @@ public class DefaultRiskAnalysis implements RiskAnalysis {
ECDSASignature signature;
try {
signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
} catch (RuntimeException x) {
} catch (IllegalArgumentException x) {
// Doesn't look like a signature.
signature = null;
}