OK, I finally got it. So you don't use the Universal class, but the Context
Specific and in that context the tag doesn't give you the type of the field,
but other information, such as the order of the data member within the
sequence (it's the order I was referring to when I spoke about the index).

Thank you for your time.
Best regards,
Eddie Lascu

-----Original Message-----
From: Conrad Sigona [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 20, 2005 11:24 AM
To: Eduard Lascu
Cc: [email protected]
Subject: Re: [ASN1] Encoding of a real with default value in BER


> By Tag you mean the last five bits (4 to 0) of the Identifier octet (where
> bits 7-6 are the Class, and bit 5 is the Primitive/Constructed bit),
right?

Dear Mr. Lascu:

Yes, that's right, but it's not quite as simple as you've expressed it.
There can be long tags and there can be multiple tags. You would do well
to review the tag sections of one of the ASN.1 reference manuals which OSS
makes freely available for download. Please visit www.oss.com.

> I thought those are used to tell the type of the member, according to this
> table:
>
> BOOLEAN = 0x01
> INTEGER = 0x02
> BIT_STRING = 0x03
> OCTET_STRING = 0x04
> NULL = 0x05
> OBJECT_ID = 0x06
> REAL = 0x09
> ENUMERATION = 0x0A
> UTF8_STRING = 0x0C
> GENERAL_STRING = 0x1B
> SEQUENCE = 0x10
> SET = 0x11

These are the UNIVERSAL tags, the default tags. They are not useful when
they are not unique enough (for example, if I have multiple optional
INTEGERs in a SEQUENCE). You therefore begin by making sure that your tags
are unique enough. A good way is to just assign each element a tag
beginning with [0] and incrementing it by 1. This ensures uniqueness
within the SEQUENCE and you don't have to think about it. Just do it and
forget about the question of whether it's unique enough. You then tell the
type of the element by comparing its tag with the tags which would be
expected.

> For all my real members I set the the Identifier octet field to 0000 1001
> (Universal, primitive, real number). Is there a way to embed the index of
> the member within the sequence in the Tag part as well?

No, you don't want an index. That's not the BER way. It would create an
invalidly encoded SEQUENCE. You instead want a tag which is unique. Take
the following example.

    Z ::= SEQUENCE {
                     a [0] IMPLICIT INTEGER OPTIONAL,  -- tag would be 80
                     b [1] IMPLICIT INTEGER OPTIONAL,  -- tag would be 81
                     c [2] IMPLICIT INTEGER OPTIONAL   -- tag would be 82
    }

It shows that I am replacing the default [UNIVERSAL 2] tags with [0], [1],
or [2], as the case may be.

Using Z above as an example, if I were to decode

    30 06 80 01 05 82 01 07

I would know that a is present (and has the value 5), b is absent, and c
is present (and has the value 7).

You can also do it with EXPLICIT tags, where you keep the original
UNIVERSAL tags but also add another tag. You might find this easier to use
to identify the type but it adds a lot more octets to the encoding. It
would look like this

    Y ::= SEQUENCE {
                     d [0] INTEGER OPTIONAL,  -- two tags, 80 and 02
                     e [1] INTEGER OPTIONAL,  -- two tags, 81 and 02
                     f [2] INTEGER OPTIONAL   -- two tags, 82 and 02
    }

In this case, where two tags are used, it takes the form TLTLV where the
ending TLV becomes the V for the first TL. That is, the first tag sort of
wraps the second. Using Y as an example, if I were to decode

    30 0A 80 03 02 01 05 82 03 02 01 07

I would know that d is present (and has the value 5), e is absent, and f
is present (and has the value 7).

Since this thread has evolved from representing REALs to working with
tags, I avoided using REALs in the examples above. It would just confuse
things, particularly for folks who didn't catch your initial question.

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

_______________________________________________
ASN1 mailing list
[email protected]
http://lists.asn1.org/mailman/listinfo/asn1

Reply via email to