Closed Axel-EH closed 2 years ago
Hey Axel, sorry I somehow didn't see this issue until now. You're absolutely right. That's a bug on my part. I will fix this now and publish a new version.
Fixed with published version 7.0.7
. Thanks again for reporting this!
Many thanks! Axel
Dear @JonathanWilbur , @hamano
Thanks for this library I'm starting to use in javascript and ASN1 DER.
I get the following exception while decoding a DER element from:
File: der.js, Function: fromBytes(bytes), Line 454
:[source,javascript] ....
....
Before that, it was encoded using the following code snippet:
[source,javascript] .... /* ASN1 Description
application_tag_31 ::= [APPLICATION 31] IMPLICIT UTF8String OPTIONAL
*/
module.exports.set_tag31 = function(tag=31) { var e = new ASN1.DERElement(); e.tagClass = ASN1.ASN1TagClass.application; e.construction = ASN1.ASN1Construction.primitive; e.tagNumber = tag; e.name = "application_tag_31"; e.utf8String = "Hi"; LOG_ASN1_ELEMENT(e); return e; } ....
Encoding with:
der_encoded = der_element.toBytes()
gives the following console output:.... Name: application_tag_31-ASN1-DER Encoded, Number bytes: 5 Dezimal: 95,31,2,72,105 Hex: 0x5F,0x1F,0x02,0x48,0x69 ....
Decoding same buffer with
der_element.fromBytes(der_encoded)
gives the following exeption as console output and fails therefore:.... Exception Thrown: Error: ASN.1 tag number could have been encoded in short form. ....
To me the identifier octet
(class application,primitive,for tags with a number greater than or equal to 31 (bit5 to bit0 0b11111)):0x5F and Tag (last Octet = bit8 zero, tag number 31) 0x1F
encoding looks correct, but the decode function should checkif (this.tagNumber < 31)
instead ofif (this.tagNumber <= 31)
.What do you think?
Best regards,
Axel