Package smartcard :: Module CardService
[hide private]
[frames] | no frames]

Source Code for Module smartcard.CardService

 1  """Card service abstract class. 
 2   
 3  A card service is a class providings specific smart card functionality, 
 4  e.g.  a GSM file system or an Open Platform loader.  CardService is an 
 5  abstract class from which concrete card services are derived.  A concrete 
 6  card service is almost always smart card operating system specific. 
 7   
 8  The card service performs its specific smart card functionnality by accessing 
 9  the smartcard with a CardConnection. 
10   
11  __author__ = "http://www.gemalto.com" 
12   
13  Copyright 2001-2012 gemalto 
14  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
15   
16  This file is part of pyscard. 
17   
18  pyscard is free software; you can redistribute it and/or modify 
19  it under the terms of the GNU Lesser General Public License as published by 
20  the Free Software Foundation; either version 2.1 of the License, or 
21  (at your option) any later version. 
22   
23  pyscard is distributed in the hope that it will be useful, 
24  but WITHOUT ANY WARRANTY; without even the implied warranty of 
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
26  GNU Lesser General Public License for more details. 
27   
28  You should have received a copy of the GNU Lesser General Public License 
29  along with pyscard; if not, write to the Free Software 
30  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
31  """ 
32   
33  from __future__ import print_function 
34  from smartcard.scard import * 
35   
36   
37 -class CardService(object):
38 """Card service abstract class. 39 Known subclasses: smartcard.PassThruCardService 40 """ 41
42 - def __init__(self, connection, cardname=None):
43 """Construct a new card service and bind to a smart card in a reader. 44 45 connection: the CardConnection used to access the smart card 46 """ 47 self.connection = connection 48 self.cardname = cardname
49
50 - def __del__(self):
51 """Destructor. Disconnect card and destroy card service resources.""" 52 self.connection.disconnect()
53
54 - def supports(cardname):
55 pass
56 supports = staticmethod(supports)
57 58 59 if __name__ == '__main__': 60 """Small sample illustrating the use of CardService.""" 61 SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] 62 DF_TELECOM = [0x7F, 0x10] 63 from smartcard.System import readers 64 cc = readers()[0].createConnection() 65 cs = CardService(cc) 66 cs.connection.connect() 67 data, sw1, sw2 = cs.connection.transmit(SELECT + DF_TELECOM) 68 print("%X %X" % (sw1, sw2)) 69 cs.connection.disconnect() 70