Bran provides transcoders for ASN.1 serialization and deserialization, and DER-encoding in Python.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
Jens Finkhaeuser 4aa3d40fa0
Add copyright notice for logo image
5 years ago
.github Add issue and PR templates 5 years ago
bran Bump version: 0.3.0 → 0.4.0 5 years ago
docs Add logo 5 years ago
tests Bump copyright notice 5 years ago
.gitignore Ignore pytest cache 5 years ago
.travis.yml Request trusty from travis 6 years ago
CODE_OF_CONDUCT.md Add CoC and contribution guide 6 years ago
CONTRIBUTING.md Add CoC and contribution guide 6 years ago
LICENSE.txt Fix license 6 years ago
MANIFEST.in Add MANIFEST.in 6 years ago
README.rst Add copyright notice for logo image 5 years ago
appveyor.yml Disable Python 3.4 5 years ago
requirements.txt Project skeleton 6 years ago
setup.cfg Bump version: 0.3.0 → 0.4.0 5 years ago
setup.py Bump version: 0.3.0 → 0.4.0 5 years ago
tox.ini Fix py35 commands 6 years ago

README.rst

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

Logo

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.

Usage

Code

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()
h.update(test)
print(h.hexdigest())  # yields SHA512 hash of the DER serialized test

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

Contributing

See CONTRIBUTING.md for details.

License

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

"Cereal bowl" logo image Copyright (c) Jens Finkhaeuser. All rights reserved. Made by Moreven B.