Skip to content

Commit

Permalink
ECKey: switch away from the deprecated DERInteger class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Apr 8, 2014
1 parent 6087e43 commit 2379eff
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/com/google/bitcoin/core/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ public static ECDSASignature decodeFromDER(byte[] bytes) {
try {
ASN1InputStream decoder = new ASN1InputStream(bytes);
DLSequence seq = (DLSequence) decoder.readObject();
DERInteger r, s;
ASN1Integer r, s;
try {
r = (DERInteger) seq.getObjectAt(0);
s = (DERInteger) seq.getObjectAt(1);
r = (ASN1Integer) seq.getObjectAt(0);
s = (ASN1Integer) seq.getObjectAt(1);
} catch (ClassCastException e) {
throw new IllegalArgumentException(e);
}
Expand All @@ -392,8 +392,8 @@ protected ByteArrayOutputStream derByteStream() throws IOException {
// Usually 70-72 bytes.
ByteArrayOutputStream bos = new ByteArrayOutputStream(72);
DERSequenceGenerator seq = new DERSequenceGenerator(bos);
seq.addObject(new DERInteger(r));
seq.addObject(new DERInteger(s));
seq.addObject(new ASN1Integer(r));
seq.addObject(new ASN1Integer(s));
seq.close();
return bos;
}
Expand Down Expand Up @@ -586,7 +586,7 @@ private static ECKey extractKeyFromASN1(byte[] asn1privkey) {
ASN1InputStream decoder = new ASN1InputStream(asn1privkey);
DLSequence seq = (DLSequence) decoder.readObject();
checkArgument(seq.size() == 4, "Input does not appear to be an ASN.1 OpenSSL EC private key");
checkArgument(((DERInteger) seq.getObjectAt(0)).getValue().equals(BigInteger.ONE),
checkArgument(((ASN1Integer) seq.getObjectAt(0)).getValue().equals(BigInteger.ONE),
"Input is of wrong version");
Object obj = seq.getObjectAt(1);
byte[] privbits = ((ASN1OctetString) obj).getOctets();
Expand Down

3 comments on commit 2379eff

@TheBlueMatt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you audit that ASN1Integer/DERInteger parsing is the same?

@TheBlueMatt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure I audited DERInteger for same-as-openssl-parsing at one point, but ASN1Integer needs the same treatment.

@mikehearn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In BC 1.50 ASN1Integer inherits from DERInteger and in 1.51 they switched it to be the other way around, so the code crashes without this change on 1.51.

As far as I can tell, the logic itself is the same though.

Please sign in to comment.