laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37145?usp=email )


Change subject: pySim.tlv.COMPR_TLV_IE: Patch comprehension bit if derived 
class misses it
......................................................................

pySim.tlv.COMPR_TLV_IE: Patch comprehension bit if derived class misses it

Our current implementation assumes that all COMPR_TLV_IE are created
with a raw tag value that has the comprehension bit set.  Check for this
during the class __new__ method and print a warning if we have to fix it up

Change-Id: I299cd65f32dffda9040d18c17a374e8dc9ebe7da
---
M pySim/tlv.py
1 file changed, 25 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/37145/1

diff --git a/pySim/tlv.py b/pySim/tlv.py
index 5835d33..c6662ea 100644
--- a/pySim/tlv.py
+++ b/pySim/tlv.py
@@ -271,6 +271,18 @@
 class COMPR_TLV_IE(TLV_IE):
     """TLV_IE formated as COMPREHENSION-TLV as described in ETSI TS 101 220."""

+    def __new__(mcs, name, bases, namespace, **kwargs):
+        x = super().__new__(mcs, name, bases, namespace)
+        if x.tag:
+            # we currently assume that the tag values always have the 
comprehension bit set;
+            # let's fix it up if a derived class has forgotten about that
+            if x.tag > 0xff and x.tag & 0x8000 == 0:
+                print("Fixing up COMPR_TLV_IE class %s: tag=0x%x has no 
comprehension bit" % (name, x.tag))
+                x.tag = x.tag | 0x8000
+            elif x.tag & 0x80 == 0:
+                print("Fixing up COMPR_TLV_IE class %s: tag=0x%x has no 
comprehension bit" % (name, x.tag))
+                x.tag = x.tag | 0x80
+
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
         self.comprehension = False

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37145?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: I299cd65f32dffda9040d18c17a374e8dc9ebe7da
Gerrit-Change-Number: 37145
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <lafo...@osmocom.org>
Gerrit-MessageType: newchange

Reply via email to