1 /* maperror.c - Error mapping
2 * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 /* Note: we might want to wrap this in a macro to get our hands on
36 the line and file where the error occured */
38 map_ksba_err (int err)
45 case -1: err = GPG_ERR_EOF; break;
46 case KSBA_Out_Of_Core: err = GPG_ERR_ENOMEM; break;
47 case KSBA_Invalid_Value: err = GPG_ERR_INV_VALUE; break;
48 case KSBA_Not_Implemented: err = GPG_ERR_NOT_IMPLEMENTED; break;
49 case KSBA_Conflict: err = GPG_ERR_CONFLICT; break;
50 case KSBA_Read_Error: err = GPG_ERR_EIO; break;
51 case KSBA_Write_Error: err = GPG_ERR_EIO; break;
52 case KSBA_No_Data: err = GPG_ERR_NO_DATA; break;
53 case KSBA_Bug: err = GPG_ERR_BUG; break;
54 case KSBA_Unsupported_Algorithm: err = GPG_ERR_UNSUPPORTED_ALGORITHM; break;
55 case KSBA_Invalid_Index: err = GPG_ERR_INV_INDEX; break;
56 case KSBA_Invalid_Sexp: err = GPG_ERR_INV_SEXP; break;
57 case KSBA_Unknown_Sexp: err = GPG_ERR_UNKNOWN_SEXP; break;
60 err = GPG_ERR_GENERAL;
63 return gpg_err_make (GPG_ERR_SOURCE_GPGSM, err);
68 map_gcry_err (int err)
79 /* Map Assuan error code ERR to an GPG_ERR_ code. We need to
80 distinguish between genuine (and legacy) Assuan error codes and
81 application error codes shared with all GnuPG modules. The rule is
82 simple: All errors with a gpg_err_source of UNKNOWN are genuine
83 Assuan codes all others are passed verbatim through. */
85 map_assuan_err (int err)
89 if (gpg_err_source (err))
94 case -1: ec = GPG_ERR_EOF; break;
95 case 0: ec = 0; break;
97 case ASSUAN_Canceled: ec = GPG_ERR_CANCELED; break;
98 case ASSUAN_Invalid_Index: ec = GPG_ERR_INV_INDEX; break;
100 case ASSUAN_Not_Implemented: ec = GPG_ERR_NOT_IMPLEMENTED; break;
101 case ASSUAN_Server_Fault: ec = GPG_ERR_ASSUAN_SERVER_FAULT; break;
102 case ASSUAN_No_Public_Key: ec = GPG_ERR_NO_PUBKEY; break;
103 case ASSUAN_No_Secret_Key: ec = GPG_ERR_NO_SECKEY; break;
105 case ASSUAN_Cert_Revoked: ec = GPG_ERR_CERT_REVOKED; break;
106 case ASSUAN_No_CRL_For_Cert: ec = GPG_ERR_NO_CRL_KNOWN; break;
107 case ASSUAN_CRL_Too_Old: ec = GPG_ERR_CRL_TOO_OLD; break;
109 case ASSUAN_Not_Trusted: ec = GPG_ERR_NOT_TRUSTED; break;
111 case ASSUAN_Card_Error: ec = GPG_ERR_CARD; break;
112 case ASSUAN_Invalid_Card: ec = GPG_ERR_INV_CARD; break;
113 case ASSUAN_No_PKCS15_App: ec = GPG_ERR_NO_PKCS15_APP; break;
114 case ASSUAN_Card_Not_Present: ec= GPG_ERR_CARD_NOT_PRESENT; break;
115 case ASSUAN_Not_Confirmed: ec = GPG_ERR_NOT_CONFIRMED; break;
116 case ASSUAN_Invalid_Id: ec = GPG_ERR_INV_ID; break;
119 ec = err < 100? GPG_ERR_ASSUAN_SERVER_FAULT : GPG_ERR_ASSUAN;
122 return gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, ec);
125 /* Map GPG_xERR_xx error codes to Assuan status codes */
127 map_to_assuan_status (int rc)
129 gpg_err_code_t ec = gpg_err_code (rc);
130 gpg_err_source_t es = gpg_err_source (rc);
136 es = GPG_ERR_SOURCE_USER_4; /* This should not happen, but we
137 need to make sure to pass a new
138 Assuan errorcode along. */
139 log_debug ("map_to_assuan_status called with no error source\n");
143 ec = GPG_ERR_NO_DATA; /* That used to be ASSUAN_No_Data_Available. */
145 return gpg_err_make (es, ec);