|
Packit |
aea12f |
/*
|
|
Packit |
aea12f |
* Copyright (C) 2012 Free Software Foundation
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Author: Nikos Mavrogiannopoulos
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This file is part of libdane.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* libdane is free software; you can redistribute it and/or
|
|
Packit |
aea12f |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
aea12f |
* the License, or (at your option) any later version.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This library is distributed in the hope that it will be useful, but
|
|
Packit |
aea12f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
* Lesser General Public License for more details.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aea12f |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
*/
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#include <config.h>
|
|
Packit |
aea12f |
#include <gnutls/dane.h>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* I18n of error codes. */
|
|
Packit |
aea12f |
#include "gettext.h"
|
|
Packit |
aea12f |
#define _(String) dgettext (PACKAGE, String)
|
|
Packit |
aea12f |
#define N_(String) gettext_noop (String)
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
#define ERROR_ENTRY(desc, name) \
|
|
Packit |
aea12f |
{ desc, #name, name}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
struct error_entry {
|
|
Packit |
aea12f |
const char *desc;
|
|
Packit |
aea12f |
const char *_name;
|
|
Packit |
aea12f |
int number;
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
typedef struct error_entry error_entry;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
static const error_entry error_algorithms[] = {
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("Success."), DANE_E_SUCCESS),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("There was error initializing the DNS query."),
|
|
Packit |
aea12f |
DANE_E_INITIALIZATION_ERROR),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("There was an error while resolving."),
|
|
Packit |
aea12f |
DANE_E_RESOLVING_ERROR),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("No DANE data were found."),
|
|
Packit |
aea12f |
DANE_E_NO_DANE_DATA),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("Unknown DANE data were found."),
|
|
Packit |
aea12f |
DANE_E_UNKNOWN_DANE_DATA),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("No DNSSEC signature was found."),
|
|
Packit |
aea12f |
DANE_E_NO_DNSSEC_SIG),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("Received corrupt data."),
|
|
Packit |
aea12f |
DANE_E_RECEIVED_CORRUPT_DATA),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("The DNSSEC signature is invalid."),
|
|
Packit |
aea12f |
DANE_E_INVALID_DNSSEC_SIG),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("There was a memory error."),
|
|
Packit |
aea12f |
DANE_E_MEMORY_ERROR),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("The requested data are not available."),
|
|
Packit |
aea12f |
DANE_E_REQUESTED_DATA_NOT_AVAILABLE),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("The request is invalid."),
|
|
Packit |
aea12f |
DANE_E_INVALID_REQUEST),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("There was an error in the certificate."),
|
|
Packit |
aea12f |
DANE_E_CERT_ERROR),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("There was an error in the public key."),
|
|
Packit |
aea12f |
DANE_E_PUBKEY_ERROR),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("No certificate was found."),
|
|
Packit |
aea12f |
DANE_E_NO_CERT),
|
|
Packit |
aea12f |
ERROR_ENTRY(N_("Error in file."),
|
|
Packit |
aea12f |
DANE_E_FILE_ERROR),
|
|
Packit |
aea12f |
{NULL, NULL, 0}
|
|
Packit |
aea12f |
};
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/**
|
|
Packit |
aea12f |
* dane_strerror:
|
|
Packit |
aea12f |
* @error: is a DANE error code, a negative error code
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* This function is similar to strerror. The difference is that it
|
|
Packit |
aea12f |
* accepts an error number returned by a gnutls function; In case of
|
|
Packit |
aea12f |
* an unknown error a descriptive string is sent instead of %NULL.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Error codes are always a negative error code.
|
|
Packit |
aea12f |
*
|
|
Packit |
aea12f |
* Returns: A string explaining the DANE error message.
|
|
Packit |
aea12f |
**/
|
|
Packit |
aea12f |
const char *dane_strerror(int error)
|
|
Packit |
aea12f |
{
|
|
Packit |
aea12f |
const char *ret = NULL;
|
|
Packit |
aea12f |
const error_entry *p;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
for (p = error_algorithms; p->desc != NULL; p++) {
|
|
Packit |
aea12f |
if (p->number == error) {
|
|
Packit |
aea12f |
ret = p->desc;
|
|
Packit |
aea12f |
break;
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
}
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
/* avoid prefix */
|
|
Packit |
aea12f |
if (ret == NULL)
|
|
Packit |
aea12f |
return _("(unknown error code)");
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
return _(ret);
|
|
Packit |
aea12f |
}
|