diff options
author | Simon Josefsson <simon@josefsson.org> | 2009-05-12 09:11:09 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2009-05-12 09:11:09 +0200 |
commit | 2ce48b6bb14124e3581be465736d42f95cd81955 (patch) | |
tree | b729c5b81b3ef213c2e28ba5f1bbc241d55bdbff /lib/minitasn1 | |
parent | df1806cc2ef67622bf1b4df54b74f0adf857cc6c (diff) | |
download | gnutls-2ce48b6bb14124e3581be465736d42f95cd81955.tar.gz |
Upgrade libtasn1 to v2.1.
Diffstat (limited to 'lib/minitasn1')
-rw-r--r-- | lib/minitasn1/coding.c | 27 | ||||
-rw-r--r-- | lib/minitasn1/decoding.c | 105 | ||||
-rw-r--r-- | lib/minitasn1/element.c | 28 | ||||
-rw-r--r-- | lib/minitasn1/element.h | 9 | ||||
-rw-r--r-- | lib/minitasn1/errors.c | 11 | ||||
-rw-r--r-- | lib/minitasn1/gstr.c | 1 | ||||
-rw-r--r-- | lib/minitasn1/gstr.h | 4 | ||||
-rw-r--r-- | lib/minitasn1/int.h | 29 | ||||
-rw-r--r-- | lib/minitasn1/libtasn1.h | 99 | ||||
-rw-r--r-- | lib/minitasn1/parser_aux.c | 120 | ||||
-rw-r--r-- | lib/minitasn1/parser_aux.h | 60 | ||||
-rw-r--r-- | lib/minitasn1/structure.c | 17 | ||||
-rw-r--r-- | lib/minitasn1/structure.h | 12 |
13 files changed, 286 insertions, 236 deletions
diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c index 337858a3c5..ea0c7d9453 100644 --- a/lib/minitasn1/coding.c +++ b/lib/minitasn1/coding.c @@ -28,7 +28,6 @@ /*****************************************************/ #include <int.h> -#include <errors.h> #include "parser_aux.h" #include <gstr.h> #include "element.h" @@ -45,8 +44,8 @@ /* ErrorDescription: string returned. */ /* Return: */ /******************************************************/ -void -_asn1_error_description_value_not_found (ASN1_TYPE node, +static void +_asn1_error_description_value_not_found (ASN1_TYPE node, char *ErrorDescription) { @@ -113,7 +112,7 @@ asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len) /* (ans[0]..ans[ans_len-1]). */ /* Return: */ /******************************************************/ -void +static void _asn1_tag_der (unsigned char class, unsigned int tag_value, unsigned char *ans, int *ans_len) { @@ -179,7 +178,7 @@ asn1_octet_der (const unsigned char *str, int str_len, /* ASN1_MEM_ERROR when DER isn't big enough */ /* ASN1_SUCCESS otherwise */ /******************************************************/ -asn1_retCode +static asn1_retCode _asn1_time_der (unsigned char *str, unsigned char *der, int *der_len) { int len_len; @@ -250,7 +249,7 @@ _asn1_get_utctime_der(unsigned char *der,int *der_len,unsigned char *str) /* ASN1_MEM_ERROR when DER isn't big enough */ /* ASN1_SUCCESS otherwise */ /******************************************************/ -asn1_retCode +static asn1_retCode _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len) { int len_len, counter, k, first, max_len; @@ -370,8 +369,8 @@ asn1_bit_der (const unsigned char *str, int bit_len, /* ASN1_MEM_ERROR if der vector isn't big enough, */ /* otherwise ASN1_SUCCESS. */ /******************************************************/ -asn1_retCode -_asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der, +static asn1_retCode +_asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der, int *counter, int *max_len) { ASN1_TYPE p; @@ -443,8 +442,8 @@ _asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der, /* ASN1_MEM_ERROR if der vector isn't big enough, */ /* otherwise ASN1_SUCCESS. */ /******************************************************/ -asn1_retCode -_asn1_insert_tag_der (ASN1_TYPE node, unsigned char *der, int *counter, +static asn1_retCode +_asn1_insert_tag_der (ASN1_TYPE node, unsigned char *der, int *counter, int *max_len) { ASN1_TYPE p; @@ -604,8 +603,8 @@ _asn1_insert_tag_der (ASN1_TYPE node, unsigned char *der, int *counter, /* node: pointer to the SET element. */ /* Return: */ /******************************************************/ -void -_asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) +static void +_asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) { struct vet { @@ -718,8 +717,8 @@ _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) /* node: pointer to the SET OF element. */ /* Return: */ /******************************************************/ -void -_asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) +static void +_asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) { struct vet { diff --git a/lib/minitasn1/decoding.c b/lib/minitasn1/decoding.c index 2374cf80a0..d72a4c0397 100644 --- a/lib/minitasn1/decoding.c +++ b/lib/minitasn1/decoding.c @@ -27,7 +27,6 @@ /*****************************************************/ #include <int.h> -#include <errors.h> #include "parser_aux.h" #include <gstr.h> #include "structure.h" @@ -181,11 +180,11 @@ asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len) int ret; long err; - ret = asn1_get_length_der( ber, ber_len, len); + ret = asn1_get_length_der (ber, ber_len, len); if (ret == -1) - { /* indefinite length method */ + { /* indefinite length method */ ret = ber_len; - err = _asn1_get_indefinite_length_string (ber+1, &ret); + err = _asn1_get_indefinite_length_string (ber + 1, &ret); if (err != ASN1_SUCCESS) return -3; } @@ -237,7 +236,7 @@ asn1_get_octet_der (const unsigned char *der, int der_len, /* Returns ASN1_SUCCESS on success or an error code on error. */ -int +static int _asn1_get_time_der (const unsigned char *der, int der_len, int *ret_len, char *str, int str_size) { @@ -257,7 +256,7 @@ _asn1_get_time_der (const unsigned char *der, int der_len, int *ret_len, -void +static void _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len, char *str, int str_size) { @@ -340,7 +339,7 @@ asn1_get_bit_der (const unsigned char *der, int der_len, -int +static int _asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len, int *ret_len) { @@ -386,7 +385,7 @@ _asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len, &len2); if (len3 < 0) return ASN1_DER_ERROR; - + counter += len2; if (counter > der_len) return ASN1_DER_ERROR; @@ -539,7 +538,7 @@ _asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len, } -int +static int _asn1_delete_not_used (ASN1_TYPE node) { ASN1_TYPE p, p2; @@ -598,49 +597,53 @@ _asn1_delete_not_used (ASN1_TYPE node) return ASN1_SUCCESS; } -asn1_retCode _asn1_extract_der_octet(ASN1_TYPE node, const unsigned char *der, int der_len) +static asn1_retCode +_asn1_extract_der_octet (ASN1_TYPE node, const unsigned char *der, + int der_len) { -int len2, len3; -int counter2, counter_end; + int len2, len3; + int counter2, counter_end; - len2 = asn1_get_length_der (der, der_len, &len3); - if (len2 < -1) - return ASN1_DER_ERROR; + len2 = asn1_get_length_der (der, der_len, &len3); + if (len2 < -1) + return ASN1_DER_ERROR; - counter2 = len3 + 1; + counter2 = len3 + 1; - if (len2 == -1) - counter_end = der_len - 2; - else - counter_end = der_len; + if (len2 == -1) + counter_end = der_len - 2; + else + counter_end = der_len; - while (counter2 < counter_end) - { - len2 = asn1_get_length_der (der + counter2, der_len - counter2, &len3); + while (counter2 < counter_end) + { + len2 = asn1_get_length_der (der + counter2, der_len - counter2, &len3); - if (len2 < -1) - return ASN1_DER_ERROR; + if (len2 < -1) + return ASN1_DER_ERROR; - if (len2 > 0) - { - _asn1_append_value( node, der + counter2 + len3, len2); - } - else - { /* indefinite */ - - len2 = _asn1_extract_der_octet( node, der+counter2+len3, der_len-counter2-len3); - if (len2 < 0) - return len2; - } - - counter2 += len2 + len3 + 1; - } - - return ASN1_SUCCESS; + if (len2 > 0) + { + _asn1_append_value (node, der + counter2 + len3, len2); + } + else + { /* indefinite */ + + len2 = + _asn1_extract_der_octet (node, der + counter2 + len3, + der_len - counter2 - len3); + if (len2 < 0) + return len2; + } + + counter2 += len2 + len3 + 1; + } + + return ASN1_SUCCESS; } -asn1_retCode +static asn1_retCode _asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len) { int len2, len3, counter, tot_len, indefinite; @@ -692,17 +695,17 @@ _asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len) { unsigned char temp[DER_LEN]; int ret; - - len2 = sizeof(temp); + + len2 = sizeof (temp); asn1_length_der (tot_len, temp, &len2); _asn1_set_value (node, temp, len2); tot_len += len2; - ret = _asn1_extract_der_octet(node, der, *len); - if (ret!=ASN1_SUCCESS) - return ret; + ret = _asn1_extract_der_octet (node, der, *len); + if (ret != ASN1_SUCCESS) + return ret; } } @@ -1241,7 +1244,7 @@ asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len, if (len4 != -1) { len2 += len4; - _asn1_set_value_octet (p, der+counter, len2+len3); + _asn1_set_value_octet (p, der + counter, len2 + len3); counter += len2 + len3; } else @@ -1261,7 +1264,7 @@ asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len, return ris; } - _asn1_set_value_octet (p, der+counter, len2); + _asn1_set_value_octet (p, der + counter, len2); counter += len2; /* Check if a couple of 0x00 are present due to an EXPLICIT TAG with @@ -1907,7 +1910,7 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, len2 += len4; if (state == FOUND) { - _asn1_set_value_octet (p, der+counter, len2+len3); + _asn1_set_value_octet (p, der + counter, len2 + len3); temp2 = NULL; if (p == nodeFound) @@ -1934,7 +1937,7 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, if (state == FOUND) { - _asn1_set_value_octet (p, der+counter, len2); + _asn1_set_value_octet (p, der + counter, len2); if (p == nodeFound) state = EXIT; diff --git a/lib/minitasn1/element.c b/lib/minitasn1/element.c index 34863781ad..4b4c8384f1 100644 --- a/lib/minitasn1/element.c +++ b/lib/minitasn1/element.c @@ -28,13 +28,14 @@ #include <int.h> -#include <errors.h> #include "parser_aux.h" #include <gstr.h> #include "structure.h" +#include "element.h" + void -_asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size) +_asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size) { ASN1_TYPE p; char tmp_name[64]; @@ -115,21 +116,19 @@ _asn1_convert_integer (const char *value, unsigned char *value_out, for (k2 = k; k2 < SIZEOF_UNSIGNED_LONG_INT; k2++) value_out[k2 - k] = val[k2]; - -#ifdef LIBTASN1_DEBUG_INTEGER - _libtasn1_log ("_asn1_convert_integer: valueIn=%s, lenOut=%d", value, *len); +#if 0 + printf ("_asn1_convert_integer: valueIn=%s, lenOut=%d", value, *len); for (k = 0; k < SIZEOF_UNSIGNED_LONG_INT; k++) - _libtasn1_log (", vOut[%d]=%d", k, value_out[k]); - _libtasn1_log ("\n"); + printf (", vOut[%d]=%d", k, value_out[k]); + printf ("\n"); #endif - return ASN1_SUCCESS; } int -_asn1_append_sequence_set (ASN1_TYPE node) +_asn1_append_sequence_set (ASN1_TYPE node) { ASN1_TYPE p, p2; char temp[10]; @@ -281,6 +280,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, ASN1_TYPE node, p, p2; unsigned char *temp, *value_temp = NULL, *default_temp = NULL; int len2, k, k2, negative; + size_t i; const unsigned char *value = ivalue; node = asn1_find_node (node_root, name); @@ -417,7 +417,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, (!negative && (value_temp[k] & 0x80))) k--; - _asn1_set_value_octet (node, value_temp+k, len-k); + _asn1_set_value_octet (node, value_temp + k, len - k); if (node->type & CONST_DEFAULT) { @@ -492,8 +492,8 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, _asn1_free (value_temp); break; case TYPE_OBJECT_ID: - for (k = 0; k < strlen (value); k++) - if ((!isdigit (value[k])) && (value[k] != '.') && (value[k] != '+')) + for (i = 0; i < strlen (value); i++) + if ((!isdigit (value[i])) && (value[i] != '.') && (value[i] != '+')) return ASN1_VALUE_NOT_VALID; if (node->type & CONST_DEFAULT) { @@ -636,8 +636,8 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, } #define ADD_STR_VALUE( ptr, ptr_size, data) \ - *len = strlen(data) + 1; \ - if (ptr_size < strlen(ptr)+(*len)) { \ + *len = (int) strlen(data) + 1; \ + if (ptr_size < (int) strlen(ptr)+(*len)) { \ return ASN1_MEM_ERROR; \ } else { \ /* this strcat is checked */ \ diff --git a/lib/minitasn1/element.h b/lib/minitasn1/element.h index f0314d27a6..b5d9eb9e55 100644 --- a/lib/minitasn1/element.h +++ b/lib/minitasn1/element.h @@ -3,11 +3,12 @@ #define _ELEMENT_H -asn1_retCode _asn1_append_sequence_set(ASN1_TYPE node); +asn1_retCode _asn1_append_sequence_set (ASN1_TYPE node); -asn1_retCode _asn1_convert_integer(const char *value,unsigned char *value_out, - int value_out_size, int *len); +asn1_retCode _asn1_convert_integer (const char *value, + unsigned char *value_out, + int value_out_size, int *len); -void _asn1_hierarchical_name(ASN1_TYPE node,char *name,int name_size); +void _asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size); #endif diff --git a/lib/minitasn1/errors.c b/lib/minitasn1/errors.c index e8f557f99c..1e46c8c543 100644 --- a/lib/minitasn1/errors.c +++ b/lib/minitasn1/errors.c @@ -21,7 +21,6 @@ */ #include <int.h> -#include "errors.h" #ifdef STDC_HEADERS # include <stdarg.h> #endif @@ -54,16 +53,18 @@ static const libtasn1_error_entry error_algorithms[] = { LIBTASN1_ERROR_ENTRY (ASN1_NAME_TOO_LONG), LIBTASN1_ERROR_ENTRY (ASN1_ARRAY_ERROR), LIBTASN1_ERROR_ENTRY (ASN1_ELEMENT_NOT_EMPTY), - {0} + {0, 0} }; /** * asn1_perror - prints a string to stderr with a description of an error * @error: is an error returned by a libtasn1 function. * - * This function is like perror(). The only difference is that it + * This function is like perror(). The only difference is that it * accepts an error returned by a libtasn1 function. * + * This function replaces libtasn1_perror() in older libtasn1. + * * Since: 1.6 **/ void @@ -77,9 +78,11 @@ asn1_perror (asn1_retCode error) * asn1_strerror - Returns a string with a description of an error * @error: is an error returned by a libtasn1 function. * - * This function is similar to strerror(). The only difference is + * This function is similar to strerror(). The only difference is * that it accepts an error (number) returned by a libtasn1 function. * + * This function replaces libtasn1_strerror() in older libtasn1. + * * Returns: Pointer to static zero-terminated string describing error * code. * diff --git a/lib/minitasn1/gstr.c b/lib/minitasn1/gstr.c index cdfa7edecb..9c0835120b 100644 --- a/lib/minitasn1/gstr.c +++ b/lib/minitasn1/gstr.c @@ -21,6 +21,7 @@ */ #include <int.h> +#include "gstr.h" /* These function are like strcat, strcpy. They only * do bounds checking (they shouldn't cause buffer overruns), diff --git a/lib/minitasn1/gstr.h b/lib/minitasn1/gstr.h index 992fd0ff3d..5452fa4683 100644 --- a/lib/minitasn1/gstr.h +++ b/lib/minitasn1/gstr.h @@ -1,5 +1,5 @@ -void _asn1_str_cpy( char* dest, size_t dest_tot_size, const char* src); -void _asn1_str_cat( char* dest, size_t dest_tot_size, const char* src); +void _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src); +void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src); #define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) #define Estrcat(x,y) _asn1_str_cat(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) diff --git a/lib/minitasn1/int.h b/lib/minitasn1/int.h index 8ef03bd9b4..5b42af5344 100644 --- a/lib/minitasn1/int.h +++ b/lib/minitasn1/int.h @@ -39,11 +39,24 @@ #include <libtasn1.h> -/* -#define LIBTASN1_DEBUG -#define LIBTASN1_DEBUG_PARSER -#define LIBTASN1_DEBUG_INTEGER -*/ +#define ASN1_SMALL_VALUE_SIZE 16 + +/* This structure is also in libtasn1.h, but then contains less + fields. You cannot make any modifications to these first fields + without breaking ABI. */ +struct node_asn_struct +{ + /* public fields: */ + char *name; /* Node name */ + unsigned int type; /* Node type */ + unsigned char *value; /* Node value */ + int value_len; + ASN1_TYPE down; /* Pointer to the son node */ + ASN1_TYPE right; /* Pointer to the brother node */ + ASN1_TYPE left; /* Pointer to the next list element */ + /* private fields: */ + unsigned char small_value[ASN1_SMALL_VALUE_SIZE]; /* For small values */ +}; #define _asn1_malloc malloc #define _asn1_free free @@ -51,7 +64,7 @@ #define _asn1_realloc realloc #define _asn1_strdup strdup -#define MAX_LOG_SIZE 1024 /* maximum number of characters of a log message */ +#define MAX_LOG_SIZE 1024 /* maximum number of characters of a log message */ /* Define used for visiting trees. */ #define UP 1 @@ -99,13 +112,13 @@ #define CONST_EXPLICIT (1<<11) #define CONST_IMPLICIT (1<<12) -#define CONST_TAG (1<<13) /* Used in ASN.1 assignement */ +#define CONST_TAG (1<<13) /* Used in ASN.1 assignement */ #define CONST_OPTION (1<<14) #define CONST_DEFAULT (1<<15) #define CONST_TRUE (1<<16) #define CONST_FALSE (1<<17) -#define CONST_LIST (1<<18) /* Used with TYPE_INTEGER and TYPE_BIT_STRING */ +#define CONST_LIST (1<<18) /* Used with TYPE_INTEGER and TYPE_BIT_STRING */ #define CONST_MIN_MAX (1<<19) #define CONST_1_PARAM (1<<20) diff --git a/lib/minitasn1/libtasn1.h b/lib/minitasn1/libtasn1.h index b8ad75b167..5e30e33db9 100644 --- a/lib/minitasn1/libtasn1.h +++ b/lib/minitasn1/libtasn1.h @@ -24,15 +24,28 @@ #ifndef LIBTASN1_H # define LIBTASN1_H +# ifndef ASN1_API +# if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY +# define ASN1_API __attribute__((__visibility__("default"))) +# elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC +# define ASN1_API __declspec(dllexport) +# elif defined _MSC_VER && ! defined ASN1_STATIC +# define ASN1_API __declspec(dllimport) +# else +# define ASN1_API +# endif +# endif + #include <stdio.h> /* for FILE* */ #include <sys/types.h> #include <time.h> #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -#define ASN1_VERSION "1.8" +#define ASN1_VERSION "2.1" typedef int asn1_retCode; /* type returned by libtasn1 functions */ @@ -96,6 +109,10 @@ extern "C" { /* that represent an ASN.1 DEFINITION. */ /******************************************************/ +#if !defined(ASN1_BUILDING) + /* This structure is also in internal.h, but then contains more + fields. You cannot make any modifications to these fields + without breaking ABI. */ struct node_asn_struct { char *name; /* Node name */ @@ -106,6 +123,7 @@ extern "C" { struct node_asn_struct *right; /* Pointer to the brother node */ struct node_asn_struct *left; /* Pointer to the next list element */ }; +#endif typedef struct node_asn_struct node_asn; @@ -118,9 +136,9 @@ extern "C" { /*****************************************/ struct static_struct_asn { - const char *name; /* Node name */ - unsigned int type; /* Node type */ - const void *value; /* Node value */ + const char *name; /* Node name */ + unsigned int type; /* Node type */ + const void *value; /* Node value */ }; typedef struct static_struct_asn ASN1_ARRAY_TYPE; @@ -143,107 +161,108 @@ extern "C" { asn1_retCode asn1_parser2tree (const char *file_name, ASN1_TYPE * definitions, - char *errorDescription); + char *errorDescription) ASN1_API; asn1_retCode asn1_parser2array (const char *inputFileName, const char *outputFileName, const char *vectorName, - char *errorDescription); + char *errorDescription) ASN1_API; asn1_retCode asn1_array2tree (const ASN1_ARRAY_TYPE * array, ASN1_TYPE * definitions, - char *errorDescription); + char *errorDescription) ASN1_API; - void asn1_print_structure (FILE *out, ASN1_TYPE structure, const char *name, - int mode); + void asn1_print_structure (FILE * out, ASN1_TYPE structure, + const char *name, int mode) ASN1_API; asn1_retCode asn1_create_element (ASN1_TYPE definitions, const char *source_name, - ASN1_TYPE * element); + ASN1_TYPE * element) ASN1_API; - asn1_retCode asn1_delete_structure (ASN1_TYPE * structure); + asn1_retCode asn1_delete_structure (ASN1_TYPE * structure) ASN1_API; asn1_retCode asn1_delete_element (ASN1_TYPE structure, - const char *element_name); + const char *element_name) ASN1_API; asn1_retCode asn1_write_value (ASN1_TYPE node_root, const char *name, - const void *ivalue, int len); + const void *ivalue, int len) ASN1_API; asn1_retCode asn1_read_value (ASN1_TYPE root, const char *name, - void *ivalue, int *len); + void *ivalue, int *len) ASN1_API; asn1_retCode asn1_number_of_elements (ASN1_TYPE element, const char *name, - int *num); + int *num) ASN1_API; asn1_retCode asn1_der_coding (ASN1_TYPE element, const char *name, - void *ider, int *len, char *ErrorDescription); + void *ider, int *len, + char *ErrorDescription) ASN1_API; asn1_retCode asn1_der_decoding (ASN1_TYPE * element, const void *ider, - int len, char *errorDescription); + int len, char *errorDescription) ASN1_API; asn1_retCode asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, const void *ider, int len, - char *errorDescription); + char *errorDescription) ASN1_API; asn1_retCode asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, const char *name_element, - int *start, int *end); + int *start, int *end) ASN1_API; asn1_retCode asn1_expand_any_defined_by (ASN1_TYPE definitions, - ASN1_TYPE * element); + ASN1_TYPE * element) ASN1_API; asn1_retCode asn1_expand_octet_string (ASN1_TYPE definitions, ASN1_TYPE * element, const char *octetName, - const char *objectName); + const char *objectName) ASN1_API; asn1_retCode asn1_read_tag (ASN1_TYPE root, const char *name, - int *tagValue, int *classValue); + int *tagValue, int *classValue) ASN1_API; const char *asn1_find_structure_from_oid (ASN1_TYPE definitions, - const char *oidValue); + const char *oidValue) ASN1_API; - const char *asn1_check_version (const char *req_version); + const char *asn1_check_version (const char *req_version) ASN1_API; - const char *asn1_strerror (asn1_retCode error); - void asn1_perror (asn1_retCode error); + const char *asn1_strerror (asn1_retCode error) ASN1_API; + void asn1_perror (asn1_retCode error) ASN1_API; /* DER utility functions. */ int asn1_get_tag_der (const unsigned char *der, int der_len, - unsigned char *cls, int *len, unsigned long *tag); + unsigned char *cls, int *len, + unsigned long *tag) ASN1_API; void asn1_octet_der (const unsigned char *str, int str_len, - unsigned char *der, int *der_len); + unsigned char *der, int *der_len) ASN1_API; asn1_retCode asn1_get_octet_der (const unsigned char *der, int der_len, int *ret_len, unsigned char *str, - int str_size, int *str_len); + int str_size, int *str_len) ASN1_API; void asn1_bit_der (const unsigned char *str, int bit_len, - unsigned char *der, int *der_len); + unsigned char *der, int *der_len) ASN1_API; asn1_retCode asn1_get_bit_der (const unsigned char *der, int der_len, int *ret_len, unsigned char *str, - int str_size, int *bit_len); + int str_size, int *bit_len) ASN1_API; signed long asn1_get_length_der (const unsigned char *der, int der_len, - int *len); + int *len) ASN1_API; signed long asn1_get_length_ber (const unsigned char *ber, int ber_len, - int *len); + int *len) ASN1_API; void asn1_length_der (unsigned long int len, unsigned char *ans, - int *ans_len); + int *ans_len) ASN1_API; /* Other utility functions. */ - ASN1_TYPE asn1_find_node (ASN1_TYPE pointer, const char *name); + ASN1_TYPE asn1_find_node (ASN1_TYPE pointer, const char *name) ASN1_API; asn1_retCode asn1_copy_node (ASN1_TYPE dst, const char *dst_name, - ASN1_TYPE src, const char *src_name); - + ASN1_TYPE src, const char *src_name) ASN1_API; /* Deprecated stuff. */ @@ -268,11 +287,11 @@ extern "C" { /* Use asn1_strerror instead. */ const char *libtasn1_strerror (asn1_retCode error) - __attribute__ ((deprecated)); + __attribute__ ((deprecated)) ASN1_API; /* Use asn1_perror instead. */ void libtasn1_perror (asn1_retCode error) - __attribute__ ((deprecated)); + __attribute__ ((deprecated)) ASN1_API; #endif diff --git a/lib/minitasn1/parser_aux.c b/lib/minitasn1/parser_aux.c index 1c71f425f5..554551dc28 100644 --- a/lib/minitasn1/parser_aux.c +++ b/lib/minitasn1/parser_aux.c @@ -21,7 +21,6 @@ */ #include <int.h> -#include <errors.h> #include "parser_aux.h" #include "gstr.h" #include "structure.h" @@ -198,14 +197,15 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) /* len: character number of value. */ /* Return: pointer to the NODE_ASN element. */ /******************************************************************/ -ASN1_TYPE -_asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) +ASN1_TYPE +_asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) { if (node == NULL) return node; if (node->value) { - _asn1_free (node->value); + if (node->value != node->small_value) + _asn1_free (node->value); node->value = NULL; node->value_len = 0; } @@ -213,9 +213,16 @@ _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) if (!len) return node; - node->value = (unsigned char *) _asn1_malloc (len); - if (node->value == NULL) - return NULL; + if (len < sizeof (node->small_value)) + { + node->value = node->small_value; + } + else + { + node->value = _asn1_malloc (len); + if (node->value == NULL) + return NULL; + } node->value_len = len; memcpy (node->value, value, len); @@ -226,18 +233,18 @@ _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) /* Function : _asn1_set_value_octet */ /* Description: sets the field VALUE in a NODE_ASN element. The */ /* previous value (if exist) will be lost. The value */ -/* given is stored as an octet string. */ +/* given is stored as an octet string. */ /* Parameters: */ /* node: element pointer. */ /* value: pointer to the value that you want to set. */ /* len: character number of value. */ /* Return: pointer to the NODE_ASN element. */ /******************************************************************/ -ASN1_TYPE -_asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len) +ASN1_TYPE +_asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len) { -int len2; -void* temp; + int len2; + void *temp; if (node == NULL) return node; @@ -254,15 +261,16 @@ void* temp; /* the same as _asn1_set_value except that it sets an already malloc'ed * value. */ -ASN1_TYPE -_asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len) +ASN1_TYPE +_asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len) { if (node == NULL) return node; if (node->value) { - _asn1_free (node->value); + if (node->value != node->small_value) + _asn1_free (node->value); node->value = NULL; node->value_len = 0; } @@ -279,33 +287,51 @@ _asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len) /******************************************************************/ /* Function : _asn1_append_value */ /* Description: appends to the field VALUE in a NODE_ASN element. */ -/* */ +/* */ /* Parameters: */ /* node: element pointer. */ /* value: pointer to the value that you want to be appended. */ /* len: character number of value. */ /* Return: pointer to the NODE_ASN element. */ /******************************************************************/ -ASN1_TYPE -_asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) +ASN1_TYPE +_asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) { if (node == NULL) return node; - if (node->value != NULL) /* value is allocated */ + if (node->value != NULL && node->value != node->small_value) { + /* value is allocated */ int prev_len = node->value_len; - node->value_len+=len; - node->value = _asn1_realloc( node->value, node->value_len); - if (node->value == NULL) { - node->value_len = 0; - return NULL; - } - memcpy( &node->value[prev_len], value, len); + node->value_len += len; + node->value = _asn1_realloc (node->value, node->value_len); + if (node->value == NULL) + { + node->value_len = 0; + return NULL; + } + memcpy (&node->value[prev_len], value, len); return node; } - else /* node->value == NULL */ - return _asn1_set_value(node, value, len); + else if (node->value == node->small_value) + { + /* value is in node */ + int prev_len = node->value_len; + node->value_len += len; + node->value = _asn1_malloc (node->value_len); + if (node->value == NULL) + { + node->value_len = 0; + return NULL; + } + memcpy (node->value, node->small_value, prev_len); + memcpy (&node->value[prev_len], value, len); + + return node; + } + else /* node->value == NULL */ + return _asn1_set_value (node, value, len); } /******************************************************************/ @@ -318,8 +344,8 @@ _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) /* to set. */ /* Return: pointer to the NODE_ASN element. */ /******************************************************************/ -ASN1_TYPE -_asn1_set_name (ASN1_TYPE node, const char *name) +ASN1_TYPE +_asn1_set_name (ASN1_TYPE node, const char *name) { if (node == NULL) return node; @@ -353,8 +379,8 @@ _asn1_set_name (ASN1_TYPE node, const char *name) /* by NODE. */ /* Return: pointer to *NODE. */ /******************************************************************/ -ASN1_TYPE -_asn1_set_right (ASN1_TYPE node, ASN1_TYPE right) +ASN1_TYPE +_asn1_set_right (ASN1_TYPE node, ASN1_TYPE right) { if (node == NULL) return node; @@ -372,8 +398,8 @@ _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right) /* node: NODE_ASN element pointer. */ /* Return: field RIGHT of NODE. */ /******************************************************************/ -ASN1_TYPE -_asn1_get_right (ASN1_TYPE node) +ASN1_TYPE +_asn1_get_right (ASN1_TYPE node) { if (node == NULL) return NULL; @@ -387,8 +413,8 @@ _asn1_get_right (ASN1_TYPE node) /* node: starting element pointer. */ /* Return: pointer to the last element along the right chain. */ /******************************************************************/ -ASN1_TYPE -_asn1_get_last_right (ASN1_TYPE node) +ASN1_TYPE +_asn1_get_last_right (ASN1_TYPE node) { ASN1_TYPE p; @@ -409,8 +435,8 @@ _asn1_get_last_right (ASN1_TYPE node) /* by NODE. */ /* Return: pointer to *NODE. */ /******************************************************************/ -ASN1_TYPE -_asn1_set_down (ASN1_TYPE node, ASN1_TYPE down) +ASN1_TYPE +_asn1_set_down (ASN1_TYPE node, ASN1_TYPE down) { if (node == NULL) return node; @@ -428,8 +454,8 @@ _asn1_set_down (ASN1_TYPE node, ASN1_TYPE down) /* node: NODE_ASN element pointer. */ /* Return: field DOWN of NODE. */ /******************************************************************/ -ASN1_TYPE -_asn1_get_down (ASN1_TYPE node) +ASN1_TYPE +_asn1_get_down (ASN1_TYPE node) { if (node == NULL) return NULL; @@ -444,7 +470,7 @@ _asn1_get_down (ASN1_TYPE node) /* Return: a null terminated string. */ /******************************************************************/ char * -_asn1_get_name (ASN1_TYPE node) +_asn1_get_name (ASN1_TYPE node) { if (node == NULL) return NULL; @@ -462,8 +488,8 @@ _asn1_get_name (ASN1_TYPE node) /* value of field TYPE. */ /* Return: NODE pointer. */ /******************************************************************/ -ASN1_TYPE -_asn1_mod_type (ASN1_TYPE node, unsigned int value) +ASN1_TYPE +_asn1_mod_type (ASN1_TYPE node, unsigned int value) { if (node == NULL) return node; @@ -480,14 +506,14 @@ _asn1_mod_type (ASN1_TYPE node, unsigned int value) /* node: NODE_ASN element pointer. */ /******************************************************************/ void -_asn1_remove_node (ASN1_TYPE node) +_asn1_remove_node (ASN1_TYPE node) { if (node == NULL) return; if (node->name != NULL) _asn1_free (node->name); - if (node->value != NULL) + if (node->value != NULL && node->value != node->small_value) _asn1_free (node->value); _asn1_free (node); } @@ -499,8 +525,8 @@ _asn1_remove_node (ASN1_TYPE node) /* node: NODE_ASN element pointer. */ /* Return: Null if not found. */ /******************************************************************/ -ASN1_TYPE -_asn1_find_up (ASN1_TYPE node) +ASN1_TYPE +_asn1_find_up (ASN1_TYPE node) { ASN1_TYPE p; diff --git a/lib/minitasn1/parser_aux.h b/lib/minitasn1/parser_aux.h index d30a34ca97..564f64ecf6 100644 --- a/lib/minitasn1/parser_aux.h +++ b/lib/minitasn1/parser_aux.h @@ -7,67 +7,53 @@ /***************************************/ /* Functions used by ASN.1 parser */ /***************************************/ -ASN1_TYPE -_asn1_add_node(unsigned int type); +ASN1_TYPE _asn1_add_node (unsigned int type); ASN1_TYPE -_asn1_set_value(ASN1_TYPE node,const void *value,unsigned int len); +_asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len); -ASN1_TYPE -_asn1_set_value_m(ASN1_TYPE node,void *value,unsigned int len); +ASN1_TYPE _asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len); ASN1_TYPE -_asn1_set_value_octet(ASN1_TYPE node,const void *value,unsigned int len); +_asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len); ASN1_TYPE -_asn1_append_value(ASN1_TYPE node,const void *value,unsigned int len); +_asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len); -ASN1_TYPE -_asn1_set_name(ASN1_TYPE node,const char *name); +ASN1_TYPE _asn1_set_name (ASN1_TYPE node, const char *name); -ASN1_TYPE -_asn1_set_right(ASN1_TYPE node, ASN1_TYPE right); +ASN1_TYPE _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right); -ASN1_TYPE -_asn1_get_right(ASN1_TYPE node); +ASN1_TYPE _asn1_get_right (ASN1_TYPE node); -ASN1_TYPE -_asn1_get_last_right(ASN1_TYPE node); +ASN1_TYPE _asn1_get_last_right (ASN1_TYPE node); -ASN1_TYPE -_asn1_set_down(ASN1_TYPE node, ASN1_TYPE down); +ASN1_TYPE _asn1_set_down (ASN1_TYPE node, ASN1_TYPE down); -char * -_asn1_get_name(ASN1_TYPE node); +char *_asn1_get_name (ASN1_TYPE node); -ASN1_TYPE -_asn1_get_down(ASN1_TYPE node); +ASN1_TYPE _asn1_get_down (ASN1_TYPE node); -ASN1_TYPE -_asn1_mod_type(ASN1_TYPE node,unsigned int value); +ASN1_TYPE _asn1_mod_type (ASN1_TYPE node, unsigned int value); -void -_asn1_remove_node(ASN1_TYPE node); +void _asn1_remove_node (ASN1_TYPE node); -void _asn1_delete_list(void); +void _asn1_delete_list (void); -void _asn1_delete_list_and_nodes(void); +void _asn1_delete_list_and_nodes (void); -char * _asn1_ltostr(long v,char *str); +char *_asn1_ltostr (long v, char *str); -ASN1_TYPE _asn1_find_up(ASN1_TYPE node); +ASN1_TYPE _asn1_find_up (ASN1_TYPE node); -asn1_retCode _asn1_change_integer_value(ASN1_TYPE node); +asn1_retCode _asn1_change_integer_value (ASN1_TYPE node); -asn1_retCode _asn1_expand_object_id(ASN1_TYPE node); +asn1_retCode _asn1_expand_object_id (ASN1_TYPE node); -asn1_retCode _asn1_type_set_config(ASN1_TYPE node); +asn1_retCode _asn1_type_set_config (ASN1_TYPE node); -asn1_retCode _asn1_check_identifier(ASN1_TYPE node); +asn1_retCode _asn1_check_identifier (ASN1_TYPE node); -asn1_retCode _asn1_set_default_tag(ASN1_TYPE node); +asn1_retCode _asn1_set_default_tag (ASN1_TYPE node); #endif - - - diff --git a/lib/minitasn1/structure.c b/lib/minitasn1/structure.c index 4998fb2e5e..39316516df 100644 --- a/lib/minitasn1/structure.c +++ b/lib/minitasn1/structure.c @@ -29,7 +29,6 @@ #include <int.h> -#include <errors.h> #include <structure.h> #include "parser_aux.h" #include <gstr.h> @@ -70,7 +69,7 @@ _asn1_add_node_only (unsigned int type) /* Return: NULL if not found. */ /******************************************************************/ ASN1_TYPE -_asn1_find_left (ASN1_TYPE node) +_asn1_find_left (ASN1_TYPE node) { if ((node == NULL) || (node->left == NULL) || (node->left->down == node)) return NULL; @@ -387,7 +386,7 @@ asn1_delete_element (ASN1_TYPE structure, const char *element_name) } ASN1_TYPE -_asn1_copy_structure3 (ASN1_TYPE source_node) +_asn1_copy_structure3 (ASN1_TYPE source_node) { ASN1_TYPE dest_node, p_s, p_d, p_d_prev; int move; @@ -409,7 +408,7 @@ _asn1_copy_structure3 (ASN1_TYPE source_node) if (p_s->name) _asn1_set_name (p_d, p_s->name); if (p_s->value) - _asn1_set_value (p_d, p_s->value, p_s->value_len); + _asn1_set_value (p_d, p_s->value, p_s->value_len); move = DOWN; } else @@ -456,7 +455,7 @@ _asn1_copy_structure3 (ASN1_TYPE source_node) static ASN1_TYPE -_asn1_copy_structure2 (ASN1_TYPE root, const char *source_name) +_asn1_copy_structure2 (ASN1_TYPE root, const char *source_name) { ASN1_TYPE source_node; @@ -467,8 +466,8 @@ _asn1_copy_structure2 (ASN1_TYPE root, const char *source_name) } -asn1_retCode -_asn1_type_choice_config (ASN1_TYPE node) +static asn1_retCode +_asn1_type_choice_config (ASN1_TYPE node) { ASN1_TYPE p, p2, p3, p4; int move, tlen; @@ -552,8 +551,8 @@ _asn1_type_choice_config (ASN1_TYPE node) } -asn1_retCode -_asn1_expand_identifier (ASN1_TYPE * node, ASN1_TYPE root) +static asn1_retCode +_asn1_expand_identifier (ASN1_TYPE * node, ASN1_TYPE root) { ASN1_TYPE p, p2, p3; char name2[ASN1_MAX_NAME_SIZE + 2]; diff --git a/lib/minitasn1/structure.h b/lib/minitasn1/structure.h index 1803e7ab04..7257986ba0 100644 --- a/lib/minitasn1/structure.h +++ b/lib/minitasn1/structure.h @@ -8,14 +8,14 @@ #ifndef _STRUCTURE_H #define _STRUCTURE_H -asn1_retCode _asn1_create_static_structure(ASN1_TYPE pointer, - char* output_file_name,char *vector_name); +asn1_retCode _asn1_create_static_structure (ASN1_TYPE pointer, + char *output_file_name, + char *vector_name); -ASN1_TYPE _asn1_copy_structure3(ASN1_TYPE source_node); +ASN1_TYPE _asn1_copy_structure3 (ASN1_TYPE source_node); -ASN1_TYPE _asn1_add_node_only(unsigned int type); +ASN1_TYPE _asn1_add_node_only (unsigned int type); -ASN1_TYPE _asn1_find_left(ASN1_TYPE node); +ASN1_TYPE _asn1_find_left (ASN1_TYPE node); #endif - |