|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2002-2014 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of LIBTASN1.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The LIBTASN1 library is free software; you can redistribute it
|
|
Packit Service |
4684c1 |
* and/or modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
4684c1 |
* version 2.1 of 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
|
|
Packit Service |
4684c1 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
4684c1 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
4684c1 |
* 02110-1301, USA
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <int.h>
|
|
Packit Service |
4684c1 |
#ifdef STDC_HEADERS
|
|
Packit Service |
4684c1 |
#include <stdarg.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define LIBTASN1_ERROR_ENTRY(name) { #name, name }
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct libtasn1_error_entry
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
const char *name;
|
|
Packit Service |
4684c1 |
int number;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
typedef struct libtasn1_error_entry libtasn1_error_entry;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const libtasn1_error_entry error_algorithms[] = {
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_SUCCESS),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_FILE_NOT_FOUND),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_FOUND),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_IDENTIFIER_NOT_FOUND),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_DER_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_FOUND),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_GENERIC_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_VALID),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_TAG_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_TAG_IMPLICIT),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_ERROR_TYPE_ANY),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_SYNTAX_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_MEM_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_MEM_ALLOC_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_DER_OVERFLOW),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_TIME_ENCODING_ERROR),
|
|
Packit Service |
4684c1 |
LIBTASN1_ERROR_ENTRY (ASN1_RECURSION),
|
|
Packit Service |
4684c1 |
{0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* asn1_perror:
|
|
Packit Service |
4684c1 |
* @error: is an error returned by a libtasn1 function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Prints a string to stderr with a description of an error. This
|
|
Packit Service |
4684c1 |
* function is like perror(). The only difference is that it accepts
|
|
Packit Service |
4684c1 |
* an error returned by a libtasn1 function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Since: 1.6
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
asn1_perror (int error)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
const char *str = asn1_strerror (error);
|
|
Packit Service |
4684c1 |
fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* asn1_strerror:
|
|
Packit Service |
4684c1 |
* @error: is an error returned by a libtasn1 function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns a string with a description of an error. This function is
|
|
Packit Service |
4684c1 |
* similar to strerror. The only difference is that it accepts an
|
|
Packit Service |
4684c1 |
* error (number) returned by a libtasn1 function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns: Pointer to static zero-terminated string describing error
|
|
Packit Service |
4684c1 |
* code.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Since: 1.6
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
const char *
|
|
Packit Service |
4684c1 |
asn1_strerror (int error)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
const libtasn1_error_entry *p;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (p = error_algorithms; p->name != NULL; p++)
|
|
Packit Service |
4684c1 |
if (p->number == error)
|
|
Packit Service |
4684c1 |
return p->name + sizeof ("ASN1_") - 1;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return NULL;
|
|
Packit Service |
4684c1 |
}
|