1、)45 4 8 TELECOMMUNICATIONSTANDARDIZATION SECTOROF ITU/0%. 3934%-3 ).4%2#/%#4)/.-/$%, !.$ ./4!4)/.30%#)(b) the need for a high-level notation for specifying such information objects;(c) the value of isolating and standardizing the rules for encoding such information objects.unanimously recommendsthat
2、 the rules for encoding information objects are defined in this Recommendation.CONTENTS0 Introduction1 Scope and field of application2 References3 Definitions4 Abbreviations and notation4.1 Abbreviations4.2 Notation5 Conformance6 General rules for encoding6.1 Structure of an encoding6.2 Identifier o
3、ctets6.3 Length octets6.4 Contents octets6.5 End-of-contents octets7 Encoding of a Boolean value8 Encoding of an integer value9 Encoding of an enumerated value10 Encoding of a real value11 Encoding of a bitstring value12 Encoding of an octetstring value13 Encoding of a null value14 Encoding of a seq
4、uence value_1)Recommendation X.209 and ISO 8825 Information processing systems - Open systems interconnection - Specification of basicencoding rules for Abstract Syntax Notation One (ASN.1) as extended by Addendum 1 to ISO 8825, were developed in closecooperation and are technically aligned.2 Fascic
5、le VIII.4 - Rec. X.20915 Encoding of a sequence-of value16 Encoding of a set value17 Encoding of a set-of value18 Encoding of a choice value19 Encoding of a selection value20 Encoding of a tagged value21 Encoding of a value of the ANY type22 Encoding of an object identifier value23 Encoding for valu
6、es of the character string types24 Encoding for values of the ASN.1 useful types25 Use in transfer syntax definitionAppendix I - Example of encodingsI.1 ASN.1 description of the record structureI.2 ASN.1 description of a record valueI.3 Representation of this record valueAppendix II - Assignment of
7、object identifier valuesAppendix III - Illustration of real value encoding0 IntroductionRecommendation X.208 (Specification of Abstract Syntax Notation One) specifies a notation for the definitionof abstract syntaxes, enabling application layer specifications to define the types of information they
8、need to transferusing the presentation service. It also specifies a notation for the specification of value of a defined type.This Recommendation defines a set of encoding rules that may be applied to values of types defined using thenotation specified in Recommendation X.208. Application of these e
9、ncoding rules produces a transfer syntax for suchvalues. It is implicit in the specification of these encoding rules that they are also to be used for decoding.There may be more than one set of encoding rules that can be applied to values of types that are defined usingthe notation of Recommendation
10、 X.208. This Recommendation defines one set of encoding rules, called basic encodingrules.This Recommendation is technically and editorially aligned with ISO 8825 plus Addendum I to ISO 8825.Appendix I gives examples of the application of the encoding rules. It is not part of this Recommendation.App
11、endix II summarises the assignment of object identifier values made in this Recommendation and is notpart of this Recommendation.Appendix III is not part of this Recommendation, and gives examples of applying the rules for encoding reals.1 Scope and field of applicationThis Recommendation specifies
12、a set of basic encoding rules that may be used to derive the specification of atransfer syntax for values of types defined using the notation specified in Recommendation X.208. These basic encodingrules are also to be applied for decoding such a transfer syntax in order to identify the data values b
13、eing transferred.These basic encoding rules are used at the time of communication (by the presentation service provider whenrequired by a presentation context). Fascicle VIII.4 - Rec. X.209 32 References1 Recommendation X.200, Reference Model of Open Systems Interconnection for CCITT Applications (s
14、ee alsoISO 7498).2 Recommendation X.208, Specification of Abstract Syntax Notation One (ASN.1) (see also ISO 8824).3 Recommendation X.226, Presentation Protocol Specification for Open Systems Interconnection for CCITTApplications (see also ISO 8823).4 ISO 2022, Information processing - ISO 7-bit and
15、 8-bit coded character sets - Code extension techniques.5 ISO 2375, Data processing - Procedure for registration of escape sequences.6 ISO 6093, Information processing - Representation of numerical values in character strings for informationinterchange.3 DefinitionsThe definitions of Recommendation
16、X.208 are used in this Recommendation.3.1 dynamic conformanceA statement of the requirement for an implementation to adhere to the behaviour prescribed by thisRecommendation in an instance of communication.3.2 static conformanceA statement of the requirement for support by an implementation of a val
17、id set of features from among thosedefined by this Recommendation.3.3 data valueInformation specified as the value of a type; the type and the value are defined using ASN.1.3.4 encoding (of a data value)The complete sequence of octets used to represent the data value.Note - Some CCITT Recommendation
18、s use the term “data element“ for this sequence of octets, but the term isnot used in this Recommendation, as ISO International Standard use it to mean “data value“.3.5 identifier octetsPart of a data value encoding which is used to identify the type of the value.3.6 length octetsPart of a data valu
19、e encoding following the identifier octets which is used to determine the end of theencoding.3.7 end-of-contents octetsPart of a data value encoding, occurring at its end, which is used to determine the end of the encoding.Note - Not all encodings require end-of-contents octets.3.8 contents octetsTh
20、at part of a data value encoding which represents a particular value, to distinguish it from other values of thesame type.4 Fascicle VIII.4 - Rec. X.2093.9 primitive encodingA data value encoding in which the contents octets directly represent the value.3.10 constructed encodingA data value encoding
21、 in which the contents octets are the complete encoding of one or more other datavalues.3.11 senderAn implementation encoding a data value for transfer.3.12 receiverAn implementation decoding the octets produced by a sender, in order to identify the data value which wasencoded.4 Abbreviations and no
22、tation4.1 AbbreviationsASN.1 Abstract Syntax Notation One4.2 Notation4.2.1 This Recommendation references the notation defined by Recommendation X.208.4.2.2 This Recommendation specifies the value of each octet in an encoding by use of the terms “most significantbit“ and “least significant bit“.Note
23、 - Lower layer specifications use the same notation to define the order of bit transmission on a serial line, orthe assignment of bits to parallel channels.4.2.3 For the purposes of this Recommendation, the bits of an octet are numbered from 8 to 1, where bit 8 is the“most significant bit“, and bit
24、1 is the “least significant bit“.5 Conformance5.1 Dynamic conformance is specified by 6 to 24 inclusive.5.2 Static conformance is specified by those documents which specify the application of these basic encodingrules.5.3 Alternative encodings are permitted. by this Recommendation as a senders optio
25、n. Conforming receivers shallsupport all alternatives.Note - Examples of such alternative encodings appear in 6.3.2 b) and Table 2/X.209.6 General rules for encoding6.1 Structure of an encoding6.1.1 The encoding of a data value shall consist of four components which shall appear in the following ord
26、er:a) identifier octets (see 6.2);b) length octets (see 6.3);c) contents octets (see 6.4);d) end-of-contents octets (see 6.5).6.1.2 The end-of-contents octets shall not be present unless the value of the length octets requires them to be present(see 6.3). Fascicle VIII.4 - Rec. X.209 56.1.3 Figure 1
27、/X.209 illustrates the structure of an encoding (primitive or constructed). Figure 2/X.209 illustrates analternative constructed encoding.6.2 Identifier octets6.2.1 The identifier octets shall encode the ASN.1 tag (class and number) of the type of the data value.6.2.2 For tags with a number ranging
28、from zero to 30 (inclusive), the identifier octets shall comprise a singlea) bits 8 and 7 shall be encoded to represent the class of the tag as specified in Table 1 /X.209;b) bit 6 shall be a zero or a one according to the rules of 6.2.5;c) bit 5 to I shall encode the number of the tag as a binary i
29、nteger with bit 5 as the most significant bit.6.2.3 Figure 3/X.209 illustrates the form of an identifier octet for a type with a tag whose number is in the rangezero to 30 (inclusive).6.2.4 For tags with a number greater than or equal to 31, the identifier shall comprise a leading octet followed byo
30、ne or more subsequent octets.TABLE 1/X.209Encoding of clan of tag6.2.4.1 The leading octet shall be encoded as follows:a) bits 8 and 7 shall be encoded to represent the class of the tags as listed in Table 1 /X.209;b) bit 6 shall be a zero or a one according to the rule of 6.2.5;c) bit 5 to I shall
31、be encoded as 111112.FIGURE 1/X.209Structure of an encodingClass Bit 8 Bit 7Universal 0 0Application 0 1Context-specific 1 0Private 1 16 Fascicle VIII.4 - Rec. X.209FIGURE 2/X.209An alternative constructed encoding6.2.4.2 The subsequent octets shall encode the number of the tag as follows:a) bit 8 o
32、f each octet shall be set to one unless it is the last octet of the identifier octets;b) bit 7 to 1 of the first subsequent octet, followed by bits 7 to 1 of the second subsequent octet, followed inturn by bits 7 to 1 of each further octet, up to and including the last subsequent octet in the identi
33、fier octetsshall be the encoding of an unsigned binary integer equal to the tag number, with bit 7 of the firstsubsequent octet as the most significant bit;c) bits 7 to 1 of the first subsequent octet shall not all be zero.6.2.4.3 Figure 4/X.209 illustrates the form of the identifier octets for a ty
34、pe with a tag whose number is greater than30.6.2.5 Bit 6 shall be set to zero if the encoding is primitive, and shall be set to one if the encoding is constructed.Note - Subsequent clauses specify whether the encoding is primitive or constructed for each type.FIGURE 3/X.209Identifier octet (low tag
35、number). Fascicle VIII.4 - Rec. X.209 7FIGURE 4/X.209Identifier octets (high tag number)6.2.6 Recommendation X.208 specifies that the tag of a type defined using the “CHOICE“ keyword takes the valueof the tag of the type from which the chosen data value is taken.6.2.7 Recommendation X.208 specifies
36、that the tag of a type defined using “ANY“ is indeterminate. The “ANY“type is subsequently defined to be an ASN.1 type, and the complete encoding is then identical to that of a value of theassigned type (including the identifier octets).6.3 Length octets6.3.1 Two forms of length octets specified. Th
37、ese area) the definite form (see 6.3.3); andb) the indefinite form (see 6.3.4).6.3.2 A sender shalla) use the definite form ( 6.3.3) if the encoding is primitive;b) use either the definite form ( 6.3.3) or the indefinite form ( 6.3.4), a senders option, if the encoding isconstructed and all immediat
38、ely available;c) use the indefinite form ( 6.3.4) if the encoding is constructed and is not all immediately available.6.3.3 For the definite form, the length octets shall consist of one or more octets, and shall represent the number ofoctets in the contents octets using either the short form ( 6.3.3
39、.1) or the long form ( 6.3.3.2) as a senders option.Note - The short form can only be used if the number of octets in the contents octets is less than or equal to 127.6.3.3.1 In the short form, the length octets shall consist of a single octet in which bit 8 is zero and bit 7 to I encode thenumber o
40、f octets in the contents octets (which may be zero), as an unsigned binary integer with bit 7 as the mostsignificant bit.Example:L = 38 can be encoded as 0010011028 Fascicle VIII.4 - Rec. X.2096.3.3.2 In the long form, the length octets shall consist of an initial octet and one or more subsequent oc
41、tets. The initialoctet shall be encoded as follows:a) bit 8 shall be one;b) bits 7 to 1 shall encode the number of subsequent octets in the length octets, as an unsigned binary integerwith bit 7 as the most significant bit;c) the value 111111112shall not be usedNote - This restriction is introduced
42、for possible future extension.Bits 8 to 1 of the first subsequent octet, followed by bits 8 to 1 of the second subsequent octet, followed in turnby bits 8 to 1 of each further octet up to and including the last subsequent octet, shall be the encoding of an unsignedbinary integer equal to the number
43、of octets in the contents octets, with bit 8 of the first subsequent octet as the mostsignificant bit.Example:L = 201 can be encoded as: 100000012110010012Note - In the long form, it is a senders option whether to use more length octets than the minimum necessary.6.3.4 For the indefinite form, the l
44、ength octets indicate that the contents are terminated by end-of-contents octets(see 6.5), and shall consist of a single octet.6.3.4.1 The single octet shall have bit 8 set to one, and bits 7 to 1 set to zero.6.3.4.2 If this form of length is used, then end-of-contents octets (see 6.5) shall be pres
45、ent in the encoding followingthe contents octets.6.4 Contents octetsThe contents octets shall consist of zero, one or more octets, and shall encode the data value as specified insubsequent clauses.Note - The contents octets depend on the type of the data value; subsequent clauses follow the same seq
46、uence asthe definition of types in ASN.1.6.5 End-of-contents octetsThe end-of-contents octets shall be present if the length is encoded as specified in 6.3.4, otherwise they shallnot be present.The end-of-contents octets shall consist of two zero octets.Note - The end-of-contents octets can be consi
47、dered as the encoding of a value whose tag is universal, whoseform is primitive, whose number of the tag is zero, and whose contents is absent, thusEnd-of-contents Length Contents00160016Absent7 Encoding of a Boolean value7.1 The encoding of a Boolean value shall be primitive. The contents octets sh
48、all consist of a single octet.7.2 If the Boolean value isFALSEthe octet shall be zero.7.2.1 If the Boolean value isTRUEthe octet shall have any non-zero value, as a senders option. Fascicle VIII.4 - Rec. X.209 9Example - If of type BOOLEAN, the value TRUE can be encoded as:Boolean Length Contents011
49、60116FF168 Encoding of an integer value8.1 The encoding of an integer value shall be primitive. The contents octets shall consist of one or more octets.8.2 If the contents octets of an integer value encoding consist of more than one octet, then the bits of the first octetand bit 8 of the second octeta) shall not all be ones; andb) shall not all be zero.Note - These rules ensure that an integer value is always encoded in the smallest possible number of octets.8.3 The contents octets shall be a twos, complement binary numbe