Skip to main content

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.

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.

Metadata

Release files for bran 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bran 0.4.0
File Size Uploaded
bran-0.4.0.tar.gz 19.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bran 0.4.0
File Interpreter ABI Platform
bran-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 27.0 kB

Release files / bran-0.4.0.tar.gz

Download URL bran-0.4.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
17086b1339ae7e58771b7fd2407f053e97299a7c0357992cc383b5c7748e2dc3
BLAKE2b-256 checksum
How to use checksums
8ea91c9801925c1516b089463381a7db9bada5b021aec0da49366532b730efbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / bran-0.4.0-py2.py3-none-any.whl

Download URL bran-0.4.0-py2.py3-none-any.whl
Size 7.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
24420bfc0282451f9916cb3dce2880cad7a1643f0646b015499e429e59dc2c3f
BLAKE2b-256 checksum
How to use checksums
d0733739af5af55f9e27b612aa8eb678421c1bb19d2daa1984c6330a6717f1f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page