Skip to content

Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7 and 3.5+.

License

Notifications You must be signed in to change notification settings

andrivet/python-asn1

This branch is 208 commits ahead of geertj/python-asn1:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

dd59aae · May 3, 2025
May 3, 2025
May 3, 2025
May 3, 2025
May 3, 2025
Mar 3, 2025
May 3, 2025
May 3, 2025
Mar 30, 2020
Feb 20, 2025
Dec 16, 2016
Mar 30, 2020
Feb 20, 2025
Apr 5, 2020
May 3, 2025
Feb 20, 2025
Feb 20, 2025
Feb 20, 2025
Mar 3, 2025
May 3, 2025
Mar 3, 2025
Sep 7, 2024
Oct 29, 2021
May 3, 2025
Feb 20, 2025

Repository files navigation

GitHub Actions PyPI Package latest release PyPI Wheel Supported versions Supported implementations

Overview

Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7 and 3.5+.

Features

  • Support BER (parser) and DER (parser and generator) encoding (including indefinite lengths)
  • 100% python, compatible with version 2.7, 3.5 and higher
  • Can be integrated by just including a file into your project
  • Support most common ASN.1 types including REAL (encoding and decoding).

Dependencies

Python-ASN1 relies on Python-Future for Python 2 and 3 compatibility. To install Python-Future:

pip install future

Python-ASN1 relies on type hints. For Python 2.7, a backport of the standard library typing module has to be installed:

pip install typing

This is not necessary for Python 3.5 and higher since it is part of the standard library.

How to install Python-asn1

Install from PyPi with the following:

pip install asn1

or download the repository from GitHub and install with the following:

python setup.py install

You can also simply include asn1.py into your project.

How to use Python-asn1

Note

You can find more detailed documentation on the Usage page.

Encoding

If you want to encode data and retrieve its DER-encoded representation, use code such as:

import asn1

encoder = asn1.Encoder()
encoder.start()
encoder.write('1.2.3', asn1.Numbers.ObjectIdentifier)
encoded_bytes = encoder.output()

Decoding

If you want to decode ASN.1 from DER or BER encoded bytes, use code such as:

import asn1

decoder = asn1.Decoder()
decoder.start(encoded_bytes)
tag, value = decoder.read()

Documentation

The complete documentation is available on Read The Docs:

python-asn1.readthedocs.io

License

Python-ASN1 is free software that is made available under the MIT license. Consult the file LICENSE that is distributed together with this library for the exact licensing terms.

Copyright

The following people have contributed to Python-ASN1. Collectively they own the copyright of this software.

About

Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7 and 3.5+.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.3%
  • Dockerfile 0.7%