Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2002-2012 Free Software Foundation, Inc.
3 : : *
4 : : * This file is part of LIBTASN1.
5 : : *
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.
10 : : *
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.
15 : : *
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
20 : : */
21 : :
22 : : #include <int.h>
23 : : #ifdef STDC_HEADERS
24 : : #include <stdarg.h>
25 : : #endif
26 : :
27 : : #define LIBTASN1_ERROR_ENTRY(name) { #name, name }
28 : :
29 : : struct libtasn1_error_entry
30 : : {
31 : : const char *name;
32 : : int number;
33 : : };
34 : : typedef struct libtasn1_error_entry libtasn1_error_entry;
35 : :
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}
56 : : };
57 : :
58 : : /**
59 : : * asn1_perror:
60 : : * @error: is an error returned by a libtasn1 function.
61 : : *
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.
65 : : *
66 : : * This function replaces libtasn1_perror() in older libtasn1.
67 : : *
68 : : * Since: 1.6
69 : : **/
70 : : void
71 : 19 : asn1_perror (asn1_retCode error)
72 : : {
73 : 19 : const char *str = asn1_strerror (error);
74 [ + + ]: 19 : fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
75 : 19 : }
76 : :
77 : : /**
78 : : * asn1_strerror:
79 : : * @error: is an error returned by a libtasn1 function.
80 : : *
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.
84 : : *
85 : : * This function replaces libtasn1_strerror() in older libtasn1.
86 : : *
87 : : * Returns: Pointer to static zero-terminated string describing error
88 : : * code.
89 : : *
90 : : * Since: 1.6
91 : : **/
92 : : const char *
93 : 39 : asn1_strerror (asn1_retCode error)
94 : : {
95 : : const libtasn1_error_entry *p;
96 : :
97 [ + + ]: 381 : for (p = error_algorithms; p->name != NULL; p++)
98 [ + + ]: 379 : if (p->number == error)
99 : 37 : return p->name + sizeof ("ASN1_") - 1;
100 : :
101 : 39 : return NULL;
102 : : }
103 : :
104 : : #ifndef ASN1_DISABLE_DEPRECATED
105 : :
106 : : /* Compatibility mappings to preserve ABI. */
107 : :
108 : : /**
109 : : * libtasn1_perror:
110 : : * @error: is an error returned by a libtasn1 function.
111 : : *
112 : : * Prints a string to stderr with a description of an error. This
113 : : * function is like perror(). The only difference is that it accepts
114 : : * an error returned by a libtasn1 function.
115 : : *
116 : : * Deprecated: Use asn1_perror() instead.
117 : : **/
118 : : void
119 : 0 : libtasn1_perror (asn1_retCode error)
120 : : {
121 : 0 : asn1_perror (error);
122 : 0 : }
123 : :
124 : : /**
125 : : * libtasn1_strerror:
126 : : * @error: is an error returned by a libtasn1 function.
127 : : *
128 : : * Returns a string with a description of an error. This function is
129 : : * similar to strerror. The only difference is that it accepts an
130 : : * error (number) returned by a libtasn1 function.
131 : : *
132 : : * Returns: Pointer to static zero-terminated string describing error
133 : : * code.
134 : : *
135 : : * Deprecated: Use asn1_strerror() instead.
136 : : **/
137 : : const char *
138 : 0 : libtasn1_strerror (asn1_retCode error)
139 : : {
140 : 0 : return asn1_strerror (error);
141 : : }
142 : :
143 : : #endif
|