{"id":15297018,"url":"https://github.com/eerimoq/asn1tools","last_synced_at":"2025-05-15T12:04:11.418Z","repository":{"id":23480974,"uuid":"99156277","full_name":"eerimoq/asn1tools","owner":"eerimoq","description":"ASN.1 parsing, encoding and decoding.","archived":false,"fork":false,"pushed_at":"2024-07-13T17:45:51.000Z","size":5285,"stargazers_count":307,"open_issues_count":66,"forks_count":105,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-14T07:51:29.619Z","etag":null,"topics":["asn1","ber","c","der","gser","jer","oer","per","python","uper","xer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eerimoq.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"eerimoq"}},"created_at":"2017-08-02T20:05:05.000Z","updated_at":"2025-04-30T16:16:55.000Z","dependencies_parsed_at":"2023-01-13T23:22:13.398Z","dependency_job_id":"88e82c30-057a-4eaa-8428-1e7f1757eba3","html_url":"https://github.com/eerimoq/asn1tools","commit_stats":{"total_commits":1307,"total_committers":18,"mean_commits":72.61111111111111,"dds":"0.12318286151491964","last_synced_commit":"de25657f7c79100d1ba5312dd7474ff3e0d0ad2e"},"previous_names":[],"tags_count":196,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eerimoq%2Fasn1tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eerimoq%2Fasn1tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eerimoq%2Fasn1tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eerimoq%2Fasn1tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eerimoq","download_url":"https://codeload.github.com/eerimoq/asn1tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asn1","ber","c","der","gser","jer","oer","per","python","uper","xer"],"created_at":"2024-09-30T19:14:22.483Z","updated_at":"2025-05-15T12:04:06.404Z","avatar_url":"https://github.com/eerimoq.png","language":"Python","funding_links":["https://github.com/sponsors/eerimoq"],"categories":[],"sub_categories":[],"readme":"|coverage|_\n|codecov|_\n|nala|_\n\nAbout\n=====\n\nA Python package for `ASN.1`_ parsing, encoding and decoding.\n\nThis project is *under development* and does only support a subset\nof the ASN.1 specification syntax.\n\nSupported codecs:\n\n- Basic Encoding Rules (BER)\n- Distinguished Encoding Rules (DER)\n- Generic String Encoding Rules (GSER)\n- JSON Encoding Rules (JER)\n- Basic Octet Encoding Rules (OER)\n- Aligned Packed Encoding Rules (PER)\n- Unaligned Packed Encoding Rules (UPER)\n- XML Encoding Rules (XER)\n\nMiscellaneous features:\n\n- `C` source code generator for OER and UPER (with some limitations).\n\nProject homepage: https://github.com/eerimoq/asn1tools\n\nDocumentation: http://asn1tools.readthedocs.org/en/latest\n\nKnown limitations\n=================\n\n- The ``CLASS`` keyword (X.681) and its friends are not yet supported.\n\n- Parametrization (X.683) is not yet supported.\n\n- The ``EMBEDDED PDV`` type is not yet supported.\n\n- The ``ANY`` and ``ANY DEFINED BY`` types are not supported. They\n  were removed from the ASN.1 standard 1994.\n\n- ``WITH COMPONENT`` and ``WITH COMPONENTS`` constraints are ignored,\n  except for OER ``REAL``.\n\n- The ``DURATION`` type is not yet supported.\n\nInstallation\n============\n\n.. code-block:: python\n\n    pip install asn1tools\n\nExample Usage\n=============\n\nThis is an example ASN.1 specification defining the messages of a\nfictitious Foo protocol (based on the FooProtocol on Wikipedia).\n\n.. code-block:: text\n\n   Foo DEFINITIONS ::= BEGIN\n\n       Question ::= SEQUENCE {\n           id        INTEGER,\n           question  IA5String\n       }\n\n       Answer ::= SEQUENCE {\n           id        INTEGER,\n           answer    BOOLEAN\n       }\n\n   END\n\nScripting\n---------\n\n`Compile`_ the ASN.1 specification, and `encode`_ and `decode`_ a\nquestion using the default codec (BER).\n\n.. code-block:: python\n\n   \u003e\u003e\u003e import asn1tools\n   \u003e\u003e\u003e foo = asn1tools.compile_files('tests/files/foo.asn')\n   \u003e\u003e\u003e encoded = foo.encode('Question', {'id': 1, 'question': 'Is 1+1=3?'})\n   \u003e\u003e\u003e encoded\n   bytearray(b'0\\x0e\\x02\\x01\\x01\\x16\\x09Is 1+1=3?')\n   \u003e\u003e\u003e foo.decode('Question', encoded)\n   {'id': 1, 'question': 'Is 1+1=3?'}\n\nThe same ASN.1 specification, but using the PER codec.\n\n.. code-block:: python\n\n   \u003e\u003e\u003e import asn1tools\n   \u003e\u003e\u003e foo = asn1tools.compile_files('tests/files/foo.asn', 'per')\n   \u003e\u003e\u003e encoded = foo.encode('Question', {'id': 1, 'question': 'Is 1+1=3?'})\n   \u003e\u003e\u003e encoded\n   bytearray(b'\\x01\\x01\\tIs 1+1=3?')\n   \u003e\u003e\u003e foo.decode('Question', encoded)\n   {'id': 1, 'question': 'Is 1+1=3?'}\n\nSee the `examples`_ folder for additional examples.\n\nCommand line tool\n-----------------\n\nThe shell subcommand\n^^^^^^^^^^^^^^^^^^^^\n\nUse the command line shell to convert data between given formats. The\ndefault input codec is BER and output codec is GSER (produces human\nreadable text).\n\n.. code-block:: text\n\n   \u003e asn1tools shell\n\n   Welcome to the asn1tools shell!\n\n   $ help\n   Commands:\n     compile\n     convert\n     exit\n     help\n   $ compile tests/files/foo.asn\n   $ convert Question 300e0201011609497320312b313d333f\n   question Question ::= {\n       id 1,\n       question \"Is 1+1=3?\"\n   }\n   $ compile --output-codec xer tests/files/foo.asn\n   $ convert Question 300e0201011609497320312b313d333f\n   \u003cQuestion\u003e\n       \u003cid\u003e1\u003c/id\u003e\n       \u003cquestion\u003eIs 1+1=3?\u003c/question\u003e\n   \u003c/Question\u003e\n   $ compile -o uper tests/files/foo.asn\n   $ convert Question 300e0201011609497320312b313d333f\n   01010993cd03156c5eb37e\n   $ exit\n   \u003e\n\nThe convert subcommand\n^^^^^^^^^^^^^^^^^^^^^^\n\nConvert given encoded Question from BER to GSER (produces human\nreadable text).\n\n.. code-block:: text\n\n   \u003e asn1tools convert tests/files/foo.asn Question 300e0201011609497320312b313d333f\n   question Question ::= {\n       id 1,\n       question \"Is 1+1=3?\"\n   }\n   \u003e\n\nConvert given encoded Question from UPER to XER (xml).\n\n.. code-block:: text\n\n   \u003e asn1tools convert -i uper -o xer tests/files/foo.asn Question 01010993cd03156c5eb37e\n   \u003cQuestion\u003e\n       \u003cid\u003e1\u003c/id\u003e\n       \u003cquestion\u003eIs 1+1=3?\u003c/question\u003e\n   \u003c/Question\u003e\n   \u003e\n\nConvert given encoded Question from UPER to JER (json).\n\n.. code-block:: text\n\n   \u003e asn1tools convert -i uper -o jer tests/files/foo.asn Question 01010993cd03156c5eb37e\n   {\n       \"id\": 1,\n       \"question\": \"Is 1+1=3?\"\n   }\n   \u003e\n\nContinuously convert encoded Questions read from standard input. Any\nline that cannot be converted is printed as is, in this example the\ndates.\n\n.. code-block:: text\n\n   \u003e cat encoded.txt\n   2018-02-24 11:22:09\n   300e0201011609497320312b313d333f\n   2018-02-24 11:24:15\n   300e0201021609497320322b323d353f\n   \u003e cat encoded.txt | asn1tools convert tests/files/foo.asn Question -\n   2018-02-24 11:22:09\n   question Question ::= {\n       id 1,\n       question \"Is 1+1=3?\"\n   }\n   2018-02-24 11:24:15\n   question Question ::= {\n       id 2,\n       question \"Is 2+2=5?\"\n   }\n   \u003e\n\nThe convert subcommand with a cache\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nConvert given encoded PCCH-Message from UPER to GSER with the\n``--cache-dir`` option set to ``my_cache``. Using a cache\nsignificantly reduces the command execution time after the first call.\n\n.. code-block:: text\n\n   \u003e time asn1tools convert --cache-dir my_cache -i uper tests/files/3gpp/rrc_8_6_0.asn PCCH-Message 28\n   pcch-message PCCH-Message ::= {\n       message c1 : paging : {\n           systemInfoModification true,\n           nonCriticalExtension {\n           }\n       }\n   }\n\n   real    0m2.090s\n   user    0m1.977s\n   sys     0m0.032s\n   \u003e time asn1tools convert --cache-dir my_cache -i uper tests/files/3gpp/rrc_8_6_0.asn PCCH-Message 28\n   pcch-message PCCH-Message ::= {\n       message c1 : paging : {\n           systemInfoModification true,\n           nonCriticalExtension {\n           }\n       }\n   }\n\n   real    0m0.276s\n   user    0m0.197s\n   sys     0m0.026s\n   \u003e\n\nThe parse subcommand\n^^^^^^^^^^^^^^^^^^^^\n\nParse given ASN.1 specification and write it as a Python dictionary to\ngiven file. Use the created file to convert given encoded Question\nfrom BER to GSER (produces human readable text). The conversion is\nsignificantly faster than passing .asn-file(s) to the convert\nsubcommand, especially for larger ASN.1 specifications.\n\n.. code-block:: text\n\n   \u003e asn1tools parse tests/files/foo.asn foo.py\n   \u003e asn1tools convert foo.py Question 300e0201011609497320312b313d333f\n   question Question ::= {\n       id 1,\n       question \"Is 1+1=3?\"\n   }\n   \u003e\n\nThe generate C source subcommand\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGenerate OER or UPER C source code from an ASN.1 specification.\n\nNo dynamic memory is used in the generated code. To achieve this all\ntypes in the ASN.1 specification must have a known maximum size,\ni.e. ``INTEGER (0..7)``, ``OCTET STRING (SIZE(12))``, etc.\n\nBelow is an example generating OER C source code from\n`tests/files/c_source/c_source.asn`_.\n\n.. code-block:: text\n\n   \u003e asn1tools generate_c_source --namespace oer tests/files/c_source/c_source.asn\n   Successfully generated oer.h and oer.c.\n\nThe same as above, but generate UPER C source code instead of OER.\n\n.. code-block:: text\n\n   \u003e asn1tools generate_c_source --codec uper --namespace uper tests/files/c_source/c_source.asn\n   Successfully generated uper.h and uper.c.\n\nThe same as the first example, but also generate fuzz testing C source\ncode for `libFuzzer`_.\n\n.. code-block:: text\n\n   \u003e asn1tools generate_c_source --namespace oer --generate-fuzzer tests/files/c_source/c_source.asn\n   Successfully generated oer.h and oer.c.\n   Successfully generated oer_fuzzer.c and oer_fuzzer.mk.\n\n   Run \"make -f oer_fuzzer.mk\" to build and run the fuzzer. Requires a\n   recent version of clang.\n\nSee `oer.h`_, `oer.c`_, `uper.h`_, `uper.c`_, `oer_fuzzer.c`_ and\n`oer_fuzzer.mk`_ for the contents of the generated files.\n\nLimitations by design:\n\n- Only the types ``BOOLEAN``, ``INTEGER``, ``NULL``, ``OCTET STRING``,\n  ``BIT STRING``, ``ENUMERATED``, ``SEQUENCE``, ``SEQUENCE OF``, and ``CHOICE``\n  are supported. The OER generator also supports ``REAL``.\n\n- All types must have a known maximum size, i.e. ``INTEGER (0..7)``,\n  ``OCTET STRING (SIZE(12))``.\n\n- ``INTEGER`` must be 64 bits or less.\n\n- ``REAL`` must be IEEE 754 binary32 or binary64. binary32 is\n  generated as ``float`` and binary64 as ``double``.\n\n- Recursive types are not supported.\n\nKnown limitations:\n\n- Extension additions (``...``) are only supported in the OER generator.\n  See `compact_extensions_uper`_ for how to make UPER ``CHOICE`` and\n  ``SEQUENCE`` extendable without using ``...``.\n\n- Named numbers in ``ENUMERATED`` are not yet supported.\n\nOther OER and/or UPER C code generators:\n\n- https://github.com/vlm/asn1c\n\n- https://github.com/ttsiodras/asn1scc\n\nSee the `benchmark example`_ for a comparison of `asn1c`, `asn1scc`\nand `asn1tools`.\n\nContributing\n============\n\n#. Fork the repository.\n\n#. Install prerequisites.\n\n   .. code-block:: text\n\n      pip install -r requirements.txt\n\n#. Implement the new feature or bug fix.\n\n#. Implement test case(s) to ensure that future changes do not break\n   legacy.\n\n#. Run the tests.\n\n   .. code-block:: text\n\n      make test\n\n#. Create a pull request.\n\nSpecifications\n==============\n\nASN.1 specifications released by ITU and IETF.\n\nGeneral\n-------\n\n- `X.680: Specification of basic notation\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf\u003e`_\n\n- `X.681: Information object specification\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.681-0207.pdf\u003e`_\n\n- `X.682: Constraint specification\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.682-0207.pdf\u003e`_\n\n- `X.683: Parameterization of ASN.1 specifications\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.683-0207.pdf\u003e`_\n\nEncodings\n---------\n\n- `X.690: Specification of Basic Encoding Rules (BER), Canonical\n  Encoding Rules (CER) and Distinguished Encoding Rules (DER)\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf\u003e`_\n\n- `X.691: Specification of Packed Encoding Rules (PER)\n  \u003chttps://www.itu.int/rec/dologin_pub.asp?lang=e\u0026id=T-REC-X.691-201508-I!!PDF-E\u0026type=items\u003e`_\n\n- `X.693: XML Encoding Rules (XER)\n  \u003chttps://www.itu.int/ITU-T/studygroups/com17/languages/X.693-0112.pdf\u003e`_\n\n- `X.696: Specification of Octet Encoding Rules (OER)\n  \u003chttps://www.itu.int/rec/dologin_pub.asp?lang=e\u0026id=T-REC-X.696-201508-I!!PDF-E\u0026type=items\u003e`_\n\n- `RFC 3641: Generic String Encoding Rules (GSER) for ASN.1\n  \u003chttps://tools.ietf.org/html/rfc3641\u003e`_\n\n- `Overview of the JSON Encoding Rules (JER)\n  \u003chttp://www.oss.com/asn1/resources/asn1-papers/Overview_of_JER.pdf\u003e`_\n\n.. |coverage| image:: https://coveralls.io/repos/github/eerimoq/asn1tools/badge.svg?branch=master\n.. _coverage: https://coveralls.io/github/eerimoq/asn1tools\n\n.. |codecov| image:: https://codecov.io/gh/eerimoq/asn1tools/branch/master/graph/badge.svg\n.. _codecov: https://codecov.io/gh/eerimoq/asn1tools\n\n.. |nala| image:: https://img.shields.io/badge/nala-test-blue.svg\n.. _nala: https://github.com/eerimoq/nala\n\n.. _ASN.1: https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One\n\n.. _Compile: http://asn1tools.readthedocs.io/en/latest/#asn1tools.compile_files\n.. _encode: http://asn1tools.readthedocs.io/en/latest/#asn1tools.compiler.Specification.encode\n.. _decode: http://asn1tools.readthedocs.io/en/latest/#asn1tools.compiler.Specification.decode\n.. _examples: https://github.com/eerimoq/asn1tools/tree/master/examples\n\n.. _tests/files/c_source/c_source.asn: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/c_source.asn\n\n.. _oer.h: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/oer.h\n\n.. _oer.c: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/oer.c\n\n.. _uper.h: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/uper.h\n\n.. _uper.c: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/uper.c\n\n.. _oer_fuzzer.c: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/oer_fuzzer.c\n\n.. _oer_fuzzer.mk: https://github.com/eerimoq/asn1tools/blob/master/tests/files/c_source/oer_fuzzer.mk\n\n.. _libFuzzer: https://llvm.org/docs/LibFuzzer.html\n\n.. _benchmark example: https://github.com/eerimoq/asn1tools/blob/master/examples/benchmarks/c_source\n\n.. _compact_extensions_uper: https://github.com/eerimoq/asn1tools/blob/master/examples/compact_extensions_uper\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feerimoq%2Fasn1tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feerimoq%2Fasn1tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feerimoq%2Fasn1tools/lists"}