> I am confused on Tagging when SEQUENCE OF is used
>
> I have the following ASN.1 BER definition:
>
> MY_PROJ DEFINITIONS AUTOMATIC TAGS ::=
>
> BEGIN
>
> A ::= SEQUENCE {
>      a     [0] INTEGER,
>      b     [1] SEQUENCE OF B
> }
>
> B ::= SEQUENCE {
>      c     [0] INTEGER,
>      d     [1] OCTET STRING
> }
>
> END
>
> Encoded Data 1.
> 30 1B                                                  /* A ::= SEQUENCE */
>          80 01 01                                                  /* a INTEGER */
>          A1 16                                                      /* b SEQUENCE OF 
> B*/
>                    30 09                               /* B ::= SEQUENCE */
>                             80 01 01                               /* c INTEGER */
>                             81 04 01 02 03 04                  /* d OCTET STRING */
>                    30 09                               /* B ::= SEQUENCE */
>                             80 01 01                               /* c INTEGER */
>                             81 04 01 02 03 04                  /* d OCTET STRING */
>
>
> Encoded Data 2.
> 30 1B                                                  /* A ::= SEQUENCE */
>          80 01 01                                                  /* a INTEGER */
>          A1 16                                                      /* b SEQUENCE OF 
> B*/
>                    A0 09                               /* B ::= SEQUENCE */
>                             80 01 01                               /* c INTEGER */
>                             81 04 01 02 03 04                  /* d OCTET STRING */
>                    A1 09                               /* B ::= SEQUENCE */
>                             80 01 01                               /* c INTEGER */
>                             81 04 01 02 03 04                  /* d OCTET STRING */
>
>
> Which encoded data is correct?

Dear Mr. Javier:

The correct encoding is Encoded Data 2. Details follow.

It seems your confusion is whether the tag for B should be [UNIVERSAL 16]
or an ascending context-specific tag ( [0], [1], etc.). If you look at B
by itself

   B ::= SEQUENCE {
        c     [0] INTEGER,
        d     [1] OCTET STRING
   }

it's fairly obvious that the only tag for B could be [UNIVERSAL 16]. Now
look at A all by itself.

   A ::= SEQUENCE {
        a     [0] INTEGER,
        b     [1] SEQUENCE OF B
   }

Here we have b which is a SEQUENCE OF B. The element b has a tag ([1])
which is not to be confused with the tag for B. The tag for B remains
[UNIVERSAL 16] and b is simply an array of Bs with a tag of its own, thus
it would look like

        tag of b
        length of b
           B
           B
           B

If we expand the Bs, we get

        tag of b
        length of b
           tag of B
           length of B
           content of B
           tag of B
           length of B
           content of B
           tag of B
           length of B
           content of B

There is no need to increment the tag of B; indeed you may not.

You have a minor syntax error in the module name, namely, that the
underscore in MY_PROJ is not within the permitted ASN.1 character set.
Please consider renaming it to MY-PROJ or MYPROJ or anything without an
underscore.

One more thing: your use of AUTOMATIC TAGS is irrelevant to your example.
It would only apply if you did not include your own tags in the SEQUENCE.
Thus, in the following example,

   Module DEFINITIONS AUTOMATIC TAGS ::= BEGIN

      Y ::= SEQUENCE { y1     INTEGER,
                       y2     INTEGER,
                       y3     INTEGER
      }

      Z ::= SEQUENCE { z1 [4] INTEGER,
                       z2 [5] INTEGER,
                       z3 [6] INTEGER
      }

   END

SEQUENCE Y would be automatically tagged (to IMPLICIT [0], IMPLICIT [1],
IMPLICIT [2]) but Z would not be.

Please let me know if I have not been clear enough.

=====================================================================
Conrad Sigona                         Voice Mail     : 1-732-302-9669 x400
OSS Nokalva                           Fax            : 1-419-831-5035
[EMAIL PROTECTED]                        My direct line : 1-315-845-1773

Reply via email to