PeculiarVentures / ASN1.js

ASN1js is a pure JavaScript library implementing a full ASN.1 BER decoder and encoder.
https://asn1js.org
Other
271 stars 57 forks source link

How to make a schema using implicit tagging with repeated values? #55

Closed gnarea closed 4 years ago

gnarea commented 4 years ago

I've been using implicit tagging with named fields following the examples in #45, but how can I build a schema for an sequence with an arbitrary number of homogeneous items?

Consider this as an example:

CargoMessageSet ::= SEQUENCE OF Message
Message ::= OCTET STRING

I can get it to work with explicit tagging using the following code:

const ASN1_SCHEMA = new asn1js.Sequence({
    name: 'CargoMessageSet',
    value: [
      new asn1js.Repeated({
        name: 'message_set',
        value: new asn1js.OctetString({ name: 'message' }),
      }),
    ],
  });

But how can I get it to work with implicit tagging? I tried the code below:

const ASN1_SCHEMA = new asn1js.Sequence({
    name: 'CargoMessages',
    value: [
      new asn1js.Repeated({
        name: 'message_set',
        value: new asn1js.Primitive({ idBlock: {tagClass: 3}, name: 'message' }),
      }),
    ],
  });

However, that schema only works when there's zero or one items. If there are two or more, asn1js.verifySchema() fails without giving an explanation: .result is a Sequence instance with no errors or warnings, and a single item.

YuryStrozhevsky commented 4 years ago

@gnarea You can try to search PKIjs source code for "IMPLICIT" and check how it made there.

gnarea commented 4 years ago

Thanks @YuryStrozhevsky!