aboutsummaryrefslogtreecommitdiffstats
path: root/pySim/construct.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-05-27 20:08:09 +0200
committerlaforge <laforge@osmocom.org>2023-06-03 12:45:35 +0000
commit954ce95a1648c7d81eac5c693532ea3554e5f489 (patch)
tree0dcbbaf4b54a96163dd323abbb5f924204b61491 /pySim/construct.py
parentba6d6ab64f8f7322adc251ec9ed9814f62e6c18d (diff)
SJA2: Implement DF.SYSTEM/EF.0348_KEY using construct
This implicitly adds support for JSON->binary encoding, not just decoding (previous code predating construct support). Change-Id: I0994d9f66a504dd3c60b43ed5cf6645515dcbc6a
Diffstat (limited to 'pySim/construct.py')
-rw-r--r--pySim/construct.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/pySim/construct.py b/pySim/construct.py
index 97af235..20a6946 100644
--- a/pySim/construct.py
+++ b/pySim/construct.py
@@ -87,6 +87,26 @@ class Rpad(Adapter):
len(obj), self.sizeof()))
return obj + self.pattern * (self.sizeof() - len(obj))
+class MultiplyAdapter(Adapter):
+ """
+ Decoder multiplies by multiplicator
+ Encoder divides by multiplicator
+
+ Parameters:
+ subcon: Subconstruct as defined by construct library
+ multiplier: Multiplier to apply to raw encoded value
+ """
+
+ def __init__(self, subcon, multiplicator):
+ super().__init__(subcon)
+ self.multiplicator = multiplicator
+
+ def _decode(self, obj, context, path):
+ return obj * 8
+
+ def _encode(self, obj, context, path):
+ return obj // 8
+
class GsmStringAdapter(Adapter):
"""Convert GSM 03.38 encoded bytes to a string."""