Skip to main content

Pure Python X.690 implementation

Project description

Pure Python X.690 implementation

Build & Publish Docs

This module contains a pure Python implementation of the “x690” standard for BER encoding/decoding. Other encodings are currently unsupported but pull-requests are welcome.

Type Extensions

It allows defining and detecting new data-types by simply subclassing the base class x690.types.Type. An example for this can be seen in puresnmp

Examples

Encoding to bytes

Encoding to bytes can be done by simply calling the Python builting bytes() on instances from x690.types:

Encoding of a single value

import x690.types as t

>>> myvalue = t.Integer(12)
>>> asbytes = bytes(myvalue)
>>> repr(asbytes)
b'\x02\x01\x0c'

Encoding of a composite value using Sequence

import x690.types as t

>>> myvalue = t.Sequence(
...     t.Integer(12),
...     t.Integer(12),
...     t.Integer(12),
... )
>>> asbytes = bytes(myvalue)
>>> repr(asbytes)
b'0\t\x02\x01\x0c\x02\x01\x0c\x02\x01\x0c'

Decoding from bytes

Decode bytes by calling x690.types.pop_tlv on your byte data. This will return a tuple where the first value contains the decoded object, and the second one will contain any remaining bytes which were not decoded.

import x690.types as t
>>> data = b'0\t\x02\x01\x0c\x02\x01\x0c\x02\x01\x0c'
>>> decoded, remaining_bytes = t.pop_tlv(data)
>>> decoded
Sequence(Integer(12), Integer(12), Integer(12))
>>> remaining_bytes
b''

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

x690-0.2.0.post2.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distribution

x690-0.2.0.post2-py2-none-any.whl (14.4 kB view hashes)

Uploaded Python 2

Supported by

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