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是无序的

阅读更多
个人分类: PKCS
上一篇ASN1 研究1
下一篇Oracle
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭