libtasn1.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2004, 2005, 2006 Free Software Foundation
00003  *      Copyright (C) 2002 Fabio Fiorina
00004  *
00005  * This file is part of LIBTASN1.
00006  *
00007  * LIBTASN1 is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as
00009  * published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * LIBTASN1 is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with LIBTASN1; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020  * 02110-1301, USA
00021  *
00022  */
00023 
00024 #ifndef LIBTASN1_H
00025 # define LIBTASN1_H
00026 
00027 #include <stdio.h>              /* for FILE* */
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       /* maximum number of characters of a name */
00040   /* inside a file with ASN1 definitons     */
00041 #define MAX_ERROR_DESCRIPTION_SIZE 128  /* maximum number of characters */
00042   /* of a description message     */
00043   /* (null character included)    */
00044 
00045 
00046   typedef int MHD__asn1_retCode;        /* type returned by libtasn1 functions */
00047 
00048   /*****************************************/
00049   /*  Errors returned by libtasn1 functions */
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 /* Constants used in MHD__asn1_visit_tree */
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 /* Constants returned by MHD__asn1_read_tag   */
00080 /*****************************************/
00081 #define ASN1_CLASS_UNIVERSAL        0x00        /* old: 1 */
00082 #define ASN1_CLASS_APPLICATION      0x40        /* old: 2 */
00083 #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80        /* old: 3 */
00084 #define ASN1_CLASS_PRIVATE          0xC0        /* old: 4 */
00085 #define ASN1_CLASS_STRUCTURED       0x20
00086 
00087 /*****************************************/
00088 /* Constants returned by MHD__asn1_read_tag   */
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 /* Structure definition used for the node of the tree */
00105 /* that represent an ASN.1 DEFINITION.                */
00106 /******************************************************/
00107 
00108   struct node_asn_struct
00109   {
00110     char *name;                 /* Node name */
00111     unsigned int type;          /* Node type */
00112     unsigned char *value;       /* Node value */
00113     int value_len;
00114     struct node_asn_struct *down;       /* Pointer to the son node */
00115     struct node_asn_struct *right;      /* Pointer to the brother node */
00116     struct node_asn_struct *left;       /* Pointer to the next list element */
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;           /* Node name */
00128     unsigned int type;          /* Node type */
00129     const void *value;          /* Node value */
00130   };
00131 
00132   typedef struct static_struct_asn ASN1_ARRAY_TYPE;
00133 
00134 
00135 
00136   /***********************************/
00137   /*  Functions definitions          */
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   /* DER utility functions. */
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   /* Other utility functions. */
00209 
00210   ASN1_TYPE MHD__asn1_find_node (ASN1_TYPE pointer, const char *name);
00211 
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215 
00216 #endif                          /* LIBTASN1_H */

Generated on Fri Feb 27 18:32:18 2009 for GNU libmicrohttpd by  doxygen 1.5.7.1