Code Monkey home page Code Monkey logo

Comments (3)

eerimoq avatar eerimoq commented on July 29, 2024

Please provide a minimal script that can be used to reproduce the error. It speeds up debugging as it eliminates the need of guessing.

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Okay, so it was easy to reproduce:

>>> import asn1tools
>>> foo = asn1tools.compile_string('A DEFINITIONS AUTOMATIC TAGS ::= BEGIN A ::= SEQUENCE SIZE (1..10) OF NULL END', 'uper')
>>> foo.encode('A', [])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    foo.encode('A', [])
  File "/home/erik/workspace/asn1tools/asn1tools/compiler.py", line 138, in encode
    return type_.encode(data, **kwargs)
  File "/home/erik/workspace/asn1tools/asn1tools/codecs/uper.py", line 283, in encode
    return encoder.as_bytearray()
  File "/home/erik/workspace/asn1tools/asn1tools/codecs/per.py", line 247, in as_bytearray
    return bytearray(binascii.unhexlify(value))
binascii.Error: Odd-length string

With encode(..., check_constraints=True) the error is as expected:

>>> foo.encode('A', [], check_constraints=True)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    foo.encode('A', [], check_constraints=True)
  File "/home/erik/workspace/asn1tools/asn1tools/compiler.py", line 136, in encode
    type_.check_constraints(data)
  File "/home/erik/workspace/asn1tools/asn1tools/codecs/compiler.py", line 94, in check_constraints
    return self.constraints_checker.encode(data)
  File "/home/erik/workspace/asn1tools/asn1tools/codecs/constraints_checker.py", line 342, in encode
    self._type.encode(data)
  File "/home/erik/workspace/asn1tools/asn1tools/codecs/constraints_checker.py", line 247, in encode
    length))
asn1tools.codecs.ConstraintsError: Expected a list of between 1 and 10 elements, but got 0.
>>>

The codec design requires check_constraints=True to give proper error messages. That's by design. The constraints checker is disabled by default as it was recently added and probably needs more testing before being enabled by default. Also, enabling it obviously slows down encoding slightly, which shouldn't be a problem in most applications. Better error messages and constraints checks is helpful for the user debugging her application.

from asn1tools.

sudhakarnaidu avatar sudhakarnaidu commented on July 29, 2024

Thank you so much for the information. I will enable "check_constraints" parameter

from asn1tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.