mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
ECDSASignature.decodeFromDER(): Now throws IllegalArgumentException if something with the input bytes is wrong. RuntimeException is bad!
This commit is contained in:
parent
0eabd240a6
commit
e5f14e789a
2 changed files with 4 additions and 4 deletions
|
@ -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) {}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue