Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit a75124e

Browse files
author
Ron Frenkel
committed
1. Formatted the code with black.
2. Added tests for length parsing
1 parent fcbcee7 commit a75124e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

emv/protocol/structures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
from collections import OrderedDict
2-
from .data import ELEMENT_FORMAT, render_element, read_tag, read_length, is_constructed, Tag
2+
from .data import (
3+
ELEMENT_FORMAT,
4+
render_element,
5+
read_tag,
6+
read_length,
7+
is_constructed,
8+
Tag,
9+
)
310
from .data_elements import Parse, EPC_PRODUCT_ID
411
from ..util import decode_int, bit_set
512
import logging

emv/protocol/test/test_structures.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ def test_tlv(self):
3131
tlv = TLV.unmarshal(data)
3232
self.assertEqual(tlv[(0x9F, 0x17)][0], 3)
3333

34+
def test_length_parsing(self):
35+
data = unformat_bytes("42 01 03")
36+
tlv = TLV.unmarshal(data)
37+
self.assertEqual(tlv[0x42][0], 3)
38+
39+
data = unformat_bytes("42 81 01 07")
40+
tlv = TLV.unmarshal(data)
41+
self.assertEqual(tlv[0x42][0], 7)
42+
43+
data = unformat_bytes("42 82 00 01 07")
44+
tlv = TLV.unmarshal(data)
45+
self.assertEqual(tlv[0x42][0], 7)
46+
47+
data = unformat_bytes("42 83 00 00 01 07")
48+
tlv = TLV.unmarshal(data)
49+
self.assertEqual(tlv[0x42][0], 7)
50+
3451
def test_duplicate_tags(self):
3552
# An ADF entry with a number of records:
3653
data = unformat_bytes(

0 commit comments

Comments
 (0)