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

Source Code for Module smartcard.sw.op21_ErrorChecker

  1  """Open Platform 2.1 error checker. 
  2   
  3  __author__ = "http://www.gemalto.com" 
  4   
  5  Copyright 2001-2011 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 smartcard.sw.ErrorChecker import ErrorChecker 
 26  import smartcard.sw.SWExceptions 
 27   
 28  op21_SW = { 
 29      0x62: (smartcard.sw.SWExceptions.WarningProcessingException, 
 30             {0x83: "Card life cycle is CARD_LOCKED"}), 
 31   
 32      0x63: (smartcard.sw.SWExceptions.WarningProcessingException, 
 33             {0x00: "Authentication failed"}), 
 34   
 35      0x64: (smartcard.sw.SWExceptions.ExecutionErrorException, 
 36             {0x00: "Execution error"}), 
 37   
 38      0x65: (smartcard.sw.SWExceptions.ExecutionErrorException, 
 39             {0x81: "Memory failure"}), 
 40   
 41      0x67: (smartcard.sw.SWExceptions.CheckingErrorException, 
 42             {0x00: "Wrong length in Lc"}), 
 43   
 44      0x69: (smartcard.sw.SWExceptions.CheckingErrorException, 
 45             {0x82: "Security status not satisfied", 
 46              0x85: "Conditions of use not satisfied"}), 
 47   
 48      0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, 
 49             {0x80: "Incorrect values in command data", 
 50              0x81: "Function not supported", 
 51              0x82: "Application not found", 
 52              0x84: "Not enough memory space", 
 53              0x86: "Incorrect parameters P1-P2", 
 54              0x88: "Referenced data not found"}), 
 55   
 56      0x6D: (smartcard.sw.SWExceptions.CheckingErrorException, 
 57             {0x00: "Instruction not supported"}), 
 58   
 59      0x6E: (smartcard.sw.SWExceptions.CheckingErrorException, 
 60             {0x00: "Class not supported"}), 
 61   
 62      0x94: (smartcard.sw.SWExceptions.CheckingErrorException, 
 63             {0x84: "Algorithm not supported", 
 64              0x85: "Invalid key check value"}), 
 65   
 66  } 
 67   
 68   
69 -class op21_ErrorChecker(ErrorChecker):
70 """Open platform 2.1 error checker. 71 72 This error checker raises the following exceptions: 73 - sw1 sw2 74 - 62 83 WarningProcessingException 75 - 63 00 WarningProcessingException 76 - 64 00 ExecutionErrorException 77 - 65 81 ExecutionErrorException 78 - 67 00 CheckingErrorException 79 - 69 82 85 CheckingErrorException 80 - 6A 80 81 82 84 86 88 CheckingErrorException 81 - 6D 00 CheckingErrorException 82 - 6E 00 CheckingErrorException 83 - 94 84 85 CheckingErrorException 84 85 This checker does not raise exceptions on undefined sw1 values, e.g.: 86 - sw1 sw2 87 - 63 any 88 - 6F any 89 90 and on undefined sw2 values, e.g.: 91 - sw1 sw2 92 - 62 81 83 93 - 64 any except 00 94 95 96 Use another checker in the error checking chain to raise exceptions 97 on these undefined values. 98 """ 99
100 - def __call__(self, data, sw1, sw2):
101 """Called to test data, sw1 and sw2 for error. 102 103 @param data: apdu response data 104 @param sw1, sw2: apdu data status words 105 106 Derived classes must raise a L{smartcard.sw.SWException} upon error.""" 107 if op21_SW.has_key(sw1): 108 exception, sw2dir = op21_SW[sw1] 109 if type(sw2dir) == type({}): 110 try: 111 message = sw2dir[sw2] 112 raise exception(data, sw1, sw2, message) 113 except KeyError: 114 pass
115 116 117 if __name__ == '__main__': 118 """Small sample illustrating the use of op21_ErrorChecker.""" 119 ecs = op21_ErrorChecker() 120 ecs([], 0x90, 0x00) 121 ecs([], 0x94, 0x81) 122 try: 123 ecs([], 0x94, 0x84) 124 except smartcard.sw.SWExceptions.CheckingErrorException, e: 125 print e, "%x %x" % (e.sw1, e.sw2) 126