root/trunk/src/libopensc/errors.c

Revision 3084, 4.3 KB (checked in by aj, 2 years ago)

convert to utf-8.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * errors.c: The textual representation of errors
3 *
4 * Copyright (C) 2001, 2002  Juha YrjölÀ <juha.yrjola@iki.fi>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#include <stdio.h>
22#include "errors.h"
23
24#define DIM(v)          (sizeof(v)/(sizeof((v)[0])))
25
26const char *sc_strerror(int error)
27{
28        const char *rdr_errors[] = {
29                "Generic reader error",
30                "No readers found",
31                "Slot not found",
32                "Slot already connected",
33                "Card not present",
34                "Card removed",
35                "Card reset",
36                "Transmit failed",
37                "Timed out while waiting for user input",
38                "Input operation cancelled by user",
39                "The two PINs did not match",
40                "Message too long (keypad)",
41                "Timeout while waiting for event from card reader",
42                "Unresponsive card (correctly inserted?)",
43                "Reader detached (hotplug device?)",
44                "Reader reattached (hotplug device?)",
45        };
46        const int rdr_base = -SC_ERROR_READER;
47        const char *card_errors[] = {
48                "Card command failed",
49                "File not found",
50                "Record not found",
51                "Unsupported CLA byte in APDU",
52                "Unsupported INS byte in APDU",
53                "Incorrect parameters in APDU",
54                "Wrong length",
55                "Card memory failure",
56                "Card does not support the requested operation",
57                "Not allowed",
58                "Card is invalid or cannot be handled",
59                "Security status not satisfied",
60                "Authentication method blocked",
61                "Unknown data received from card",
62                "PIN code or key incorrect",
63                "File already exists",
64                "Data object not found",
65        };
66        const int card_base = -SC_ERROR_CARD_CMD_FAILED;
67        const char *arg_errors[] = {
68                "Invalid arguments",
69                "Command too short",
70                "Command too long",
71                "Buffer too small",
72                "Invalid PIN length",
73                "Invalid data",
74        };
75        const int arg_base = -SC_ERROR_INVALID_ARGUMENTS;
76        const char *int_errors[] = {
77                "Internal error",
78                "Invalid ASN.1 object",
79                "Required ASN.1 object not found",
80                "Premature end of ASN.1 stream",
81                "Out of memory",
82                "Object not valid",
83                "Object not found",
84                "Requested object not found",
85                "Not supported",
86                "Passphrase required",
87                "The key is extractable",
88                "Decryption failed",
89                "Wrong padding",
90                "Unsupported card",
91                "Unable to load external module",
92                "EF offset too large"
93        };
94        const int int_base = -SC_ERROR_INTERNAL;
95        const char *p15i_errors[] = {
96                "Generic PKCS #15 initialization error",
97                "Syntax error",
98                "Inconsistent or incomplete pkcs15 profile",
99                "Key length/algorithm not supported by card",
100                "No default (transport) key available",
101                "The PKCS#15 Key/certificate ID specified is not unique",
102                "Unable to load key and certificate(s) from file",
103                "Object is not compatible with intended use",
104                "File template not found",
105                "Invalid PIN reference",
106                "File too small",
107        };
108        const int p15i_base = -SC_ERROR_PKCS15INIT;
109        const char *misc_errors[] = {
110                "Unknown error",
111                "PKCS#15 compatible smart card not found",
112        };
113        const int misc_base = -SC_ERROR_UNKNOWN;
114        const char **errors = NULL;
115        int count = 0, err_base = 0;
116       
117        if (error < 0)
118                error = -error;
119        if (error >= misc_base) {
120                errors = misc_errors;
121                count = DIM(misc_errors);
122                err_base = misc_base;
123        } else if (error >= p15i_base) {
124                errors = p15i_errors;
125                count = DIM(p15i_errors);
126                err_base = p15i_base;
127        } else if (error >= int_base) {
128                errors = int_errors;
129                count = DIM(int_errors);
130                err_base = int_base;
131        } else if (error >= arg_base) {
132                errors = arg_errors;
133                count = DIM(arg_errors);
134                err_base = arg_base;
135        } else if (error >= card_base) {
136                errors = card_errors;
137                count = DIM(card_errors);
138                err_base = card_base;
139        } else if (error >= rdr_base) {
140                errors = rdr_errors;
141                count = DIM(rdr_errors);
142                err_base = rdr_base;
143        }
144        error -= err_base;
145        if (error >= count || count == 0)
146                return misc_errors[0];
147        return errors[error];
148}
Note: See TracBrowser for help on using the browser.