10000 issue when constructed tag follow an optional tag in prettyPrint() · Issue #84 · pyasn1/pyasn1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

issue when constructed tag follow an optional tag in prettyPrint() #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
didijuve opened this issue Mar 13, 2025 · 0 comments
Open

Comments

@didijuve
Copy link

Hello,
when I try to prettyPrint some data with this grammar, i've got an error :

pyasn1.error.PyAsn1Error: Constructed tag format expected.


from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
from binascii import hexlify, unhexlify
from pyasn1.codec.der import decoder

class Octet16(univ.OctetString):
pass

Octet16.subtypeSpec = constraint.ValueSizeConstraint(16, 16)

class OctetTo16(univ.OctetString):
pass

OctetTo16.subtypeSpec = constraint.ValueSizeConstraint(1, 16)

class MyListObject(univ.Choice):
pass

MyListObject.componentType = namedtype.NamedTypes(
namedtype.NamedType('firstList', univ.SequenceOf(componentType=univ.Integer()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('secondList', univ.SequenceOf(componentType=univ.Integer()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
namedtype.NamedType('thirdList', univ.SequenceOf(componentType=univ.Integer()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
)

class MyObject(univ.Sequence):
pass

MyObject.componentType = namedtype.NamedTypes(
namedtype.NamedType('Id', char.UTF8String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('Value', Octet16().subtype(implicitTag=tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 26))),
namedtype.NamedType('counter', univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
namedtype.OptionalNamedType('Id2', OctetTo16().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
namedtype.NamedType('objectList', MyListObject())
)

message = '30368009312E322E332E3434345A1089001012012341234012345678901224810102820F5FAFBBC335368BD6D6CA093745D32BA003020101'
code, substrate = decoder.decode(unhexlify(message), asn1Spec=MyObject())
print(code.prettyPrint())


If I remove the optional for the object 'Id2', the prettyPrint() works.
If I remove the object 'thirdList' the prettyPrint() works also.
Is there something wrong in my grammar?

Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0