Blame libdane/errors.c

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