JonathanWilbur / asn1-ts

ASN.1 TypeScript library, including codecs for Basic Encoding Rules (BER) and Distinguished Encoding Rules (DER).
MIT License
32 stars 6 forks source link

Invalid Tag Class and Construction Setting in toBytes() #3

Closed JonathanWilbur closed 5 years ago

JonathanWilbur commented 5 years ago

The method toBytes in all codecs incorrectly sets the tag class and construction.

In the lines below, I OR'ed the tag octets with the ASN1TagClass and ASN1Construction with the assumption that those enum members had values that were already shifted to the proper bit. Below is the OR in the BER codec:

https://github.com/JonathanWilbur/asn1-ts/blob/5b05c4e4df4169f03ebd0573cb340d2dd205724f/source/codecs/ber.ts#L761-L762

And here it is in the DER codec:

https://github.com/JonathanWilbur/asn1-ts/blob/5b05c4e4df4169f03ebd0573cb340d2dd205724f/source/codecs/der.ts#L720-L721

And here are the enum definitions:

https://github.com/JonathanWilbur/asn1-ts/blob/5b05c4e4df4169f03ebd0573cb340d2dd205724f/source/values.ts#L6-L18

This would result in tags being encoded with the incorrect tag numbers.