是pyasn1无法独立地(不定义新类型)解析下面代码片段中描述的不确定长度构造的数据,还是我的示例不是有效的误码率编码的ASN.1?
如果pyasn1在没有帮助的情况下无法处理这个问题,我还可以求助于另一个python库吗?
# e7 80 : private, constructed, tag 7, indefinite length
# 02 01 44 : integer 0x44
# 02 01 55 : integer 0x55
# 00 00 : end of contents (terminating the 0xe7 object)
data = 'e7 80 02 01 44 02 01 55 00 00'
data = binascii.unhexlify( ''.join(data.split()) )
# throws pyasn1.error.PyAsn1Error: Missing end-of-octets terminator
pyasn1.codec.ber.decoder.decode(data)发布于 2019-06-25 11:57:09
您的示例完全有效(误码率编码)
您甚至可以使用https://asn1.io/asn1playground/来证明
编译以下模式:
Schema DEFINITIONS EXPLICIT TAGS ::=
BEGIN
ASequence::= [PRIVATE 7] IMPLICIT SEQUENCE
{
num1 INTEGER,
num2 INTEGER
}
END和解码e7 80 02 01 44 02 01 55 00 00
结果将是:
> OSS ASN-1Step Version 9.0.1 Copyright (C) 2019 OSS Nokalva, Inc. All
> rights reserved. This product is licensed for use by "OSS Nokalva,
> Inc."
>
> C0043I: 0 error messages, 0 warning messages and 0 informatory
> messages issued.
>
>
> ASN1STEP: Decoding PDU #1 :
>
> ASequence SEQUENCE: tag = [PRIVATE 7] constructed; length = indef
> num1 INTEGER: tag = [UNIVERSAL 2] primitive; length = 1
> 68
> num2 INTEGER: tag = [UNIVERSAL 2] primitive; length = 1
> 85
> EOC
> Successfully decoded 10 bytes. rec1value ASequence ::= { num1 68, num2 85 }请注意,您不需要一个模式来对其进行解码(您只需要松开语义)
您将需要pyasn1的洞察力。尝试在这里打开一个问题:https://github.com/etingof/pyasn1/issues
发布于 2019-06-22 16:34:40
您的示例数据似乎格式错误。我不知道细节,但它似乎涉及到数据的第一个字节'e7‘。我理解这是信息的“类型”。似乎这种类型的数据比你所提供的要多。
我看到使用'30‘作为第一个字节的例子,表示“序列”。这些示例的格式与您的相似。因此,我尝试将示例数据中的“e7”替换为“30”,并且使用此更改,您的代码将无错误地运行。
为了明确我的意思,这段代码是为我运行的,没有错误:
# 30 80 : sequence, indefinite length
# 02 01 44 : integer 0x44
# 02 01 55 : integer 0x55
# 00 00 : end of contents (terminating the 0x30 object)
data = '30 80 02 01 44 02 01 55 00 00'
data = binascii.unhexlify( ''.join(data.split()) )
# throws pyasn1.error.PyAsn1Error: Missing end-of-octets terminator
pyasn1.codec.ber.decoder.decode(data)我相信这表明您的代码是“正确的”。我希望我对这件事了解得更多,这样我就能得到更多的帮助,我想向你解释一下"e7“的类型是什么。没有这一点,我希望这仍然是有帮助的。
https://stackoverflow.com/questions/56716754
复制相似问题