英文:
Explanation of the UPER encoding of an extensible sequence
问题
I have the following ASN.1 SEQENCE type, with the following value, and that produces the below encoding in UPER. I'm interested in why the encoding looks like it does, particularly the start as it's what's consistent across multiple compilers and encoders (both open source and commercial), but from reading the spec I don't understand how it's possible.
The first byte is 1110 0000
, and I don't understand how the start is 111
in the encoding, as from looking at the sequence and value, it feels like it should be 11
, as the first bit is the extension addition presence flag, and the second bit is the first boolean, however I don't know where the third 1
comes from, as from reading the X.691 specification, the next thing should be the normally small integer length determinant of the bitfield of extension additions, and since the number of extension additions is 3, the next bit should be zero to indicate that it's a bitfield of less than 64 bits, followed by the bitfield, but in every implementation the third bit is 1
, is there something I'm missing from the spec that would explain why the third bit is 1
and not 0
?
Edit:
The second byte is 0111 0000
which would imply a bit field length of maybe one (1
), or three 11
, but given the recent answer indicating that there is fact only two extension additions, I'm confused as what the length determinant is supposed to be here for the extensions bitfield.
Schema And Value
G ::= SEQUENCE {
a BOOLEAN,
...,
[[
b BOOLEAN
]],
[[
c BOOLEAN
]],
...,
d BOOLEAN
}
value ::= G {
a TRUE,
b TRUE,
c TRUE,
d TRUE
}
encoding (hexadecimal):
E070180018000A
(Note: I have retained the code sections as requested and only translated the non-code content.)
英文:
I have the following ASN.1 SEQENCE type, with the following value, and that produces the below encoding in UPER. I'm interested in why the encoding looks like it does, particularly the start as it's what's consistent across multiple compilers and encoders (both open source and commercial), but from reading the spec I don't understand how it's possible.
The first byte is 1110 0000
, and I don't understand how the start is 111
in the encoding, as from looking at the sequence and value, it feels like it should be 11
, as the first bit is the extension addition presence flag, and the second bit is the first boolean, however I don't know where the third 1
comes from, as from reading the X.691 specification, the next thing should be the normally small integer length determinant of the bitfield of extension additions, and since the number of extension additions is 3, the next bit should be zero to indicate that it's a bitfield of less than 64 bits, followed by the bitfield, but in every implementation the third bit is 1
, is there something I'm missing from the spec that would explain why the third bit is 1
and not 0
?
Edit:
The second byte is 0111 0000
which would imply a bit field length of maybe one (1
), or three 11
, but given the recent answer indicating that there is fact only two extension additions, I'm confused as what the length determinant is supposed to be here for the extensions bitfield.
Schema And Value
G ::= SEQUENCE {
a BOOLEAN,
...,
[[
b BOOLEAN
]],
[[
c BOOLEAN
]],
...,
d BOOLEAN
}
value ::= G {
a TRUE,
b TRUE,
c TRUE,
d TRUE
}
encoding (hexadecimal):
E070180018000A
答案1
得分: 3
以下是翻译好的部分:
组件 "a" 和 "d" 构成您的序列类型的扩展根。请注意,第二个省略号标志着扩展添加的结束和扩展根的第二部分的开始。
在这个序列类型中,有两个扩展添加组。第一组包含 "b",第二组包含 "c"。PER 编码的第一个比特是 '1',因为序列值包含一个或多个扩展。PER 编码的第二个比特包含组件 "a" 的编码,第三个比特包含组件 "d" 的编码(而不是 "b")。
这是对这种编码的解释:
偏移量(比特),长度(比特),描述
0, 1, 前导
0, 1, 扩展比特('1':序列值被扩展)
1, 1, 根组件 'a'('1':TRUE)
2, 1, 根组件 'd'('1':TRUE)
3, 1, 扩展位图长度的格式('0':一个“通常较小”的长度)
4, 6, 扩展位图的长度('000001':长度为1+1=2比特)--见下面的注释
10, 2, 扩展位图('11')
12, 8, 第一个扩展的长度('00000001':长度为1字节)
20, 8, 第一个扩展
20, 1, 组件 'b'('1':TRUE)
21, 7, 填充('0000000')
28, 8, 第二个扩展的长度('00000001':长度为1字节)
36, 8, 第二个扩展
36, 1, 组件 'c'('1':TRUE)
36, 7, 填充('0000000')
44, 4, 完整编码的最终填充('0000')
总长度:48比特
11100000 01110000 00011000 00000000 00011000 00000000
E0 70 18 00 18 00
注:一个“通常较小的长度”是一个长度决定因素,限制在1..64范围内。这样的长度值必须通过将长度减一编码为6位无符号整数字段来进行编码。
英文:
The components "a" and "d" constitute the extension root of your sequence type. Note that the second ellipsis marks the end of the extension additions and the beginning of the second part of the extension root.
In this sequence type, there are two extension addition groups. The first group contains "b" and the second group contains "c". The first bit of the PER encoding is '1' because the sequence value contains one or more extensions. The second bit of the PER encoding contains the encoding of component "a" and the third bit contains the encoding of component "d" (not "b").
Here is an explanation of this encoding:
offset (bits), length (bits), description
0, 1, preamble
0, 1, extension bit ('1': the sequence value is extended)
1, 1, root component 'a' ('1': TRUE)
2, 1, root component 'd' ('1': TRUE)
3, 1, format of the length of the extension bitmap ('0': a "normally small" length)
4, 6, length of the extension bitmap ('000001': the length is 1+1=2 bits) --see note below
10, 2, extension bitmap ('11')
12, 8, length of the first extension ('00000001': the length is 1 octet)
20, 8, first extension
20, 1, component 'b' ('1': TRUE)
21, 7, padding ('0000000')
28, 8, length of the second extension ('00000001': the length is 1 octet)
36, 8, second extension
36, 1, component 'c' ('1': TRUE)
36, 7, padding ('0000000')
44, 4, final padding of the complete encoding ('0000')
total length: 48 bits
11100000 01110000 00011000 00000000 00011000 00000000
E0 70 18 00 18 00
Note: A "normally small length" is a length determinant that is restricted to the range 1..64. Such a length value must be encoded by encoding the length minus one into a 6-bit unsigned integer field.
答案2
得分: 1
(@Alessandro 先回答了)
显示编码的另一种方式(如在x.691附录中使用)
类型按规范顺序重新组织
G ::= SEQUENCE {
a 布尔值,
d 布尔值,
...,
b 布尔值,
c 布尔值
}
编码的比特。'.' 是八位字节边界
1 存在扩展
1 a 是TRUE
1 d 是TRUE
00000.01 存在2个扩展(长度通常编码为小型)
1 b 存在
1 c 存在
0000.0001 b的长度(1)
1000.0000 b的值为TRUE
0000.0001 c的长度(1)
1000.0000 c的值为TRUE
0000 填充
英文:
(@Alessandro answered first)
Another way to show the encoding (as used in x.691 appendix)
Type reorganized in canonical order
G ::= SEQUENCE {
a BOOLEAN,
d BOOLEAN,
...,
b BOOLEAN,
c BOOLEAN
}
Bits of the encoding. '.' is the octet boundary
1 There are extensions
1 a is TRUE
1 d is TRUE
00000.01 There are 2 extensions (length encoded as normally small)
1 b is present
1 c is present
0000.0001 length of b (1)
1000.0000 value of b TRUE
0000.0001 length of c(1)
1000.0000 value of c TRUE
0000 padding
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论