【发布时间】:2019-11-22 06:34:59
【问题描述】:
我正在尝试构建一个包含可变大小整数列表的 ASN.1 类型,并像这样尝试过
class ASNBigInteger(Integer):
"""
A subtype of the pyasn1 Integer type to support
bigger numbers
"""
subtypeSpec = ValueRangeConstraint(0x1, 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141)
class ANSBigIntegerList(univ.SequenceOf):
"""
A subytpe of Sequenceof for variable length
list of BigIntegers
"""
componentType = ASNBigInteger()
subtypeSpec = ValueSizeConstraint(1, 9223372036854775807)
class ASNMLSAGSignature(Sequence):
"""
ASN.1 type specification for MLSAG
Ring Signature
"""
componentType = NamedTypes(
NamedType('Ix', ASNBigInteger()),
NamedType('Iy', ASNBigInteger()),
NamedType('c0', ASNBigInteger()),
NamedType('sl', ANSBigIntegerList())
)
尝试使用这种类型:
def get_asn1_encoded(self) -> str:
"""
Get the ring signature as der encoded
:return: asn encoded signature
"""
asn = ASNMLSAGSignature()
asn["Ix"] = self.I().x()
asn["Iy"] = self.I().y()
asn["c0"] = self.c0()
asn["sl"] = self.sl()
serialized = encode(asn)
return serialized.hex()
(注意 self.sl() 返回一个整数列表) 在我设置 sl 值的那一行,我得到了这个错误:
KeyError: PyAsn1Error('NamedTypes can cast only scalar values',)
我需要如何将 python 列表转换为 ASN.1 列表,或者我的类型定义有什么问题吗?
【问题讨论】: