1 """ISO7816-4 sw1 only 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 iso7816_4SW1 = {
29 0x62: smartcard.sw.SWExceptions.WarningProcessingException,
30 0x63: smartcard.sw.SWExceptions.WarningProcessingException,
31 0x64: smartcard.sw.SWExceptions.ExecutionErrorException,
32 0x65: smartcard.sw.SWExceptions.ExecutionErrorException,
33 0x66: smartcard.sw.SWExceptions.SecurityRelatedException,
34 0x67: smartcard.sw.SWExceptions.CheckingErrorException,
35 0x68: smartcard.sw.SWExceptions.CheckingErrorException,
36 0x69: smartcard.sw.SWExceptions.CheckingErrorException,
37 0x6A: smartcard.sw.SWExceptions.CheckingErrorException,
38 0x6B: smartcard.sw.SWExceptions.CheckingErrorException,
39 0x6C: smartcard.sw.SWExceptions.CheckingErrorException,
40 0x6D: smartcard.sw.SWExceptions.CheckingErrorException,
41 0x6E: smartcard.sw.SWExceptions.CheckingErrorException,
42 0x6F: smartcard.sw.SWExceptions.CheckingErrorException,
43 }
44
45
47 """ISO7816-4 error checker based on status word sw1 only.
48
49 This error checker raises the following exceptions:
50 - sw1 sw2
51 - 62 any WarningProcessingException
52 - 63 any WarningProcessingException
53 - 64 any ExecutionErrorException
54 - 65 any ExecutionErrorException
55 - 66 any SecurityRelatedException
56 - 67 any CheckingErrorException
57 - 68 any CheckingErrorException
58 - 69 any CheckingErrorException
59 - 6a any CheckingErrorException
60 - 6b any CheckingErrorException
61 - 6c any CheckingErrorException
62 - 6d any CheckingErrorException
63 - 6e any CheckingErrorException
64 - 6f any CheckingErrorException
65 """
66
68 """Called to test data, sw1 and sw2 for error.
69
70 @param data: apdu response data
71 @param sw1, sw2: apdu data status words
72 """
73 if iso7816_4SW1.has_key(sw1):
74 exception = iso7816_4SW1[sw1]
75 raise exception(data, sw1, sw2)
76
77
78 if __name__ == '__main__':
79 """Small sample illustrating the use of ISO7816_4_SW1ErrorChecker."""
80 ecs = ISO7816_4_SW1ErrorChecker()
81 ecs([], 0x90, 0x00)
82 try:
83 ecs([], 0x66, 0x80)
84 except smartcard.sw.SWExceptions.SecurityRelatedException, e:
85 print e, "%x %x" % (e.sw1, e.sw2)
86