errors.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <int.h>
00021 #include "errors.h"
00022 #ifdef STDC_HEADERS
00023 # include <stdarg.h>
00024 #endif
00025
00026
00027 #define LIBTASN1_ERROR_ENTRY(name) \
00028 { #name, name }
00029
00030 struct libtasn1_error_entry {
00031 const char *name;
00032 int number;
00033 };
00034 typedef struct libtasn1_error_entry libtasn1_error_entry;
00035
00036 static libtasn1_error_entry error_algorithms[] = {
00037 LIBTASN1_ERROR_ENTRY( ASN1_SUCCESS ),
00038 LIBTASN1_ERROR_ENTRY( ASN1_FILE_NOT_FOUND ),
00039 LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_FOUND ),
00040 LIBTASN1_ERROR_ENTRY( ASN1_IDENTIFIER_NOT_FOUND ),
00041 LIBTASN1_ERROR_ENTRY( ASN1_DER_ERROR ),
00042 LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_FOUND ),
00043 LIBTASN1_ERROR_ENTRY( ASN1_GENERIC_ERROR ),
00044 LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_VALID ),
00045 LIBTASN1_ERROR_ENTRY( ASN1_TAG_ERROR ),
00046 LIBTASN1_ERROR_ENTRY( ASN1_TAG_IMPLICIT ),
00047 LIBTASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
00048 LIBTASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
00049 LIBTASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
00050 LIBTASN1_ERROR_ENTRY( ASN1_MEM_ALLOC_ERROR ),
00051 LIBTASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
00052 LIBTASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
00053 LIBTASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
00054 LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_EMPTY ),
00055 {0}
00056 };
00057
00058 #define LIBTASN1_ERROR_LOOP(b) \
00059 const libtasn1_error_entry *p; \
00060 for(p = error_algorithms; p->name != NULL; p++) { b ; }
00061
00062 #define LIBTASN1_ERROR_ALG_LOOP(a) \
00063 LIBTASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 void libtasn1_perror(asn1_retCode error)
00075 {
00076 const char *ret = NULL;
00077
00078
00079 LIBTASN1_ERROR_ALG_LOOP(ret =
00080 p->name + sizeof("ASN1_") - 1);
00081
00082 _libtasn1_log( "LIBTASN1 ERROR: %s\n", ret);
00083
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 const char* libtasn1_strerror(asn1_retCode error)
00095 {
00096 const char *ret = NULL;
00097
00098
00099 LIBTASN1_ERROR_ALG_LOOP(ret =
00100 p->name + sizeof("ASN1_") - 1);
00101
00102 return ret;
00103 }
00104
00105
00106
00107 #ifdef LIBTASN1_DEBUG
00108 void _libtasn1_log( const char *fmt, ...) {
00109 va_list args;
00110 char str[MAX_LOG_SIZE];
00111
00112 va_start(args,fmt);
00113 vsprintf( str,fmt,args);
00114 va_end(args);
00115
00116 fprintf(stderr, str);
00117
00118 return;
00119 }
00120 #else
00121 # ifndef C99_MACROS
00122
00123
00124
00125
00126 void _libtasn1_null_log( void* x, ...) { return; }
00127 # endif
00128 #endif
00129