|
21 | 21 | # SCARD_ATTR_VENDOR_IFD_SERIAL_NO support has been added in ccid 1.3.13 |
22 | 22 | # SCARD_ATTR_ATR_STRING support has been added in ccid 0.9.0 |
23 | 23 |
|
| 24 | +from struct import unpack |
24 | 25 | from smartcard.scard import * |
25 | 26 | from smartcard.pcsc.PCSCExceptions import * |
26 | 27 | from smartcard.util import toHexString, toASCIIString |
27 | | -from struct import unpack |
28 | 28 |
|
29 | 29 | hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER) |
30 | 30 | if hresult != SCARD_S_SUCCESS: |
|
33 | 33 | hresult, readers = SCardListReaders(hcontext, []) |
34 | 34 | if hresult != SCARD_S_SUCCESS: |
35 | 35 | raise ListReadersException(hresult) |
36 | | -print('PC/SC Readers:', readers) |
| 36 | +print("PC/SC Readers:", readers) |
37 | 37 |
|
38 | 38 | for reader in readers: |
39 | | - hresult, hcard, dwActiveProtocol = SCardConnect(hcontext, reader, |
40 | | - SCARD_SHARE_DIRECT, SCARD_PROTOCOL_ANY) |
| 39 | + hresult, hcard, dwActiveProtocol = SCardConnect( |
| 40 | + hcontext, reader, SCARD_SHARE_DIRECT, SCARD_PROTOCOL_ANY |
| 41 | + ) |
41 | 42 | if hresult != SCARD_S_SUCCESS: |
42 | 43 | raise BaseSCardException(hresult) |
43 | 44 |
|
44 | 45 | print("reader:", reader) |
45 | | - for attribute in (SCARD_ATTR_VENDOR_IFD_SERIAL_NO, |
46 | | - SCARD_ATTR_ATR_STRING, SCARD_ATTR_CHANNEL_ID): |
| 46 | + for attribute in ( |
| 47 | + SCARD_ATTR_VENDOR_IFD_SERIAL_NO, |
| 48 | + SCARD_ATTR_ATR_STRING, |
| 49 | + SCARD_ATTR_CHANNEL_ID, |
| 50 | + ): |
47 | 51 | hresult, attrib = SCardGetAttrib(hcard, attribute) |
48 | | - print(hex(attribute), end=' ') |
| 52 | + print(hex(attribute), end=" ") |
49 | 53 | if hresult != SCARD_S_SUCCESS: |
50 | 54 | print(SCardGetErrorMessage(hresult)) |
51 | 55 | else: |
|
57 | 61 | if DDDD == 0x0020: |
58 | 62 | bus = (DDDDCCCC & 0xFF00) >> 8 |
59 | 63 | addr = DDDDCCCC & 0xFF |
60 | | - print(" USB: bus: {}, addr: {}".format(bus, addr)) |
61 | | - |
| 64 | + print(f" USB: bus: {bus}, addr: {addr}") |
62 | 65 |
|
63 | 66 | hresult = SCardDisconnect(hcard, SCARD_LEAVE_CARD) |
64 | 67 | if hresult != SCARD_S_SUCCESS: |
|
0 commit comments