Skip to main content

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

Project description

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 (except indefinite lengths)

  • 100% python, compatible with version 2.7, 3.5 and higher

  • Can be integrated by just including a file into your project

Dependencies

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

pip install future

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

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.

Changelog

2.7.0 (2023-01-17)

  • Add context manager support (thanks to Mastermind-U)

2.6.0 (2022-07-15)

  • Add support for GeneralizedTime (thanks to vollkorntomate)

2.5.0 (2022-03-03)

  • Fixes to BitString decoding and encoding of IA5String and UTCTime (thanks to 0xbf00)

2.4.2 (2021-10-29)

  • Fix a minor mistake in the dump.py example

  • Add Python 3.9 and 3.10

2.4.1 (2020-07-16)

  • Fix #89 - Replace explicit references to enum34 by enum-compat

2.4.0 (2020-06-23)

  • Fix #21 - Invalid decoding in non-Universal classes

  • Fix #57 - Invalid encoding of non-Universal classes

2.3.1 (2020-04-06)

  • No change in code, only in packaging and in texts (README, …)

2.3.0 (2020-04-05)

  • Tests: Replace nose by pytest

  • Add Python 3.8, remove Python 3.4 support

  • PR#26 (from rumbah): Add test for default (implicit) encoding types

  • PR#25 (from thomwiggers): Attempt to support BIT STRING

  • Fix wrong example code, see #27

  • (from jcrowgey) Makes the package usable with pip install

  • Remove support of Python 3.3 (some dependencies do not support 3.3)

  • PR#15 (from ThePlasmaRailgun) Fix parsing of object identifier

  • PR#10 (from robinleander): Allow user to determine decoding tagtype

2.2.0 (2017-10-30)

  • Use “true” enums instead of classes. Use enun34 backport for old Python versions.

2.1.1 (2017-10-30)

  • Fix a bug (#9): two’s complement corner case with values such as -32769. Add new test cases to test them.

2.1.0 (2016-12-18)

  • Add more documentation

  • Use (simulated) enumerations

  • Add Python 2.6 in automated checks and tests

  • Add type hints (for static checking) and fix some code

2.0.0 (2016-12-16)

  • First public release by Sebastien Andrivet

  • Support both python 2 and 3 (with Python-Future)

  • All strings are now in unicode

  • Add more ASN.1 tags (like PrintableString)

  • Fix errors in the example (dump.py)

  • Code reorganization

0.9 (2011-05-18)

  • Initial public release by Geert Jansen

Project details


Download files

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

Source Distribution

asn1-2.7.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asn1-2.7.0-py2.py3-none-any.whl (10.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file asn1-2.7.0.tar.gz.

File metadata

  • Download URL: asn1-2.7.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for asn1-2.7.0.tar.gz
Algorithm Hash digest
SHA256 44c0fc3d28c6a926e4d4959ffbc1bccf37faf4dca07520ba2e9b1b5b36fe0bda
MD5 6c8d13a79629e210d28623a8f2d728c0
BLAKE2b-256 2a9f9a45cbf77edbf85006bbd6d0067cc87b6a9291e12b2c958d818132e7e04d

See more details on using hashes here.

File details

Details for the file asn1-2.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: asn1-2.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for asn1-2.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 feb01dee1f485ecc1b1c0b66762196baaad22c0e1c89861159413b28393fba33
MD5 e092601c2a2cbbbe14b9fd0229b55276
BLAKE2b-256 70b9983c341cff02fb09a32be5635bf13030e02917d81499900815dae26b738e

See more details on using hashes here.

Supported by

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