2 * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010 Free Software
5 * This file is part of LIBTASN1.
7 * The LIBTASN1 library is free software; you can redistribute it
8 * and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #define LIBTASN1_ERROR_ENTRY(name) { #name, name }
30 struct libtasn1_error_entry
35 typedef struct libtasn1_error_entry libtasn1_error_entry;
37 static const libtasn1_error_entry error_algorithms[] = {
38 LIBTASN1_ERROR_ENTRY (ASN1_SUCCESS),
39 LIBTASN1_ERROR_ENTRY (ASN1_FILE_NOT_FOUND),
40 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_FOUND),
41 LIBTASN1_ERROR_ENTRY (ASN1_IDENTIFIER_NOT_FOUND),
42 LIBTASN1_ERROR_ENTRY (ASN1_DER_ERROR),
43 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_FOUND),
44 LIBTASN1_ERROR_ENTRY (ASN1_GENERIC_ERROR),
45 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_VALID),
46 LIBTASN1_ERROR_ENTRY (ASN1_TAG_ERROR),
47 LIBTASN1_ERROR_ENTRY (ASN1_TAG_IMPLICIT),
48 LIBTASN1_ERROR_ENTRY (ASN1_ERROR_TYPE_ANY),
49 LIBTASN1_ERROR_ENTRY (ASN1_SYNTAX_ERROR),
50 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ERROR),
51 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ALLOC_ERROR),
52 LIBTASN1_ERROR_ENTRY (ASN1_DER_OVERFLOW),
53 LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG),
54 LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR),
55 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY),
61 * @error: is an error returned by a libtasn1 function.
63 * Prints a string to stderr with a description of an error. This
64 * function is like perror(). The only difference is that it accepts
65 * an error returned by a libtasn1 function.
67 * This function replaces libtasn1_perror() in older libtasn1.
72 asn1_perror (asn1_retCode error)
74 const char *str = asn1_strerror (error);
75 fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
80 * @error: is an error returned by a libtasn1 function.
82 * Returns a string with a description of an error. This function is
83 * similar to strerror. The only difference is that it accepts an
84 * error (number) returned by a libtasn1 function.
86 * This function replaces libtasn1_strerror() in older libtasn1.
88 * Returns: Pointer to static zero-terminated string describing error
94 asn1_strerror (asn1_retCode error)
96 const libtasn1_error_entry *p;
98 for (p = error_algorithms; p->name != NULL; p++)
99 if (p->number == error)
100 return p->name + sizeof ("ASN1_") - 1;
105 #ifndef ASN1_DISABLE_DEPRECATED
107 /* Compatibility mappings to preserve ABI. */
111 * @error: is an error returned by a libtasn1 function.
113 * Prints a string to stderr with a description of an error. This
114 * function is like perror(). The only difference is that it accepts
115 * an error returned by a libtasn1 function.
117 * Deprecated: Use asn1_perror() instead.
120 libtasn1_perror (asn1_retCode error)
127 * @error: is an error returned by a libtasn1 function.
129 * Returns a string with a description of an error. This function is
130 * similar to strerror. The only difference is that it accepts an
131 * error (number) returned by a libtasn1 function.
133 * Returns: Pointer to static zero-terminated string describing error
136 * Deprecated: Use asn1_strerror() instead.
139 libtasn1_strerror (asn1_retCode error)
141 return asn1_strerror (error);