0

我是 Python 和 PYASN1 的新手,如何表达以下结构?有什么我可以参考的文件吗?我在internet上搜索,有一个关于PYASN1的小文档

OtherInfo ::= SEQUENCE {
       keyInfo KeySpecificInfo,
       partyAInfo [0] OCTET STRING OPTIONAL,
       suppPubInfo [2] OCTET STRING
     }

KeySpecificInfo ::= SEQUENCE {
    algorithm OBJECT IDENTIFIER,
    counter OCTET STRING SIZE (4..4) }
4

1 回答 1

0

应该是这样的,假设您的 ASN.1 模块默认声明显式标记。

此外,文档.

class KeySpecificInfo(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('algorithm', ObjectIdentifier()),
        namedtype.NamedType(
            'counter', OctetString().subtype(subtypeSpec=ValueSizeConstraint(4, 4)))
    )

class OtherInfo(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('keyInfo', KeySpecificInfo()),
        namedtype.OptionalNamedType('partyAInfo', OctetString().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)),
        namedtype.NamedType('suppPubInfo', OctetString().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
    )
于 2019-03-05T17:39:03.453 回答