ASN.1编码规则详解(最全最经典)(1) (10)

凌霜傲雪 分享 2020-06-28 下载文档

2.9 字符串类型

Known-multiple Character String Type指字符串中每个字符编码所占字节数都一样。

Table 2-5 字符串类型一览表 类型名字 NumericString PrintableString Tag 字符表 18 19 字符“0”到“9”,空格 字符“A” 到 “Z”,“a”到“z”,“0”到“9”,空格,单引号(’),圆括号(( ,)),加号(+),逗号(,),减号(-),点(.),斜杠(/),冒号(:),等号(=),问号(?) VisibleString ISO646String IA5String 22 26 [ISOReg] entry no. 6; space [ISOReg] entry no. 1 & 6; space, delete TeletexString T61String 20 [ISOReg] entry no. 6, 87, 102, 103, 106, 107, 126, 144, 150, 153, 156, 164, 165, 168; space, delete VideotexString 21 [ISOReg] entry no. 1, 13, 72, 73, 87, 89, 102, 108, 126, 128, 129, 144, 150, 153, 164, 165, 168; space, delete GraphicString 25 all the graphical sets (called `G') of [ISOReg]; space GeneralString 27 all the graphical sets (called 是 是 是 是 是 是 ESC Multi 是 是 类型名字 Tag 字符表 `G') and all the control characters (called `C') of [ISOReg]; space, delete ESC Multi UniversalString BMPString 28 30 [ISO10646-1] the basic multilingual plane [ISO10646-1] (65,536 cells) 是 是 UTF8String

12 [ISO10646-1] 2.10 组合类型与扩展原则

2.10.1 Tag

传输数据时,一定要避免接收方收到数据解码时出现不清楚的地方。具体说,接收方要明确知道每个收到数据的类型,我们就要对各类型进行系统性的编号。在ASN.1的第一种编解码规则BER(Basic Encode Rule)中,对数据编码使用的是三元组规则:或者称为TLV,这里type或者称为tag,它是类型的标识符,在ASN.1中每种类型的tag是唯一的。length是编码数据value的字节数。value是实际数据的编码。 I. Tags与Tagging Classes

分配给每个类型的tag实际上是一个值对:。有四种tagging class:UNIVERSAL,context-specific,APPLICATION和PRIVATE。这种方式实际提供了不同的Tag空间。在一个上下文中,如果Tagging Class不同,则相同number的两个Tag也是不同的。

UNIVERSAL的Tag是ASN.1标准定义的,在描述中不能修改。

Table 2-6 ASN.1中定义的UNIVERSAL类Tag Tag 0 1 类型 BER保留 BOOLEAN Tag 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 类型 INTEGER BIT STRING OCTET STRING NULL OBJECT IDENTIFIER ObjectDescripion EXTERNAL, INSTANCE OF REAL ENUMERATED EMBEDDED PDV UFT8String RELATIVE-OID 保留 保留 SEQUENCE, SEQUENCE OF SET, SET OF NumericString PrintableString TeletexString, T61String VideotexString IA5String UTCTime GeneralizedTime GraphicString VisibleString, ISO646String GeneralString UniversalString Tag 29 30 31 类型 CHARACTER STRING BMPString 保留

context-specific Tag是对SEQUENCE、SET和CHOICE及其成员使用的,可以在描述中自己定义,只要不产生歧义,相同数值可以在不同结构中反复使用。如:

A-possible-type ::= SET {

integer [0] CHOICE {

a [0] INTEGER, b [1] INTEGER },

boolean [1] CHOICE {

a [0] BOOLEAN, b [1] BOOLEAN } }

APPLICATION的Tag是为了“to define a data type that finds wide, scattered use within a particular application and that must be distinguishable (by means of its [ abstract syntax]) from all other data types used in the application”。在APPLICATION作用域内,其Tag也是唯一的。如:

Order-number ::= [APPLICATION 0] NumericString (SIZE (12))

但是因为使用IMPORTS等方式下,很难保证唯一性,所以这种Tag类(APPLICATION的Tag)已经不推荐使用了。

PRIVATE的Tag是为了“use a private-use Tagged [ type] to define a data type that finds use within a particular organization or country and that must be distinguishable (by means of its [ abstract syntax]) from all other data types used by that organization or country”。如一个公司可

能这样扩展传输层PDU:

RejectTPDU ::= SET { destRef yr-tu-nr credit extended }

PRIVATE类的Tag现在也不推荐使用了。 II. Tagging Mode

使用context-specific类Tag,如下: Afters ::= CHOICE {

cheese [0]IA5String, dessert [1]IA5String }

当没有其它更多描述信息,并且使用BER编码时,会将UNIVERSAL类和context-specific类的Tag同时编码出来。这种方式称为EXPLICIT模式。

在下面这种情况: T1 ::= [0] INTEGER 变更为:

T2 ::= [0] CHOICE {

integer INTEGER, real REAL }

当CHOICE取值为integer时不需要变更。

与之相对应的是IMPLICIT模式,它将只编码context-specific类的Tag,直到另一个UNIVERSAL类Tag出现。如:

[0] Reference, [1] TPDUnumber,

[2] Credit,

[PRIVATE 0] BOOLEAN DEFAULT FALSE


ASN.1编码规则详解(最全最经典)(1) (10).doc 将本文的Word文档下载到电脑

下一篇:创建星级供电所PPT汇报框架课件 doc - 图文

相关推荐
相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xxxxxx QQ:xxxxxx