Sourcecode and documentation for libtasn1-2 version 0.2.10-3sarge1
show bar | Show file versions
Search packages:
| Sourcecode archive home

libtasn1.h

00001 /*
00002  *      Copyright (C) 2002 Fabio Fiorina
00003  *
00004  * This file is part of LIBTASN1.
00005  *
00006  * The LIBTASN1 library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public   
00008  * License as published by the Free Software Foundation; either 
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef LIBASN1_H
00023 # define LIBASN1_H
00024 
00025 #include <stdio.h> /* for FILE* */
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 #define LIBTASN1_VERSION "0.2.10"
00032 
00033 #include <sys/types.h>
00034 #include <time.h>
00035 
00036 #define MAX_NAME_SIZE 128 /* maximum number of characters of a name */ 
00037                     /* inside a file with ASN1 definitons     */
00038 #define MAX_ERROR_DESCRIPTION_SIZE 128 /* maximum number of characters */ 
00039                                         /* of a description message     */
00040                                         /* (null character included)    */
00041 
00042 
00043 typedef int asn1_retCode;  /* type returned by libasn1 functions */
00044 
00045   /*****************************************/
00046   /*  Errors returned by libasn1 functions */
00047   /*****************************************/
00048 #define ASN1_SUCCESS               0
00049 #define ASN1_FILE_NOT_FOUND        1
00050 #define ASN1_ELEMENT_NOT_FOUND     2
00051 #define ASN1_IDENTIFIER_NOT_FOUND  3
00052 #define ASN1_DER_ERROR             4
00053 #define ASN1_VALUE_NOT_FOUND       5
00054 #define ASN1_GENERIC_ERROR         6
00055 #define ASN1_VALUE_NOT_VALID       7
00056 #define ASN1_TAG_ERROR             8
00057 #define ASN1_TAG_IMPLICIT          9
00058 #define ASN1_ERROR_TYPE_ANY        10
00059 #define ASN1_SYNTAX_ERROR          11
00060 #define ASN1_MEM_ERROR           12
00061 #define ASN1_MEM_ALLOC_ERROR     13
00062 #define ASN1_DER_OVERFLOW          14
00063 #define ASN1_NAME_TOO_LONG         15
00064 #define ASN1_ARRAY_ERROR           16
00065 #define ASN1_ELEMENT_NOT_EMPTY     17
00066 
00067 /*************************************/
00068 /* Constants used in asn1_visit_tree */
00069 /*************************************/
00070 #define ASN1_PRINT_NAME             1
00071 #define ASN1_PRINT_NAME_TYPE        2
00072 #define ASN1_PRINT_NAME_TYPE_VALUE  3
00073 #define ASN1_PRINT_ALL              4
00074 
00075 /*****************************************/
00076 /* Constants returned by asn1_read_tag   */
00077 /*****************************************/
00078 #define ASN1_CLASS_UNIVERSAL        1
00079 #define ASN1_CLASS_APPLICATION      2
00080 #define ASN1_CLASS_CONTEXT_SPECIFIC 3
00081 #define ASN1_CLASS_PRIVATE          4
00082 
00083 
00084 /*****************************************/
00085 /* Constants returned by asn1_read_tag   */
00086 /*****************************************/
00087 #define ASN1_TAG_BOOLEAN          0x01
00088 #define ASN1_TAG_INTEGER          0x02
00089 #define ASN1_TAG_SEQUENCE         0x10
00090 #define ASN1_TAG_SET              0x11
00091 #define ASN1_TAG_OCTET_STRING     0x04
00092 #define ASN1_TAG_BIT_STRING       0x03
00093 #define ASN1_TAG_UTCTime          0x17
00094 #define ASN1_TAG_GENERALIZEDTime  0x18
00095 #define ASN1_TAG_OBJECT_ID        0x06
00096 #define ASN1_TAG_ENUMERATED       0x0A
00097 #define ASN1_TAG_NULL             0x05
00098 #define ASN1_TAG_GENERALSTRING    0x1B
00099 
00100 
00101 /******************************************************/
00102 /* Structure definition used for the node of the tree */
00103 /* that rappresent an ASN.1 DEFINITION.               */
00104 /******************************************************/
00105 typedef struct node_asn_struct{
00106   char *name;                    /* Node name */
00107   unsigned int type;             /* Node type */
00108   unsigned char *value;          /* Node value */
00109   int value_len;
00110   struct node_asn_struct *down;  /* Pointer to the son node */
00111   struct node_asn_struct *right; /* Pointer to the brother node */
00112   struct node_asn_struct *left;  /* Pointer to the next list element */ 
00113 } node_asn;
00114 
00115 typedef node_asn* ASN1_TYPE;
00116 
00117 #define ASN1_TYPE_EMPTY  NULL
00118 
00119 struct static_struct_asn{
00120   char *name;                    /* Node name */
00121   unsigned int type;             /* Node type */
00122   unsigned char *value;          /* Node value */
00123 };
00124 
00125 typedef struct static_struct_asn ASN1_ARRAY_TYPE;
00126 
00127 
00128 
00129   /***********************************/
00130   /*  Functions definitions          */
00131   /***********************************/
00132 
00133 asn1_retCode asn1_parser2tree(const char *file_name,ASN1_TYPE *definitions,
00134                               char *errorDescription);
00135 
00136 asn1_retCode asn1_parser2array(const char *inputFileName,const char *outputFileName,
00137                                const char *vectorName,char *errorDescription);
00138 
00139 asn1_retCode asn1_array2tree(const ASN1_ARRAY_TYPE *array,
00140                              ASN1_TYPE *definitions,char *errorDescription);
00141 
00142 void asn1_print_structure(FILE *out,ASN1_TYPE structure,const char *name,int mode);
00143 
00144 asn1_retCode asn1_create_element(ASN1_TYPE definitions,const char *source_name,
00145                                  ASN1_TYPE *element);
00146 
00147 asn1_retCode asn1_delete_structure(ASN1_TYPE *structure);
00148 
00149 asn1_retCode asn1_delete_element(ASN1_TYPE structure,const char *element_name);
00150 
00151 asn1_retCode asn1_write_value(ASN1_TYPE element,const char *name,
00152                         const void *value,int len);
00153 
00154 asn1_retCode asn1_read_value(ASN1_TYPE element,const char *name,void *value,
00155                              int *len);
00156 
00157 asn1_retCode asn1_number_of_elements(ASN1_TYPE element,const char *name,int *num);
00158 
00159 asn1_retCode asn1_der_coding(ASN1_TYPE element,const char *name,
00160                void *der,int *len,char *ErrorDescription);
00161 
00162 asn1_retCode asn1_der_decoding(ASN1_TYPE *element,const void *der,int len,
00163                  char *errorDescription);
00164 
00165 asn1_retCode asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName,
00166              const void *der,int len,char *errorDescription);
00167 
00168 asn1_retCode asn1_der_decoding_startEnd(ASN1_TYPE element,const void *der,
00169                int len,const char *name,int *start, int *end);
00170 
00171 asn1_retCode asn1_expand_any_defined_by(ASN1_TYPE definitions,
00172                ASN1_TYPE *element);
00173 
00174 asn1_retCode asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
00175              const char *octetName,const char *objectName);
00176 
00177 asn1_retCode asn1_read_tag(node_asn *root,const char *name,int *tagValue, 
00178                      int *classValue);
00179 
00180 const char*  asn1_find_structure_from_oid(ASN1_TYPE definitions,
00181                 const char *oidValue);
00182 
00183 const char *asn1_check_version( const char *req_version );
00184 
00185 const char* libtasn1_strerror(asn1_retCode error);
00186 
00187 void libtasn1_perror(asn1_retCode error);
00188 
00189 #ifdef __cplusplus
00190 }
00191 #endif
00192 
00193 #endif /* LIBASN1_H */
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 

Generated by  Doxygen 1.5.1