ASN.1 タグ付けの概要が必要なようです。これにアプローチするには 2 つの角度があります。X.690 は、BER/CER/DER エンコード規則を定義します。そのため、タグがどのようにエンコードされるかという質問に答えます。X.680 は、ASN.1 自体を定義します。そのため、タグ付けの構文とルールを定義します。どちらの仕様も ITU-T の Web サイトで見つけることができます。簡単に概要を説明します。
タグは、タイプを識別するために BER/DER/CER で使用されます。これらは、SEQUENCE の構成要素と CHOICE の選択肢を区別するのに特に役立ちます。
タグは、タグ クラスとタグ番号を組み合わせたものです。タグ クラスは、UNIVERSAL、APPLICATION、PRIVATE、および CONTEXT-SPECIFIC です。UNIVERSAL クラスは、基本的に組み込み型に使用されます。APPLICATION は通常、ユーザー定義型に使用されます。CONTEXT-SPECIFIC は通常、構築された型 (SEQUENCE、CHOICE、SEQUENCE OF) 内のコンポーネントに使用されます。構文的には、タグが ASN.1 モジュールで指定される場合、それらは括弧内に記述されます: [ tag_class tag_number ]; CONTEXT-SPECIFIC の場合、tag_class は省略されます。したがって、[APPLICATION 10] または [0]。
すべての ASN.1 タイプには関連付けられたタグがありますが、構文的には、ASN.1 作成者がタイプをエンコードするタグを指定するために使用する「TaggedType」もあります。基本的に、TaggedType は型の前にタグ プレフィックスを置きます。例えば:
MyType ::= SEQUENCE {
field_with_tagged_type [0] UTF8String
}
The tag in a TaggedType is either explicit or implicit. If explicit, this means that I want the original tag to be explicitly encoded. If implicit, this means I am happy to have only the tag that I specified be encoded. In the explicit case, the BER encoding results in a nested TLV (tag-length-value): the outer tag ([0] in the example above), the length, and then another TLV as the value. In the example, this inner TLV would have a tag of [UNIVERSAL 12] for the UTF8String.
Whether the tag is explicit or implicit depends upon how you write the tag and the tagging environment. For example:
MyType2 ::= SEQUENCE {
field_with_explicit_tag [0] EXPLICIT UTF8String OPTIONAL,
field_with_implicit_tag [1] IMPLICIT UTF8String OPTIONAL,
field_with_tag [2] UTF8String OPTIONAL
}
If you specify neither IMPLICIT nor EXPLICIT, there are some rules that define whether the tag is explicit or implicit (see X.680 31). These rules take into consideration the tagging environment defined for the ASN.1 module. The ASN.1 module may specify the tagging environment as IMPLICIT TAGS, EXPLICIT TAGS, or AUTOMATIC TAGS. Roughly speaking, if you don't specify IMPLICIT or EXPLICIT for a tag, the tag will be explicit if the tagging environment is EXPLICIT and implicit if the tagging environment is IMPLICIT or AUTOMATIC. An automatic tagging environment is basically the same as an IMPLICIT tagging environment, except that unique tags are automatically assigned for members of SEQUENCE and CHOICE types.
Note that in the above example, the three components of MyType2 are all optional. In BER/CER/DER, a decoder will know what component is present based on the encoded tag (which obviously better be unique).