Line data Source code
1 : /*
2 : * Copyright (C) 2012 Free Software Foundation
3 : *
4 : * Author: Nikos Mavrogiannopoulos
5 : *
6 : * This file is part of libdane.
7 : *
8 : * libdane is free software; you can redistribute it and/or
9 : * modify it under the terms of the GNU Lesser General Public License
10 : * as published by the Free Software Foundation; either version 2.1 of
11 : * the License, or (at your option) any later version.
12 : *
13 : * This library is distributed in the hope that it will be useful, but
14 : * WITHOUT ANY WARRANTY; without even the implied warranty of
15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : * Lesser General Public License for more details.
17 : *
18 : * You should have received a copy of the GNU Lesser General Public License
19 : * along with this program. If not, see <https://www.gnu.org/licenses/>
20 : *
21 : */
22 :
23 : #include <config.h>
24 : #include <gnutls/dane.h>
25 :
26 : /* I18n of error codes. */
27 : #include "gettext.h"
28 : #define _(String) dgettext (PACKAGE, String)
29 : #define N_(String) gettext_noop (String)
30 :
31 : #define ERROR_ENTRY(desc, name) \
32 : { desc, #name, name}
33 :
34 : struct error_entry {
35 : const char *desc;
36 : const char *_name;
37 : int number;
38 : };
39 : typedef struct error_entry error_entry;
40 :
41 : static const error_entry error_algorithms[] = {
42 : ERROR_ENTRY(N_("Success."), DANE_E_SUCCESS),
43 : ERROR_ENTRY(N_("There was error initializing the DNS query."),
44 : DANE_E_INITIALIZATION_ERROR),
45 : ERROR_ENTRY(N_("There was an error while resolving."),
46 : DANE_E_RESOLVING_ERROR),
47 : ERROR_ENTRY(N_("No DANE data were found."),
48 : DANE_E_NO_DANE_DATA),
49 : ERROR_ENTRY(N_("Unknown DANE data were found."),
50 : DANE_E_UNKNOWN_DANE_DATA),
51 : ERROR_ENTRY(N_("No DNSSEC signature was found."),
52 : DANE_E_NO_DNSSEC_SIG),
53 : ERROR_ENTRY(N_("Received corrupt data."),
54 : DANE_E_RECEIVED_CORRUPT_DATA),
55 : ERROR_ENTRY(N_("The DNSSEC signature is invalid."),
56 : DANE_E_INVALID_DNSSEC_SIG),
57 : ERROR_ENTRY(N_("There was a memory error."),
58 : DANE_E_MEMORY_ERROR),
59 : ERROR_ENTRY(N_("The requested data are not available."),
60 : DANE_E_REQUESTED_DATA_NOT_AVAILABLE),
61 : ERROR_ENTRY(N_("The request is invalid."),
62 : DANE_E_INVALID_REQUEST),
63 : ERROR_ENTRY(N_("There was an error in the certificate."),
64 : DANE_E_CERT_ERROR),
65 : ERROR_ENTRY(N_("There was an error in the public key."),
66 : DANE_E_PUBKEY_ERROR),
67 : ERROR_ENTRY(N_("No certificate was found."),
68 : DANE_E_NO_CERT),
69 : ERROR_ENTRY(N_("Error in file."),
70 : DANE_E_FILE_ERROR),
71 : {NULL, NULL, 0}
72 : };
73 :
74 : /**
75 : * dane_strerror:
76 : * @error: is a DANE error code, a negative error code
77 : *
78 : * This function is similar to strerror. The difference is that it
79 : * accepts an error number returned by a gnutls function; In case of
80 : * an unknown error a descriptive string is sent instead of %NULL.
81 : *
82 : * Error codes are always a negative error code.
83 : *
84 : * Returns: A string explaining the DANE error message.
85 : **/
86 15 : const char *dane_strerror(int error)
87 : {
88 15 : const char *ret = NULL;
89 15 : const error_entry *p;
90 :
91 120 : for (p = error_algorithms; p->desc != NULL; p++) {
92 120 : if (p->number == error) {
93 : ret = p->desc;
94 : break;
95 : }
96 : }
97 :
98 : /* avoid prefix */
99 15 : if (ret == NULL)
100 0 : return _("(unknown error code)");
101 :
102 15 : return _(ret);
103 : }
|