diff options
| author | J08nY | 2023-02-17 13:40:33 +0100 |
|---|---|---|
| committer | J08nY | 2023-02-17 13:40:33 +0100 |
| commit | 9efa088d462899c94afd06fbad25003c403a6cee (patch) | |
| tree | bd279114ad01e4549fc9841f190090b63e03c3ce /pyecsca/sca/target/PCSC.py | |
| parent | fb6f0a428dbbd1e53fce582b5e6c7af3b7316485 (diff) | |
| download | pyecsca-9efa088d462899c94afd06fbad25003c403a6cee.tar.gz pyecsca-9efa088d462899c94afd06fbad25003c403a6cee.tar.zst pyecsca-9efa088d462899c94afd06fbad25003c403a6cee.zip | |
Add support for smartleia targets.
Diffstat (limited to 'pyecsca/sca/target/PCSC.py')
| -rw-r--r-- | pyecsca/sca/target/PCSC.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/pyecsca/sca/target/PCSC.py b/pyecsca/sca/target/PCSC.py index f36843f..ace59cc 100644 --- a/pyecsca/sca/target/PCSC.py +++ b/pyecsca/sca/target/PCSC.py @@ -1,5 +1,5 @@ """Provides a smartcard target communicating via PC/SC (Personal Computer/Smart Card).""" -from typing import Union +from typing import Union, Optional from public import public from smartcard.CardConnection import CardConnection @@ -7,7 +7,7 @@ from smartcard.System import readers from smartcard.pcsc.PCSCCardConnection import PCSCCardConnection from smartcard.pcsc.PCSCReader import PCSCReader -from .ISO7816 import ISO7816Target, CommandAPDU, ResponseAPDU, ISO7816 +from .ISO7816 import ISO7816Target, CommandAPDU, ResponseAPDU, ISO7816, CardProtocol, CardConnectionException @public @@ -27,8 +27,16 @@ class PCSCTarget(ISO7816Target): # pragma: no cover self.reader = reader self.connection: PCSCCardConnection = self.reader.createConnection() - def connect(self): - self.connection.connect(CardConnection.T0_protocol | CardConnection.T1_protocol) + def connect(self, protocol: Optional[CardProtocol] = None): + proto = CardConnection.T0_protocol | CardConnection.T1_protocol + if protocol == CardProtocol.T0: + proto = CardConnection.T0_protocol + elif protocol == CardProtocol.T1: + proto = CardConnection.T1_protocol + try: + self.connection.connect(proto) + except: # noqa + raise CardConnectionException() @property def atr(self) -> bytes: |
