Thank you all for your answers. You enlighted me in my confusion. I had missed NOTE 2 in the 8.7.3.2 paragraph.
regards /Bertil Lev Walkin wrote:
Steven Legg wrote:Lev, Lev Walkin wrote: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 tagLev Walkin wrote:Second form is correct....but unless I'm missing something, you have an extra tag (225) betweenSEQUENCE (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.Sure we do. Bertil's original question stated "in constructed form" and his alternative encodings for the "a" component both have tag 225, i.e. with the constructed bit set.Okay, I missed that.We do have primitive encoding here.Nested inside the contents octets of the constructed encoding for the "a" component.Yes, so we have a constructed [p1] wrapping a primitive [u4].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.How do you reach the conclusion that the [UNIVERSAL 4] tag only applies when the string is indefinite length encoded ? I can't find anything in X.690 to support that view.You are right here: I should have written "only when the string is encoded using indefinite length or using definite length form of constructed encoding", such as in 8.1.3.2, clause b).If DER or CER is used, for such string there will be a primitive encoding with a known length.You can have a constructed OCTET STRING in CER.Key is "such string". String of three octets. Both DER and CER request primitive encoding for such short strings. I must admit I have missed the "constructed" word in the original statement.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 tagI completely disagree. The "a" form is consistent with clauses 8.1.3.2, 8.14 and 8.7of X.690. The "b" form violates 8.7.3.2 and 8.14.3.I must correct myself here. As specified in 8.7.1, the base of OCTET STRING can either be primitive or constructed, and Bertil originally explicitly specified that the constructed form is used. The situation is more adequately described by: 8.7.1, "constructed" option. 8.14.3, clause "a)" 8.1.3.2, clauses "b)" or "c)". The correct form is indeed either of: 30, 07, E1, 05, 04, 03, 01, 02, 03 (Bertil's "a" form) which violates both DER and CER, see #9.2 30, 05, C1, 03, 01, 02, 03 which is not really what Bertil wants to do (do a "constructed" octet string), but does not violate DER and CER and variations, such as my examples 2, 3, 4 in my original email, plus variations with the definite length constructed encodings. Steven, thank you for highlighting my lack of reading skills.
_______________________________________________ ASN1 mailing list [email protected] http://lists.asn1.org/mailman/listinfo/asn1
