mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-31 08:23:22 +03:00
utils: Fix bertlv_encode_tag() for multi-byte tags
We used to support only single-byte tags in bertlv_encode_tag, let's fix that. The easy option is to simply call bertlv_parse_tag, as that already supported multi-byte tags. Change-Id: If0bd9137883c4c8b01c4dfcbb53cabeee5c1ce2b
This commit is contained in:
@@ -262,15 +262,22 @@ def bertlv_encode_tag(t) -> bytes:
|
|||||||
remainder = inp & ~ (inp << (remain_bits - bitcnt))
|
remainder = inp & ~ (inp << (remain_bits - bitcnt))
|
||||||
return outp, remainder
|
return outp, remainder
|
||||||
|
|
||||||
|
def count_int_bytes(inp: int) -> int:
|
||||||
|
"""count the number of bytes require to represent the given integer."""
|
||||||
|
i = 1
|
||||||
|
inp = inp >> 8
|
||||||
|
while inp:
|
||||||
|
i += 1
|
||||||
|
inp = inp >> 8
|
||||||
|
return i
|
||||||
|
|
||||||
if isinstance(t, int):
|
if isinstance(t, int):
|
||||||
# FIXME: multiple byte tags
|
# first convert to a dict representation
|
||||||
tag = t & 0x1f
|
tag_size = count_int_bytes(t)
|
||||||
constructed = True if t & 0x20 else False
|
t, remainder = bertlv_parse_tag(t.to_bytes(tag_size, 'big'))
|
||||||
cls = t >> 6
|
tag = t['tag']
|
||||||
else:
|
constructed = t['constructed']
|
||||||
tag = t['tag']
|
cls = t['class']
|
||||||
constructed = t['constructed']
|
|
||||||
cls = t['class']
|
|
||||||
if tag <= 30:
|
if tag <= 30:
|
||||||
t = tag & 0x1f
|
t = tag & 0x1f
|
||||||
if constructed:
|
if constructed:
|
||||||
|
|||||||
Reference in New Issue
Block a user