diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index a16fdb3e..c8079f66 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -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 -# Copyright (C) 2021-2022 Harald Welte +# Copyright (C) 2021-2023 Harald Welte # # 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: diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index 4244b230..34fc6465 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -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)) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index c6f6c57e..e99762dd 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -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() diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index f0b3e67a..a01917f4 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -17,7 +17,7 @@ # along with this program. If not, see . # -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) diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index daf2eb82..998d1d89 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -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