1

ケース :- pyasn1 を使用して BER でエンコードされたデータをデコードする必要がありますが、タグの順序が異なる場合があります。そのため、データのデコード中にエラーが発生します。オプションのタグですが、タグの順序は本当に重要ですか?

注:- (ケース 1) 1 つの CDR に 8 つの異なるタグが順番に並んでいます: AF 30 81 82 83 84 85 86

     (case2)Another 8 Tags is in order : AF 30 81 83 84 85 86 82

しかし、単一のデコード構造で両方の順序をデコードする必要があります。それは可能ですか?

ここでは、参照用に私の構造を示しています....

クラス ChangeOfCharCondition(univ.Sequence):

componentType = namedtype.NamedTypes(

namedtype.OptionalNamedType('Requested', univ.OctetString().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))

namedtype.OptionalNamedType('Negotiated', univ.OctetString().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),

namedtype.OptionalNamedType('Uplink', univ.Integer().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),

namedtype.OptionalNamedType('Downlink', univ.Integer().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),

namedtype.NamedType('changeCondition', univ.Integer().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),

namedtype.NamedType('changeTime', univ.OctetString().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6)))
    )

クラス TrafficVolumes(univ.SequenceOf):

tagSet = baseTagSet = tag.initTagSet(tag.Tag(tag.tagClassContext,
                                             tag.tagFormatSimple, 15))

componentType = ChangeOfCharCondition()

クラス Cdr(univ.Set):

tagSet = baseTagSet = tag.initTagSet(tag.Tag(tag.tagClassContext,
                                             tag.tagFormatSimple, 20))
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType('TrafficVolumes', TrafficVolumes().subtype(
    implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 15))))

サンプルデータ(case1) - bytearray('\xaf200\x81\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x82\x0cx01\x12Q\x1fs\x96HHv\ xfa\xff\xff\x83\x01\x00\x84\x01\x00\x85\x01\x02\x86\t\x12\x12\x10\x12\x00P+\x050') で正常に動作します

サンプルデータ(case2) - bytearray('\xaf200\x81\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x83\x01\x00\x84\x01\ x00\x85\x01\x02\x86\t\x12\x12\x10\x12\x00P+\x050\x82\x0cx01\x12Q\x1fs\x96HHv\xfa\xff\xff') この場合、 PyAsn1Error : TagSet(Tag(tagClass=128, tagFormat=0, tagId=2)) asn1Spec にありません: None'

4

0 に答える 0