00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LIBTASN1_H
00025 # define LIBTASN1_H
00026
00027 #include <stdio.h>
00028
00029 #ifdef __cplusplus
00030 extern "C"
00031 {
00032 #endif
00033
00034 #define LIBTASN1_VERSION "1.2"
00035
00036 #include <sys/types.h>
00037 #include <time.h>
00038
00039 #define MAX_NAME_SIZE 128
00040
00041 #define MAX_ERROR_DESCRIPTION_SIZE 128
00042
00043
00044
00045
00046 typedef int MHD__asn1_retCode;
00047
00048
00049
00050
00051 #define ASN1_SUCCESS 0
00052 #define ASN1_FILE_NOT_FOUND 1
00053 #define ASN1_ELEMENT_NOT_FOUND 2
00054 #define ASN1_IDENTIFIER_NOT_FOUND 3
00055 #define ASN1_DER_ERROR 4
00056 #define ASN1_VALUE_NOT_FOUND 5
00057 #define ASN1_GENERIC_ERROR 6
00058 #define ASN1_VALUE_NOT_VALID 7
00059 #define ASN1_TAG_ERROR 8
00060 #define ASN1_TAG_IMPLICIT 9
00061 #define ASN1_ERROR_TYPE_ANY 10
00062 #define ASN1_SYNTAX_ERROR 11
00063 #define ASN1_MEM_ERROR 12
00064 #define ASN1_MEM_ALLOC_ERROR 13
00065 #define ASN1_DER_OVERFLOW 14
00066 #define ASN1_NAME_TOO_LONG 15
00067 #define ASN1_ARRAY_ERROR 16
00068 #define ASN1_ELEMENT_NOT_EMPTY 17
00069
00070
00071
00072
00073 #define ASN1_PRINT_NAME 1
00074 #define ASN1_PRINT_NAME_TYPE 2
00075 #define ASN1_PRINT_NAME_TYPE_VALUE 3
00076 #define ASN1_PRINT_ALL 4
00077
00078
00079
00080
00081 #define ASN1_CLASS_UNIVERSAL 0x00
00082 #define ASN1_CLASS_APPLICATION 0x40
00083 #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80
00084 #define ASN1_CLASS_PRIVATE 0xC0
00085 #define ASN1_CLASS_STRUCTURED 0x20
00086
00087
00088
00089
00090 #define ASN1_TAG_BOOLEAN 0x01
00091 #define ASN1_TAG_INTEGER 0x02
00092 #define ASN1_TAG_SEQUENCE 0x10
00093 #define ASN1_TAG_SET 0x11
00094 #define ASN1_TAG_OCTET_STRING 0x04
00095 #define ASN1_TAG_BIT_STRING 0x03
00096 #define ASN1_TAG_UTCTime 0x17
00097 #define ASN1_TAG_GENERALIZEDTime 0x18
00098 #define ASN1_TAG_OBJECT_ID 0x06
00099 #define ASN1_TAG_ENUMERATED 0x0A
00100 #define ASN1_TAG_NULL 0x05
00101 #define ASN1_TAG_GENERALSTRING 0x1B
00102
00103
00104
00105
00106
00107
00108 struct node_asn_struct
00109 {
00110 char *name;
00111 unsigned int type;
00112 unsigned char *value;
00113 int value_len;
00114 struct node_asn_struct *down;
00115 struct node_asn_struct *right;
00116 struct node_asn_struct *left;
00117 };
00118
00119 typedef struct node_asn_struct node_asn;
00120
00121 typedef node_asn *ASN1_TYPE;
00122
00123 #define ASN1_TYPE_EMPTY NULL
00124
00125 struct static_struct_asn
00126 {
00127 const char *name;
00128 unsigned int type;
00129 const void *value;
00130 };
00131
00132 typedef struct static_struct_asn ASN1_ARRAY_TYPE;
00133
00134
00135
00136
00137
00138
00139
00140 MHD__asn1_retCode MHD__asn1_parser2tree (const char *file_name,
00141 ASN1_TYPE * definitions,
00142 char *errorDescription);
00143
00144 MHD__asn1_retCode MHD__asn1_parser2array (const char *inputFileName,
00145 const char *outputFileName,
00146 const char *vectorName,
00147 char *errorDescription);
00148
00149 MHD__asn1_retCode MHD__asn1_array2tree (const ASN1_ARRAY_TYPE * array,
00150 ASN1_TYPE * definitions,
00151 char *errorDescription);
00152
00153 MHD__asn1_retCode MHD__asn1_create_element (ASN1_TYPE definitions,
00154 const char *source_name,
00155 ASN1_TYPE * element);
00156
00157 MHD__asn1_retCode MHD__asn1_delete_structure (ASN1_TYPE * structure);
00158
00159 MHD__asn1_retCode MHD__asn1_write_value (ASN1_TYPE node_root,
00160 const char *name,
00161 const void *ivalue, int len);
00162
00163 MHD__asn1_retCode MHD__asn1_read_value (ASN1_TYPE root, const char *name,
00164 void *ivalue, int *len);
00165
00166 MHD__asn1_retCode MHD__asn1_der_coding (ASN1_TYPE element, const char *name,
00167 void *ider, int *len,
00168 char *ErrorDescription);
00169
00170 MHD__asn1_retCode MHD__asn1_der_decoding (ASN1_TYPE * element,
00171 const void *ider, int len,
00172 char *errorDescription);
00173
00174 MHD__asn1_retCode MHD__asn1_der_decoding_startEnd (ASN1_TYPE element,
00175 const void *ider,
00176 int len,
00177 const char *name_element,
00178 int *start, int *end);
00179
00180
00181
00182 int MHD__asn1_get_tag_der (const unsigned char *der, int der_len,
00183 unsigned char *cls, int *len,
00184 unsigned long *tag);
00185
00186 void MHD__asn1_octet_der (const unsigned char *str, int str_len,
00187 unsigned char *der, int *der_len);
00188
00189 MHD__asn1_retCode MHD__asn1_get_octet_der (const unsigned char *der,
00190 int der_len, int *ret_len,
00191 unsigned char *str, int str_size,
00192 int *str_len);
00193
00194 void MHD__asn1_bit_der (const unsigned char *str, int bit_len,
00195 unsigned char *der, int *der_len);
00196
00197 MHD__asn1_retCode MHD__asn1_get_bit_der (const unsigned char *der,
00198 int der_len, int *ret_len,
00199 unsigned char *str, int str_size,
00200 int *bit_len);
00201
00202 signed long MHD__asn1_get_length_der (const unsigned char *der, int der_len,
00203 int *len);
00204
00205 void MHD__asn1_length_der (unsigned long int len, unsigned char *ans,
00206 int *ans_len);
00207
00208
00209
00210 ASN1_TYPE MHD__asn1_find_node (ASN1_TYPE pointer, const char *name);
00211
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215
00216 #endif