A EMV BER-TLV encoding/decoding package
Project description
BER-TLV Package
Summary
This is a BER-TLV (described in EMV Book 3) format encoder/decoder library for Python. BER is Basic Encoding Rules. TLV stands for Tag + Length + Value. Tag is 1-4 byte long (integer) identifier. Length is 1-4 byte integer representing value (or entire branch) size. Value is binary data, which can also be a nested list of sub-items. BER-TLV is a binary data storage tree, which is widely used in electonic payment industry and in EMV in particular.
Install
pip3 install ber-tlv
Usage
Parse TLV:
from ber_tlv.tlv import *
Tlv.parse(binascii.unhexlify("9F100D8A034142438A036465661001FF"), True)
>>> {40720:{138:[b'ABC',b'def'],16:b'\xff'}}
Build TLV:
from ber_tlv.tlv import *
Tlv.hexify_bytes(Tlv.build({0x9F10:{0x8A:[b"ABC",b"def"],0x10:b"\xff"}}))
>>> "9F100D8A034142438A036465661001FF"
Technical description
Below is a brief technical description of BER-TLV format.
Tag field
Tag has variable size of 1-4 bytes. If first tag byte, bits 1-5 are set to 1, there are more tag bytes follow. In subsequent bytes, bit 8 indicates if this is a last byte. Other bits identify unique tag number.
Length field
Length field has variable size of 1-4 bytes. When bit b8 of the most significant byte of the length field is set to 0, the length field consists of only one byte. Bits b7 to b1 code the number of bytes of the value field. The length field is within the range 1 to 127.When bit b8 of the most significant byte of the length field is set to 1, the subsequent bits b7 to b1 of the most significant byte code the number of subsequent bytes in the length field. The subsequent bytes code an integer representing the number of bytes in the value field.
Value field
Value is binary bytes array of specified length. Value may represent recursive sub-tree (branch).
Padding
Before, between, or after TLV-coded data objects, zero bytes without any meaning may occur (for example, due to erased or modified TLV-coded data objects).
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
Built Distribution
File details
Details for the file ber-tlv-0.0.3.tar.gz
.
File metadata
- Download URL: ber-tlv-0.0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e191c7ce427455a5523bfd18e2d6e33bdc7dda78eae45538c3be3385fb5f5ec |
|
MD5 | 01124ddb5f74198119818f6b3ba3facc |
|
BLAKE2b-256 | c0dcdfa6196694d6f4a89e623cabd61bf24dde5325272ce92822aaa8d77d9215 |
File details
Details for the file ber_tlv-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: ber_tlv-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 223def0fba22720a77a3696cdd97c818af64e2419d89809f1031d12375d156d4 |
|
MD5 | 3dd338494da27f27b94b5e11ed613eb4 |
|
BLAKE2b-256 | 363a83a18d1e8e001e6d40b67546842d4329235e5ff200cc142dc2840ca9b95e |