ANS1 研究3

二、标签模式

  

         EXPLICIT tagging:----------------------默认的模式,即默认使用显式模式,它会在已存在的标签之前添加自定义的值
– Default tagging mode
– EXPLICIT tag is added in front of the existing tag


• IMPLICIT tagging:-------------------------------------,覆盖已存在的标签的值
– IMPLICIT tag replaces an existing tag

 

明确定义的标签:

Primary use of tags
• Avoid ambiguous descriptions
• Example:
Unambiguous ::= SEQUENCE {
val1 [0] INTEGER OPTIONAL,
val2 INTEGER OPTIONAL
}

Tagging distinguishes val1 and val2 encodings

 

结构类型标注规则:

• Tags values must be sequential from 0------------------标签值必须是连续的从0开始的
• Tagging class must not be UNIVERSAL--------------------标签类不能是UNIVERSAL
InvalidSeq ::= SEQUENCE {
version INTEGER,
name [UNIVERSAL 0] PrintableString
}

这不是一个有效的声明

 

透明类型标注规则

OpenType and CHOICE types are always explicitly
tagged (even when not mentioned in an IMPLICIT
TAGS module header)------开放类型和选择类型总是显式的标签(即使在一个使用隐式标签的模块使用)

• CHOICE inner elements tags must be distinct-----选择类型内部的元素标签必须不同

Generic ::= [0] IMPLICIT OpenType---------这不是有效的,(因为只能使用显式标签)


 

多个标签

asn1提供多标签(或者递归标签)

TaggedInt ::= [1] EXPLICIT [0] IMPLICIT INTEGER
Equivalent to:
TaggedInt ::= [1] EXPLICIT Int


Int ::= [0] IMPLICIT INTEGER

隐藏的含糊不清的声明

HiddenSequence ::= SEQUENCE {
first Seq OPTIONAL,
second SeqOfInt
}
Seq ::= SEQUENCE {
val INTEGER
}
SeqOfInt ::= SEQUENCE OF INTEGER

 

When first is not present and second holds a
single INTEGER value, the encoding is successfully
generated…-------------当第一个不在,第二个只有一个integer值,可以正确的编码
… but the decoder cannot determine whether first or
second is encoded!--------但是解码者不能区分是第一个还是第二个编码

修正后:

HiddenSequence ::= SEQUENCE {
first Seq OPTIONAL,
second [0] SeqOf
}

标签执行中的错误

TrickySequence ::= SEQUENCE {
first Seq OPTIONAL,
second SeqOfBool
}
Seq ::= SEQUENCE {
val INTEGER
}
SeqOfBool ::= SEQUENCE OF BOOLEAN

 

first and second hold different inner elements
types (INTEGER and BOOLEAN)…


… but when first is absent, decoders have to go inside
the SEQUENCE OF and fail to decode the first
INTEGER value to know that the encoding does not
enclose first…-----------但是当第一个不在,解码者必须进入sequence of 标签,解释第一个integer失败,不能够知道没有将第一个元素添加到编码中。

修正:

TrickySequence ::= SEQUENCE {
first Seq OPTIONAL,
second [0] SeqOfBool
}

Sequence是有序的,而Set是无序的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值