8000 Error decoding recursive types · Issue #19 · pyasn1/pyasn1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Error decoding recursive types #19

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
FernandoGM5 opened this issue Dec 29, 2022 · 0 comments
Open

Error decoding recursive types #19

FernandoGM5 opened this issue Dec 29, 2022 · 0 comments

Comments

@FernandoGM5
Copy link

When a defined class has a component of himself, the decoder do wrong with the tags and looses the track for decoding.
How it can be solved?
Thanks

The example:

from pyasn1.codec.ber.decoder import decode # der o ber
from pyasn1.codec.ber.encoder import encode # der o ber
from hexdump import hexdump

from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful

class FloatingPoint(univ.OctetString):
    pass

class Data(univ.Choice):
    pass

Data.componentType = namedtype.NamedTypes(
    namedtype.NamedType('array', univ.SequenceOf(componentType=Data()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
    namedtype.NamedType('structure', univ.SequenceOf(componentType=Data()).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
    namedtype.NamedType('floating-point', FloatingPoint().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
)

dataO=Data()
dataO['floating-point']=b"\x08\x40\xFF\xFF\xF5"
bin=encode(dataO)
hexdump(bin)
    #produces 87 05 08 40 FF FF F5

dataO2=decode(bin,Data())# OK

bin=b"\xa2\x07\x87\x05\x08\x40\xFF\xFF\xF5"
dataO2=decode(bin,Data()) # NOT OK. ERROR:

#pyasn1.error.PyAsn1Error: <TagSet object, tags 128:0:7> not in asn1Spec: <Data schema object, tagSet=<TagSet object, untagged>, subtypeSpec=<ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 1, 1>>, componentType=<NamedTypes object, types >, sizeSpec=<ConstraintsIntersection object>>

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