mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-17 02:48:34 +03:00
commands: avoid double lchan patching, get rid of cla_byte getter+setter methods
The SimCardCommands has a cla_byte @property method, which automatically returns the lchan patched CLA byte. We use cla_byte property to build the UICC command APDUs inside SimCardCommands and then we hand the APDU over to the send_apdu* methods. The cla_byte @property method as well as the send_apdu* methods perform the lchan patching. This means the CLA byte gets patched twice, which is technically not an issue, but can be confusing when trying to understand the code. To fix this, let's remove the @property methods and turn cla_byte into a normal property again. This is also more accurate since the cla_byte property originally was introduced to switch between UICC and classic SIM APDU commands, which have almost identcal APDUs. Related: OS#6531 Change-Id: I420f8a5f7ff8d9e5ef94d6519fb3716d6c7caf64
This commit is contained in:
@@ -66,7 +66,6 @@ class SimCardCommands:
|
||||
byte by the respective instance. """
|
||||
def __init__(self, transport: LinkBase, lchan_nr: int = 0):
|
||||
self._tp = transport
|
||||
self._cla_byte = None
|
||||
self.sel_ctrl = "0000"
|
||||
self.lchan_nr = lchan_nr
|
||||
# invokes the setter below
|
||||
@@ -76,15 +75,10 @@ class SimCardCommands:
|
||||
def fork_lchan(self, lchan_nr: int) -> 'SimCardCommands':
|
||||
"""Fork a per-lchan specific SimCardCommands instance off the current instance."""
|
||||
ret = SimCardCommands(transport = self._tp, lchan_nr = lchan_nr)
|
||||
ret.cla_byte = self._cla_byte
|
||||
ret.cla_byte = self.cla_byte
|
||||
ret.sel_ctrl = self.sel_ctrl
|
||||
return ret
|
||||
|
||||
@property
|
||||
def cla_byte(self) -> Hexstr:
|
||||
"""Return the lchan patched default CLA value for this card."""
|
||||
return cla_with_lchan(self._cla_byte, self.lchan_nr)
|
||||
|
||||
@property
|
||||
def max_cmd_len(self) -> int:
|
||||
"""Maximum length of the command apdu data section. Depends on secure channel protocol used."""
|
||||
@@ -93,11 +87,6 @@ class SimCardCommands:
|
||||
else:
|
||||
return 255
|
||||
|
||||
@cla_byte.setter
|
||||
def cla_byte(self, new_val: Hexstr):
|
||||
"""Set the (raw, without lchan) default CLA value for this card."""
|
||||
self._cla_byte = new_val
|
||||
|
||||
def send_apdu(self, pdu: Hexstr, apply_lchan:bool = True) -> ResTuple:
|
||||
"""Sends an APDU and auto fetch response data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user