add unit tests for BER-TLV encoder/decoder functions

... and while at it resolve a bug in bertlv_parse_len()
discovered by those new tests.

Change-Id: I9f14dafab4f712c29224c4eb25cacab7885e2b68
This commit is contained in:
Harald Welte
2021-05-04 20:06:45 +02:00
parent c781ab85bc
commit de02718631
2 changed files with 25 additions and 1 deletions

View File

@@ -132,7 +132,7 @@ def bertlv_parse_len(binary:bytes) -> Tuple[int, bytes]:
for i in range(1, 1+num_len_oct):
length <<= 8
length |= binary[i]
return (length, binary[num_len_oct:])
return (length, binary[1+num_len_oct:])
def bertlv_encode_len(length:int) -> bytes:
"""Encode a single Length value according to ITU-T X.690 8.1.3;