pyasn1:asn1late工具输出在解码期间产生错误

时间:2018-11-05 08:03:51

标签: pyasn1

我根据此链接Pyasn1 how do decoder.decode works?的建议使用asn1late工具转换了asn1定义

下面是我得到的输出,

from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful


class Stkt_Type(univ.Enumerated):
    pass


Stkt_Type.namedValues = namedval.NamedValues(
    ('call', 2),
    ('televoting', 5),
    ('management', 3)
)


class Stkt_obj(univ.Sequence):
    pass


Stkt_obj.componentType = namedtype.NamedTypes(
    namedtype.NamedType('class', univ.Integer()),
    namedtype.NamedType('object', univ.Integer()),
    namedtype.OptionalNamedType('mn', univ.OctetString())
)


class Stkt_evt(univ.Sequence):
    pass


Stkt_evt.componentType = namedtype.NamedTypes(
    namedtype.NamedType('feature', univ.Integer()),
    namedtype.NamedType('subfeat', univ.Integer()),
    namedtype.NamedType('type', univ.Integer()),
    namedtype.NamedType('subtype', univ.Integer()),
    namedtype.NamedType('value', univ.Integer()),
    namedtype.OptionalNamedType('dump', univ.OctetString())
)


class Stkt_tag(univ.Sequence):
    pass


Stkt_tag.componentType = namedtype.NamedTypes(
    namedtype.NamedType('feature', univ.Integer()),
    namedtype.NamedType('subfeat', univ.Integer()),
    namedtype.NamedType('type', univ.Integer()),
    namedtype.NamedType('subtype', univ.Integer()),
    namedtype.NamedType('dump', univ.OctetString())
)


class Stkt_ele(univ.Choice):
    pass


Stkt_ele.componentType = namedtype.NamedTypes(
    namedtype.NamedType('data', Stkt_tag().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
    namedtype.NamedType('evt', Stkt_evt().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
    namedtype.NamedType('obj', Stkt_obj().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
)


class StktVarPart(univ.Sequence):
    pass


StktVarPart.componentType = namedtype.NamedTypes(
    namedtype.NamedType('type', Stkt_Type().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
    namedtype.NamedType('srv-id', univ.Integer().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
    namedtype.NamedType('ele', univ.SequenceOf(componentType=Stkt_ele()))
)

我看到上面的输出不遵循pyASN1文档所述的语法。

请问我对asn1tool的输出还有什么期望吗?

如果我能确认这是正确的,我将不胜感激

因为使用它,我在下面出现错误。

>>> from pyasn1.codec.ber.decoder import decode
>>> with open ('acc30704001', 'rb') as cdrin:
...     received_record, rest_of_substrate = decode(cdrin.read(), asn1Spec=StktVarPart())
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/opt/cdr_dec_py27/venv/local/lib/python2.7/site-packages/pyasn1/codec/ber/decoder.py", line 1293, in __call__
    **options
  File "/opt/cdr_dec_py27/venv/local/lib/python2.7/site-packages/pyasn1/codec/ber/decoder.py", line 71, in valueDecoder
    value, _ = decodeFun(head, asn1Spec, tagSet, length, **options)
  File "/opt/cdr_dec_py27/venv/local/lib/python2.7/site-packages/pyasn1/codec/ber/decoder.py", line 1318, in __call__
    '%s not in asn1Spec: %r' % (tagSet, asn1Spec)
pyasn1.error.PyAsn1Error: <TagSet object at 0x7f95d5aacf50 tags 0:0:0-128:32:17> not in asn1Spec: <StktVarPart schema object at 0x7f95d5aba0d0 componentType=<NamedTypes object at 0x7f95d5aaca10 types <NamedType object at 0x7f95d5aac6d0 type type=<Stkt_Type schema object at 0x7f95d5aac810 namedValues <NamedValues object 0x7f95d5b0d5d0 enums management=3, call=2, televoting=5> tagSet <TagSet object at 0x7f95d5aac7d0 tags 0:0:10-128:32:0>>>, <NamedType object at 0x7f95d5aac750 type srv-id=<Integer schema object at 0x7f95d5aac910 tagSet <TagSet object at 0x7f95d5aac8d0 tags 0:0:2-128:32:1>>>, <NamedType object at 0x7f95d5aac9d0 type ele=<SequenceOf value object at 0x7f95d5aac990 componentType=<Stkt_ele schema object at 0x7f95d5aac850 componentType=<NamedTypes object at 0x7f95d5aac1d0 types <NamedType object at 0x7f95d5aa3690 type data=<Stkt_tag schema object at 0x7f95d5aa3f50 componentType=<NamedTypes object at 0x7f95d5aa35d0 types <NamedType object at 0x7f95d5aa32d0 type feature=<Integer schema object at 0x7f95d5aa3310 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5aa3410 type subfeat=<Integer schema object at 0x7f95d5aa3390 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5aa3490 type type=<Integer schema object at 0x7f95d5aa3450 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5aa3510 type subtype=<Integer schema object at 0x7f95d5aa34d0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5aa3590 type dump=<OctetString schema object at 0x7f95d5aa3550 tagSet <TagSet object at 0x7f95d5af9090 tags 0:0:4> encoding iso-8859-1>>> tagSet=<TagSet object at 0x7f95d5aa3ed0 tags 0:32:16-128:32:0> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5b03210> sizeSpec=<ConstraintsIntersection object at 0x7f95d5b03250>>>, <NamedType object at 0x7f95d5aa3f90 type evt=<Stkt_evt schema object at 0x7f95d5aac090 componentType=<NamedTypes object at 0x7f95d5b188d0 types <NamedType object at 0x7f95d5b18590 type feature=<Integer schema object at 0x7f95d5b181d0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5b18690 type subfeat=<Integer schema object at 0x7f95d5b18610 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5b18710 type type=<Integer schema object at 0x7f95d5b186d0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5b18790 type subtype=<Integer schema object at 0x7f95d5b18750 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5b18810 type value=<Integer schema object at 0x7f95d5b187d0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <OptionalNamedType object at 0x7f95d5b18890 type dump=<OctetString schema object at 0x7f95d5b18850 tagSet <TagSet object at 0x7f95d5af9090 tags 0:0:4> encoding iso-8859-1>>> tagSet=<TagSet object at 0x7f95d5aac050 tags 0:32:16-128:32:1> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5b03210> sizeSpec=<ConstraintsIntersection object at 0x7f95d5b03250>>>, <NamedType object at 0x7f95d5aac0d0 type obj=<Stkt_obj schema object at 0x7f95d5aac190 componentType=<NamedTypes object at 0x7f95d5b18110 types <NamedType object at 0x7f95d5b0ded0 type class=<Integer schema object at 0x7f95d5b0dbd0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <NamedType object at 0x7f95d5b18050 type object=<Integer schema object at 0x7f95d5b0dfd0 tagSet <TagSet object at 0x7f95d5aef950 tags 0:0:2>>>, <OptionalNamedType object at 0x7f95d5b180d0 type mn=<OctetString schema object at 0x7f95d5b18090 tagSet <TagSet object at 0x7f95d5af9090 tags 0:0:4> encoding iso-8859-1>>> tagSet=<TagSet object at 0x7f95d5aac150 tags 0:32:16-128:32:2> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5b03210> sizeSpec=<ConstraintsIntersection object at 0x7f95d5b03250>>>> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5b03890> sizeSpec=<ConstraintsIntersection object at 0x7f95d5b03910 consts <ValueSizeConstraint object at 0x7f95d5b038d0 consts 1, 1>> tagSet=<TagSet object at 0x7f95d5b036d0 untagged>> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5af9c10> sizeSpec=<ConstraintsIntersection object at 0x7f95d5af9c50> tagSet=<TagSet object at 0x7f95d5af9b10 tags 0:32:16>>>> subtypeSpec=<ConstraintsIntersection object at 0x7f95d5b03210> sizeSpec=<ConstraintsIntersection object at 0x7f95d5b03250> tagSet=<TagSet object at 0x7f95d5b03110 tags 0:32:16>>

0 个答案:

没有答案