mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
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
This commit is contained in:
16
pySim/tlv.py
16
pySim/tlv.py
@@ -268,7 +268,21 @@ class BER_TLV_IE(TLV_IE):
|
||||
return bertlv_encode_len(len(val))
|
||||
|
||||
|
||||
class COMPR_TLV_IE(TLV_IE):
|
||||
class ComprTlvMeta(TlvMeta):
|
||||
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
|
||||
return x
|
||||
|
||||
class COMPR_TLV_IE(TLV_IE, metaclass=ComprTlvMeta):
|
||||
"""TLV_IE formated as COMPREHENSION-TLV as described in ETSI TS 101 220."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user