pySim/transport: Use newly-defined ResTuple type
Let's use the newly-added ResTuple type annotation rather than open-coding it everywhere. Change-Id: I122589e8aec4bf66dc2e86d7602ebecb771dcb93
This commit is contained in:
@@ -10,12 +10,12 @@ from construct import Construct
|
||||
|
||||
from pySim.exceptions import *
|
||||
from pySim.construct import filter_dict
|
||||
from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr, SwHexstr, SwMatchstr
|
||||
from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr, SwHexstr, SwMatchstr, ResTuple
|
||||
from pySim.cat import ProactiveCommand, CommandDetails, DeviceIdentities, Result
|
||||
|
||||
#
|
||||
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
|
||||
# Copyright (C) 2021-2022 Harald Welte <laforge@osmocom.org>
|
||||
# Copyright (C) 2021-2023 Harald Welte <laforge@osmocom.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -68,7 +68,7 @@ class LinkBase(abc.ABC):
|
||||
self.proactive_handler = proactive_handler
|
||||
|
||||
@abc.abstractmethod
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, Hexstr]:
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
"""Implementation specific method for sending the PDU."""
|
||||
|
||||
def set_sw_interpreter(self, interp):
|
||||
@@ -99,7 +99,7 @@ class LinkBase(abc.ABC):
|
||||
"""Resets the card (power down/up)
|
||||
"""
|
||||
|
||||
def send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
"""Sends an APDU with minimal processing
|
||||
|
||||
Args:
|
||||
@@ -116,7 +116,7 @@ class LinkBase(abc.ABC):
|
||||
self.apdu_tracer.trace_response(pdu, sw, data)
|
||||
return (data, sw)
|
||||
|
||||
def send_apdu(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def send_apdu(self, pdu: Hexstr) -> ResTuple:
|
||||
"""Sends an APDU and auto fetch response data
|
||||
|
||||
Args:
|
||||
@@ -145,7 +145,7 @@ class LinkBase(abc.ABC):
|
||||
|
||||
return data, sw
|
||||
|
||||
def send_apdu_checksw(self, pdu: Hexstr, sw: SwMatchstr = "9000") -> Tuple[Hexstr, SwHexstr]:
|
||||
def send_apdu_checksw(self, pdu: Hexstr, sw: SwMatchstr = "9000") -> ResTuple:
|
||||
"""Sends an APDU and check returned SW
|
||||
|
||||
Args:
|
||||
|
||||
@@ -21,11 +21,11 @@ import struct
|
||||
import socket
|
||||
import os
|
||||
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pySim.transport import LinkBase
|
||||
from pySim.exceptions import *
|
||||
from pySim.utils import h2b, b2h, Hexstr, SwHexstr
|
||||
from pySim.utils import h2b, b2h, Hexstr, ResTuple
|
||||
|
||||
|
||||
class L1CTLMessage:
|
||||
@@ -123,7 +123,7 @@ class CalypsoSimLink(LinkBase):
|
||||
def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False):
|
||||
pass # Nothing to do really ...
|
||||
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
|
||||
# Request FULL reset
|
||||
req_msg = L1CTLMessageSIM(h2b(pdu))
|
||||
|
||||
@@ -20,9 +20,9 @@ import logging as log
|
||||
import serial
|
||||
import time
|
||||
import re
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pySim.utils import Hexstr, SwHexstr
|
||||
from pySim.utils import Hexstr, ResTuple
|
||||
from pySim.transport import LinkBase
|
||||
from pySim.exceptions import *
|
||||
|
||||
@@ -141,7 +141,7 @@ class ModemATCommandLink(LinkBase):
|
||||
def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False):
|
||||
pass # Nothing to do really ...
|
||||
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
# Make sure pdu has upper case hex digits [A-F]
|
||||
pdu = pdu.upper()
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from smartcard.CardConnection import CardConnection
|
||||
from smartcard.CardRequest import CardRequest
|
||||
@@ -26,7 +26,7 @@ from smartcard.System import readers
|
||||
|
||||
from pySim.exceptions import NoCardError, ProtocolError, ReaderError
|
||||
from pySim.transport import LinkBase
|
||||
from pySim.utils import h2i, i2h, Hexstr, SwHexstr
|
||||
from pySim.utils import h2i, i2h, Hexstr, ResTuple
|
||||
|
||||
|
||||
class PcscSimLink(LinkBase):
|
||||
@@ -81,7 +81,7 @@ class PcscSimLink(LinkBase):
|
||||
self.connect()
|
||||
return 1
|
||||
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
|
||||
apdu = h2i(pdu)
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
import serial
|
||||
import time
|
||||
import os.path
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pySim.exceptions import NoCardError, ProtocolError
|
||||
from pySim.transport import LinkBase
|
||||
from pySim.utils import h2b, b2h, Hexstr, SwHexstr
|
||||
from pySim.utils import h2b, b2h, Hexstr, ResTuple
|
||||
|
||||
|
||||
class SerialSimLink(LinkBase):
|
||||
@@ -185,7 +185,7 @@ class SerialSimLink(LinkBase):
|
||||
def _rx_byte(self):
|
||||
return self._sl.read()
|
||||
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]:
|
||||
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||
|
||||
pdu = h2b(pdu)
|
||||
data_len = pdu[4] # P3
|
||||
|
||||
Reference in New Issue
Block a user