From e5f14e789a391bb1ed89e78943a25eed12943334 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 26 Jun 2017 13:23:52 +0200 Subject: [PATCH] ECDSASignature.decodeFromDER(): Now throws IllegalArgumentException if something with the input bytes is wrong. RuntimeException is bad! --- core/src/main/java/org/bitcoinj/core/ECKey.java | 6 +++--- .../main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/ECKey.java b/core/src/main/java/org/bitcoinj/core/ECKey.java index a796d0cc..8d3d15f6 100644 --- a/core/src/main/java/org/bitcoinj/core/ECKey.java +++ b/core/src/main/java/org/bitcoinj/core/ECKey.java @@ -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) {} diff --git a/core/src/main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java b/core/src/main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java index 80714ce9..021379bd 100644 --- a/core/src/main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java +++ b/core/src/main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java @@ -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; }