Steven Legg wrote:

Lev,

Lev Walkin wrote:
Rick Berge wrote:

Bertil Karlsson wrote:

Hello,

I wonder if someone knows the right BER encoding of the following example:

Seq ::= SEQUENCE{
  a     [PRIVATE 1] IMPLICIT OCTET STRING
}

If the component is encoded with value 1,2,3 (three octets) in
constructed  form what would
the encoding of the inner OCTET STRING be?

Which of the following is right for Seq?
a        48,7,225,5,4,3,1,2,3        [UNIVERSAL 4] as inner tag
b        48,7,225,5,193,3,1,2,3    [PRIVATE 1] as inner tag


Lev Walkin wrote:

Second form is correct.



...but unless I'm missing something, you have an extra tag (225) between
SEQUENCE (48) and [PRIVATE 1] (193).


You are missing something. The constructed [private 1](225) is not
necessary, as there is a primitive [private 1] (193). It is would
be necessary only in case of nested tags, which is not the case.

I think you have missed Note 2 on Clause 8.7.3.2 of X.690 (07/2002):

"In particular, the tags in the contents octets are always universal class, number 4."

The "contents octets" being the contents octets of the constructed (outer) OCTET STRING encoding.
This makes the first form (case a) the correct encoding.

We don't have a constructed encoding here. We do have primitive encoding
here. You are right that the [UNIVERSAL 4] tag applies to the inner
tags, but this is only when the string is encoded using indefinite
length. If DER or CER is used, for such string there will be a primitive
encoding with a known length. That is, you can't possibly receive or
transmit string of this length with [UNIVERSAL 4] tag, if using CER or
DER.

With BER, you can do that, but the #a form will still be invalid.
The correct forms for BER are (note, hexadecimal encodings):

1. Primitive, known-length string:

        30, 05, C1, 03, 1, 2, 3
                ^^<- [PRIVATE 1], primitive

2. Constructed, indefinite length string "a":

        30, 09, E1, 80, 04, 03, 1, 2, 3, 0, 0
                ^^<- [PRIVATE 1], constructed
                        ^^<- [UNIVERSAL 4], primitive

3. Constructed, indefinite length string "a" in two blocks:

        30, 0B, E1, 80, 04, 01, 1, 04, 02, 2, 3, 0, 0

4. Constructed, indefinite length string "a" in three blocks:

        30, 0D, E1, 80, 04, 01, 1, 04, 01, 2, 04, 01, 3, 0, 0

5. Consructed, indefinite length sequence Seq and string a:

        30, 80, E1, 80, 04, 3, 1, 2, 3, 0, 0, 0, 0

6. And other derivatives.




The following form is never valid:

>>>>> a        48,7,225,5,4,3,1,2,3        [UNIVERSAL 4] as inner tag


=== Here's how unber(1) display #4 form of encoding ===

[EMAIL PROTECTED]:~]> echo "30,0D,E1,80,04,01,01,04,01,02,04,01,03,00,00" | \
        xxd -r -p | unber -m -

<C T="[UNIVERSAL 16]" TL="2" V="13">
    <I T="[PRIVATE 1]" TL="2" V="Indefinite">
        <P T="[UNIVERSAL 4]" TL="2" V="1">&#x01;</P>
        <P T="[UNIVERSAL 4]" TL="2" V="1">&#x02;</P>
        <P T="[UNIVERSAL 4]" TL="2" V="1">&#x03;</P>
    </I T="[UNIVERSAL 0]">
</C T="[UNIVERSAL 16]">
=== cut ===

--
Lev Walkin
[EMAIL PROTECTED]
_______________________________________________
ASN1 mailing list
[email protected]
http://lists.asn1.org/mailman/listinfo/asn1

Reply via email to