Skip to main content

ASN.1 tools.

Project description

buildstatus coverage

About

A Python package for ASN.1 parsing, encoding and decoding.

This project is under development and does only support a subset of the ASN.1 specification syntax. BER and PER codecs are also under development.

Project homepage: https://github.com/eerimoq/asn1tools

Documentation: http://asn1tools.readthedocs.org/en/latest

Installation

pip install asn1tools

Example Usage

This is an example ASN.1 specification defining the messages of a fictitious Foo protocol (based on the FooProtocol on Wikipedia).

Foo DEFINITIONS ::= BEGIN

    Question ::= SEQUENCE {
        id        INTEGER,
        question  IA5String
    }

    Answer ::= SEQUENCE {
        id        INTEGER,
        answer    BOOLEAN
    }

END

Compile the ASN.1 specification, and encode and decode a question using the default codec (BER).

>>> import asn1tools
>>> foo = asn1tools.compile_file('tests/files/foo.asn')
>>> encoded = foo.encode('Question', {'id': 1, 'question': 'Is 1+1=3?'})
>>> encoded
bytearray(b'0\x0e\x02\x01\x01\x16\x09Is 1+1=3?')
>>> foo.decode('Question', encoded)
{'id': 1, 'question': 'Is 1+1=3?'}

The same ASN.1 specification, but using the PER codec.

>>> import asn1tools
>>> foo = asn1tools.compile_file('tests/files/foo.asn', 'per')
>>> encoded = foo.encode('Question', {'id': 1, 'question': 'Is 1+1=3?'})
>>> encoded
bytearray(b'\x01\x01\tIs 1+1=3?')
>>> foo.decode('Question', encoded)
{'id': 1, 'question': 'Is 1+1=3?'}

See the examples folder for additional examples

Contributing

  1. Fork the repository.

  2. Implement the new feature or bug fix.

  3. Implement test case(s) to ensure that future changes do not break legacy.

  4. Run the tests.

    make test
  5. Create a pull request.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asn1tools-0.9.0.tar.gz (103.6 kB view details)

Uploaded Source

Built Distribution

asn1tools-0.9.0-py2.py3-none-any.whl (17.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file asn1tools-0.9.0.tar.gz.

File metadata

  • Download URL: asn1tools-0.9.0.tar.gz
  • Upload date:
  • Size: 103.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asn1tools-0.9.0.tar.gz
Algorithm Hash digest
SHA256 fa7fae40e890868ec1cec3329609d0fd4dd9c38e45f49559f30e3f60a1b085ef
MD5 a42de761aa21ee643442eb0e2f3d96da
BLAKE2b-256 e9096ab03748d3839ebf584abc2d32791dc01802de76717bd002131eeb7927b3

See more details on using hashes here.

File details

Details for the file asn1tools-0.9.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for asn1tools-0.9.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 790fd80e6b8245223c4f471dbb0cba841e81d82e0dd2f572426a15f61e3570ac
MD5 5db310eac2f49337aeaa2a4b6989de8c
BLAKE2b-256 925a1b53329020eaef2335014a1f875177acefb93d6f90ae0e9ef7468c2b834c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page