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
Fork the repository.
Implement the new feature or bug fix.
Implement test case(s) to ensure that future changes do not break legacy.
Run the tests.
make testCreate a pull request.
Metadata
Release files for asn1tools 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| asn1tools-0.9.0.tar.gz | 103.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asn1tools-0.9.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 121.5 kB
Release files / asn1tools-0.9.0.tar.gz
| Download URL | asn1tools-0.9.0.tar.gz |
|---|---|
| Size | 103.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa7fae40e890868ec1cec3329609d0fd4dd9c38e45f49559f30e3f60a1b085ef
|
|
BLAKE2b-256 checksum How to use checksums |
e9096ab03748d3839ebf584abc2d32791dc01802de76717bd002131eeb7927b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / asn1tools-0.9.0-py2.py3-none-any.whl
| Download URL | asn1tools-0.9.0-py2.py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
790fd80e6b8245223c4f471dbb0cba841e81d82e0dd2f572426a15f61e3570ac
|
|
BLAKE2b-256 checksum How to use checksums |
925a1b53329020eaef2335014a1f875177acefb93d6f90ae0e9ef7468c2b834c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |