indutny / asn1.js

ASN.1 Decoder/Encoder/DSL
MIT License
181 stars 64 forks source link

Error in decode on RFC3161 structure #86

Open lapo-luchini opened 7 years ago

lapo-luchini commented 7 years ago

Hi, I have a problem when decoding a TimeStampResp… when using normal decode only status is printed, while the answer is complete and certainly contains more, when using partial: true it enters a loop and never stops. I wasn't able to detect the loop using the inspector so far (nor find any problem in my ASN.1 definition). I saved my self-contained test case in this gist.

{ status: { status: 'granted' } }
[ 'tagged', '', 0, 1700 ]
[ 'content', '', 4, 1700 ]
[ 'tagged', 'status', 4, 9 ]
[ 'content', 'status', 6, 9 ]
[ 'tagged', 'status/status', 6, 9 ]
[ 'content', 'status/status', 8, 9 ]
[ 'tagged', 'timeStampToken', 9, 1700 ]
[ 'content', 'timeStampToken', 13, 1700 ]
[ 'tagged', 'timeStampToken/contentType', 13, 24 ]
[ 'content', 'timeStampToken/contentType', 15, 24 ]
[ 'tagged', 'timeStampToken/content', 28, 183 ]
[ 'content', 'timeStampToken/content', 30, 183 ]
[ 'tagged', 'timeStampToken/content/version', 30, 33 ]
[ 'content', 'timeStampToken/content/version', 32, 33 ]
[ 'tagged', 'timeStampToken/content/digestAlgorithms', 33, 50 ]
[ 'content', 'timeStampToken/content/digestAlgorithms', 35, 50 ]
^C
misos1 commented 7 years ago

From where are these definitions? First problem is with "common.Attribute" where common is not defined so seems it will not parse this optional branch "this.key('timeStampToken').optional().use(TimeStampToken)" due to exception. When you set this not to be optional you get exception that common is not defined.