Package smartcard :: Package sw :: Module ISO7816_4_SW1ErrorChecker
[hide private]
[frames] | no frames]

Source Code for Module smartcard.sw.ISO7816_4_SW1ErrorChecker

 1  """ISO7816-4 sw1 only error checker. 
 2   
 3  __author__ = "http://www.gemalto.com" 
 4   
 5  Copyright 2001-2012 gemalto 
 6  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
 7   
 8  This file is part of pyscard. 
 9   
10  pyscard is free software; you can redistribute it and/or modify 
11  it under the terms of the GNU Lesser General Public License as published by 
12  the Free Software Foundation; either version 2.1 of the License, or 
13  (at your option) any later version. 
14   
15  pyscard is distributed in the hope that it will be useful, 
16  but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18  GNU Lesser General Public License for more details. 
19   
20  You should have received a copy of the GNU Lesser General Public License 
21  along with pyscard; if not, write to the Free Software 
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
23  """ 
24   
25  from __future__ import print_function 
26  from smartcard.sw.ErrorChecker import ErrorChecker 
27  import smartcard.sw.SWExceptions 
28   
29  iso7816_4SW1 = { 
30      0x62: smartcard.sw.SWExceptions.WarningProcessingException, 
31      0x63: smartcard.sw.SWExceptions.WarningProcessingException, 
32      0x64: smartcard.sw.SWExceptions.ExecutionErrorException, 
33      0x65: smartcard.sw.SWExceptions.ExecutionErrorException, 
34      0x66: smartcard.sw.SWExceptions.SecurityRelatedException, 
35      0x67: smartcard.sw.SWExceptions.CheckingErrorException, 
36      0x68: smartcard.sw.SWExceptions.CheckingErrorException, 
37      0x69: smartcard.sw.SWExceptions.CheckingErrorException, 
38      0x6A: smartcard.sw.SWExceptions.CheckingErrorException, 
39      0x6B: smartcard.sw.SWExceptions.CheckingErrorException, 
40      0x6C: smartcard.sw.SWExceptions.CheckingErrorException, 
41      0x6D: smartcard.sw.SWExceptions.CheckingErrorException, 
42      0x6E: smartcard.sw.SWExceptions.CheckingErrorException, 
43      0x6F: smartcard.sw.SWExceptions.CheckingErrorException, 
44  } 
45   
46   
47 -class ISO7816_4_SW1ErrorChecker(ErrorChecker):
48 """ISO7816-4 error checker based on status word sw1 only. 49 50 This error checker raises the following exceptions: 51 - sw1 sw2 52 - 62 any WarningProcessingException 53 - 63 any WarningProcessingException 54 - 64 any ExecutionErrorException 55 - 65 any ExecutionErrorException 56 - 66 any SecurityRelatedException 57 - 67 any CheckingErrorException 58 - 68 any CheckingErrorException 59 - 69 any CheckingErrorException 60 - 6a any CheckingErrorException 61 - 6b any CheckingErrorException 62 - 6c any CheckingErrorException 63 - 6d any CheckingErrorException 64 - 6e any CheckingErrorException 65 - 6f any CheckingErrorException 66 """ 67
68 - def __call__(self, data, sw1, sw2):
69 """Called to test data, sw1 and sw2 for error. 70 71 @param data: apdu response data 72 @param sw1, sw2: apdu data status words 73 """ 74 if sw1 in iso7816_4SW1: 75 exception = iso7816_4SW1[sw1] 76 raise exception(data, sw1, sw2)
77 78 79 if __name__ == '__main__': 80 """Small sample illustrating the use of ISO7816_4_SW1ErrorChecker.""" 81 ecs = ISO7816_4_SW1ErrorChecker() 82 ecs([], 0x90, 0x00) 83 try: 84 ecs([], 0x66, 0x80) 85 except smartcard.sw.SWExceptions.SecurityRelatedException as e: 86 print(str(e) + " %x %x" % (e.sw1, e.sw2)) 87