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


Change subject: pySim.apdu: Get rid of HexAdapter
......................................................................

pySim.apdu: Get rid of HexAdapter

In the past, we always wrapped a HexAdapter around bytes-like data in
order to make sure it's printed as hex-digits.  However, now that we are
doing JSON output it's much easier to let the pySim.utils.JsonEncoder
take care of this in a generic way.

We should do a similar migrtaion all over pySim (pySim-shell,
filesystem, etc.) - but for now only do it in the low-hanging fruit of
pySim-trace aka pySim.apdu

Change-Id: I0cde40b2db08b4db9c10c1ece9ca6fdd42aa9154
---
M pySim/apdu/__init__.py
M pySim/apdu/ts_102_221.py
M pySim/apdu/ts_31_102.py
3 files changed, 41 insertions(+), 23 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/35/37535/1

diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py
index fbe7e6b..469b2fa 100644
--- a/pySim/apdu/__init__.py
+++ b/pySim/apdu/__init__.py
@@ -150,8 +150,8 @@
     # fall-back constructs if the derived class provides no override
     _construct_p1 = Byte
     _construct_p2 = Byte
-    _construct = HexAdapter(GreedyBytes)
-    _construct_rsp = HexAdapter(GreedyBytes)
+    _construct = GreedyBytes
+    _construct_rsp = GreedyBytes
     _tlv = None
     _tlv_rsp = None

diff --git a/pySim/apdu/ts_102_221.py b/pySim/apdu/ts_102_221.py
index eaac868..491c0d3 100644
--- a/pySim/apdu/ts_102_221.py
+++ b/pySim/apdu/ts_102_221.py
@@ -99,7 +99,7 @@
                 logger.warning('SELECT UNKNOWN FID %s', file_hex)
         elif mode == 'df_name':
             # Select by AID (can be sub-string!)
-            aid = self.cmd_dict['body']
+            aid = b2h(self.cmd_dict['body'])
             sels = lchan.rs.mf.get_app_selectables(['AIDS'])
             adf = self._find_aid_substr(sels, aid)
             if adf:
@@ -115,7 +115,7 @@
             self.file = lchan.selected_file
             if 'body' in self.rsp_dict:
                 # not every SELECT is asking for the FCP in response...
-                return 
lchan.selected_file.decode_select_response(self.rsp_dict['body'])
+                return 
lchan.selected_file.decode_select_response(b2h(self.rsp_dict['body']))
         return None

 
@@ -128,7 +128,7 @@

     def process_on_lchan(self, lchan):
         if self.cmd_dict['p2'] == 'response_like_select':
-            return 
lchan.selected_file.decode_select_response(self.rsp_dict['body'])
+            return 
lchan.selected_file.decode_select_response(b2h(self.rsp_dict['body']))

 def _decode_binary_p1p2(p1, p2) -> Dict:
     ret = {}
diff --git a/pySim/apdu/ts_31_102.py b/pySim/apdu/ts_31_102.py
index c335773..58f91a2 100644
--- a/pySim/apdu/ts_31_102.py
+++ b/pySim/apdu/ts_31_102.py
@@ -42,28 +42,28 @@
                               BitsInteger(4),
                               'authentication_context'/Enum(BitsInteger(3), 
gsm=0, umts=1,
                                                             vgcs_vbs=2, gba=4))
-    _cs_cmd_gsm_3g =  Struct('_rand_len'/Int8ub, 
'rand'/HexAdapter(Bytes(this._rand_len)),
-                         '_autn_len'/COptional(Int8ub), 
'autn'/If(this._autn_len, HexAdapter(Bytes(this._autn_len))))
-    _cs_cmd_vgcs = Struct('_vsid_len'/Int8ub, 
'vservice_id'/HexAdapter(Bytes(this._vsid_len)),
-                          '_vkid_len'/Int8ub, 
'vk_id'/HexAdapter(Bytes(this._vkid_len)),
-                          '_vstk_rand_len'/Int8ub, 
'vstk_rand'/HexAdapter(Bytes(this._vstk_rand_len)))
-    _cmd_gba_bs = Struct('_rand_len'/Int8ub, 
'rand'/HexAdapter(Bytes(this._rand_len)),
-                         '_autn_len'/Int8ub, 
'autn'/HexAdapter(Bytes(this._autn_len)))
-    _cmd_gba_naf = Struct('_naf_id_len'/Int8ub, 
'naf_id'/HexAdapter(Bytes(this._naf_id_len)),
-                          '_impi_len'/Int8ub, 
'impi'/HexAdapter(Bytes(this._impi_len)))
+    _cs_cmd_gsm_3g =  Struct('_rand_len'/Int8ub, 'rand'/Bytes(this._rand_len),
+                         '_autn_len'/COptional(Int8ub), 
'autn'/If(this._autn_len, Bytes(this._autn_len)))
+    _cs_cmd_vgcs = Struct('_vsid_len'/Int8ub, 
'vservice_id'/Bytes(this._vsid_len),
+                          '_vkid_len'/Int8ub, 'vk_id'/Bytes(this._vkid_len),
+                          '_vstk_rand_len'/Int8ub, 
'vstk_rand'/Bytes(this._vstk_rand_len))
+    _cmd_gba_bs = Struct('_rand_len'/Int8ub, 'rand'/Bytes(this._rand_len),
+                         '_autn_len'/Int8ub, 'autn'/Bytes(this._autn_len))
+    _cmd_gba_naf = Struct('_naf_id_len'/Int8ub, 
'naf_id'/Bytes(this._naf_id_len),
+                          '_impi_len'/Int8ub, 'impi'/Bytes(this._impi_len))
     _cs_cmd_gba = Struct('tag'/Int8ub, 'body'/Switch(this.tag, { 0xDD: 
'bootstrap'/_cmd_gba_bs,
                                                                  0xDE: 
'naf_derivation'/_cmd_gba_naf }))
-    _cs_rsp_gsm = Struct('_len_sres'/Int8ub, 
'sres'/HexAdapter(Bytes(this._len_sres)),
-                         '_len_kc'/Int8ub, 
'kc'/HexAdapter(Bytes(this._len_kc)))
-    _rsp_3g_ok = Struct('_len_res'/Int8ub, 
'res'/HexAdapter(Bytes(this._len_res)),
-                        '_len_ck'/Int8ub, 'ck'/HexAdapter(Bytes(this._len_ck)),
-                        '_len_ik'/Int8ub, 'ik'/HexAdapter(Bytes(this._len_ik)),
-                        '_len_kc'/COptional(Int8ub), 'kc'/If(this._len_kc, 
HexAdapter(Bytes(this._len_kc))))
-    _rsp_3g_sync = Struct('_len_auts'/Int8ub, 
'auts'/HexAdapter(Bytes(this._len_auts)))
+    _cs_rsp_gsm = Struct('_len_sres'/Int8ub, 'sres'/Bytes(this._len_sres),
+                         '_len_kc'/Int8ub, 'kc'/Bytes(this._len_kc))
+    _rsp_3g_ok = Struct('_len_res'/Int8ub, 'res'/Bytes(this._len_res),
+                        '_len_ck'/Int8ub, 'ck'/Bytes(this._len_ck),
+                        '_len_ik'/Int8ub, 'ik'/Bytes(this._len_ik),
+                        '_len_kc'/COptional(Int8ub), 'kc'/If(this._len_kc, 
Bytes(this._len_kc)))
+    _rsp_3g_sync = Struct('_len_auts'/Int8ub, 'auts'/Bytes(this._len_auts))
     _cs_rsp_3g = Struct('tag'/Int8ub, 'body'/Switch(this.tag, { 0xDB: 
'success'/_rsp_3g_ok,
                                                                 0xDC: 
'sync_fail'/_rsp_3g_sync}))
-    _cs_rsp_vgcs = Struct(Const(b'\xDB'), '_vstk_len'/Int8ub, 
'vstk'/HexAdapter(Bytes(this._vstk_len)))
-    _cs_rsp_gba_naf = Struct(Const(b'\xDB'), '_ks_ext_naf_len'/Int8ub, 
'ks_ext_naf'/HexAdapter(Bytes(this._ks_ext_naf_len)))
+    _cs_rsp_vgcs = Struct(Const(b'\xDB'), '_vstk_len'/Int8ub, 
'vstk'/Bytes(this._vstk_len))
+    _cs_rsp_gba_naf = Struct(Const(b'\xDB'), '_ks_ext_naf_len'/Int8ub, 
'ks_ext_naf'/Bytes(this._ks_ext_naf_len))
     def _decode_cmd(self) -> Dict:
         r = {}
         r['p1'] = parse_construct(self._construct_p1, self.p1.to_bytes(1, 
'big'))

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37535?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: I0cde40b2db08b4db9c10c1ece9ca6fdd42aa9154
Gerrit-Change-Number: 37535
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to