[Pcsclite-git-commit] [PCSC] 01/01: SCardGetAttrib.py: also use SCARD_ATTR_ATR_STRING
Ludovic Rousseau
rousseau at moszumanska.debian.org
Mon Apr 25 15:10:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository PCSC.
commit 77740786d5450273fad1400322918f5a276b3131
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date: Mon Apr 25 11:31:44 2016 +0200
SCardGetAttrib.py: also use SCARD_ATTR_ATR_STRING
Try to use both attributes SCARD_ATTR_VENDOR_IFD_SERIAL_NO and
SCARD_ATTR_ATR_STRING
Not all devices have a serial number so SCARD_ATTR_VENDOR_IFD_SERIAL_NO
may just return an empty buffer.
SCARD_ATTR_ATR_STRING should always work when a card is inserted (and
the CCID driver is used).
---
UnitaryTests/SCardGetAttrib.py | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/UnitaryTests/SCardGetAttrib.py b/UnitaryTests/SCardGetAttrib.py
index 7f4bd1d..738bfa9 100755
--- a/UnitaryTests/SCardGetAttrib.py
+++ b/UnitaryTests/SCardGetAttrib.py
@@ -2,7 +2,7 @@
"""
# SCardGetAttrib.py: get SCARD_ATTR_VENDOR_IFD_SERIAL_NO PC/SC attribute
-# Copyright (C) 2010 Ludovic Rousseau
+# Copyright (C) 2010,2016 Ludovic Rousseau
"""
# This program is free software; you can redistribute it and/or modify
@@ -18,10 +18,12 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
-# SCARD_ATTR_VENDOR_IFD_SERIAL_NO support has been added in revision 4956
+# SCARD_ATTR_VENDOR_IFD_SERIAL_NO support has been added in ccid 1.3.13
+# SCARD_ATTR_ATR_STRING support has been added in ccid 0.9.0
from smartcard.scard import *
from smartcard.pcsc.PCSCExceptions import *
+from smartcard.util import toHexString
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
if hresult != SCARD_S_SUCCESS:
@@ -38,10 +40,14 @@ for reader in readers:
if hresult != SCARD_S_SUCCESS:
raise BaseSCardException(hresult)
- hresult, attrib = SCardGetAttrib(hcard, SCARD_ATTR_VENDOR_IFD_SERIAL_NO)
- print reader, ":",
- print "".join([chr(x) for x in attrib])
- print SCardGetErrorMessage(hresult)
+ print "reader:", reader
+ for attribute in (SCARD_ATTR_VENDOR_IFD_SERIAL_NO, SCARD_ATTR_ATR_STRING):
+ hresult, attrib = SCardGetAttrib(hcard, attribute)
+ print hex(attribute),
+ if hresult != SCARD_S_SUCCESS:
+ print SCardGetErrorMessage(hresult)
+ else:
+ print attrib, toHexString(attrib)
hresult = SCardDisconnect(hcard, SCARD_LEAVE_CARD)
if hresult != SCARD_S_SUCCESS:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git
More information about the Pcsclite-cvs-commit
mailing list