Skip to main content

DER-Encoded ASN.1 Serialization and Deserialization

Project description

Posix Build Status Windows Build Status Docs License PyPI Python Versions Package Format Package Status

Bran provides transcoders for ASN.1 serialization and deserialization, and DER-encoding.

The purpose is to provide a serialization format for native Python types, such as nested dicts, whose serialization is unambiguous and stable. That is two values with the same contents serialize to the same byte string.

That makes it possible to create hashes and MACs to verify message integrity.

Note that this does not make this package a full implementation of ASN.1 specs. That is not the goal. The goal is just to have a stable byte representation of Python values; DER in particular is only picked because it helps in this.



You just encode some values. In most cases, you’ll want to use the DERTranscoder class.

test = { 'some': { 'nested': 42, 'value': (0, 1, False) } }

from bran import DERTranscoder
transcoder = DERTranscoder()

encoded = transcoder.encode(test)
decoded = transcoder.decode(encoded)

assert decoded == test

In order for bran to be this simple to use, some assumptions are made. The one with the most impact is that any collections.Mapping will be encoded to the same byte representation, which means when decoded, it will become a Python dict. Similar assumptions are made for collections.Set and collections.Sequence.

For the purpose of hashing, consider the following code:

from bran.hash import hasher

test = { 'some': { 'nested': 42, 'value': (0, 1, False) } }

h = hasher()
print(h.hexdigest())  # yields SHA512 hash of the DER serialized test

import hashlib
h = hasher(hashfunc = hashlib.md5)
print(h.hexdigest())  # yields MD5 hash of the DER serialized test


See for details.


Licensed under MITNFA (MIT +no-false-attribs) License. See the LICENSE.txt file for details.

Project details

Download files

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

Files for bran, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size bran-0.4.0-py2.py3-none-any.whl (7.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size bran-0.4.0.tar.gz (19.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page