laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/34851?usp=email )
Change subject: utils: Fix bertlv_encode_tag() for multi-byte tags
......................................................................
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
---
M pySim/utils.py
1 file changed, 28 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/51/34851/1
diff --git a/pySim/utils.py b/pySim/utils.py
index 6cacdaa..666f728 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -262,15 +262,22 @@
remainder = inp & ~ (inp << (remain_bits - bitcnt))
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):
- # FIXME: multiple byte tags
- tag = t & 0x1f
- constructed = True if t & 0x20 else False
- cls = t >> 6
- else:
- tag = t['tag']
- constructed = t['constructed']
- cls = t['class']
+ # first convert to a dict representation
+ tag_size = count_int_bytes(t)
+ t, remainder = bertlv_parse_tag(t.to_bytes(tag_size))
+ tag = t['tag']
+ constructed = t['constructed']
+ cls = t['class']
if tag <= 30:
t = tag & 0x1f
if constructed:
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/34851?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: If0bd9137883c4c8b01c4dfcbb53cabeee5c1ce2b
Gerrit-Change-Number: 34851
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange