Updated to minitasn1 3.0
[gnutls.git] / lib / minitasn1 / errors.c
blob8b6e5e4df1482ff839e121dc35f030670a650b71
1 /*
2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 * This file is part of LIBTASN1.
6 * The LIBTASN1 library is free software; you can redistribute it
7 * and/or modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA
22 #include <int.h>
23 #ifdef STDC_HEADERS
24 #include <stdarg.h>
25 #endif
27 #define LIBTASN1_ERROR_ENTRY(name) { #name, name }
29 struct libtasn1_error_entry
31 const char *name;
32 int number;
34 typedef struct libtasn1_error_entry libtasn1_error_entry;
36 static const libtasn1_error_entry error_algorithms[] = {
37 LIBTASN1_ERROR_ENTRY (ASN1_SUCCESS),
38 LIBTASN1_ERROR_ENTRY (ASN1_FILE_NOT_FOUND),
39 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_FOUND),
40 LIBTASN1_ERROR_ENTRY (ASN1_IDENTIFIER_NOT_FOUND),
41 LIBTASN1_ERROR_ENTRY (ASN1_DER_ERROR),
42 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_FOUND),
43 LIBTASN1_ERROR_ENTRY (ASN1_GENERIC_ERROR),
44 LIBTASN1_ERROR_ENTRY (ASN1_VALUE_NOT_VALID),
45 LIBTASN1_ERROR_ENTRY (ASN1_TAG_ERROR),
46 LIBTASN1_ERROR_ENTRY (ASN1_TAG_IMPLICIT),
47 LIBTASN1_ERROR_ENTRY (ASN1_ERROR_TYPE_ANY),
48 LIBTASN1_ERROR_ENTRY (ASN1_SYNTAX_ERROR),
49 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ERROR),
50 LIBTASN1_ERROR_ENTRY (ASN1_MEM_ALLOC_ERROR),
51 LIBTASN1_ERROR_ENTRY (ASN1_DER_OVERFLOW),
52 LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG),
53 LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR),
54 LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY),
55 {0, 0}
58 /**
59 * asn1_perror:
60 * @error: is an error returned by a libtasn1 function.
62 * Prints a string to stderr with a description of an error. This
63 * function is like perror(). The only difference is that it accepts
64 * an error returned by a libtasn1 function.
66 * This function replaces libtasn1_perror() in older libtasn1.
68 * Since: 1.6
69 **/
70 void
71 asn1_perror (asn1_retCode error)
73 const char *str = asn1_strerror (error);
74 fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
77 /**
78 * asn1_strerror:
79 * @error: is an error returned by a libtasn1 function.
81 * Returns a string with a description of an error. This function is
82 * similar to strerror. The only difference is that it accepts an
83 * error (number) returned by a libtasn1 function.
85 * This function replaces libtasn1_strerror() in older libtasn1.
87 * Returns: Pointer to static zero-terminated string describing error
88 * code.
90 * Since: 1.6
91 **/
92 const char *
93 asn1_strerror (asn1_retCode error)
95 const libtasn1_error_entry *p;
97 for (p = error_algorithms; p->name != NULL; p++)
98 if (p->number == error)
99 return p->name + sizeof ("ASN1_") - 1;
101 return NULL;