From 50c0a347a98616a0a977d9aa4cce048ede278083 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Wed, 21 Apr 2010 23:24:09 +0200 Subject: Upgrade to libtasn1 version 2.6. --- lib/minitasn1/Makefile.am | 2 +- lib/minitasn1/coding.c | 2 +- lib/minitasn1/decoding.c | 124 ++++++++---------------- lib/minitasn1/element.h | 21 ++++ lib/minitasn1/gstr.h | 22 +++++ lib/minitasn1/libtasn1.h | 234 +++++++++++++++++++++------------------------ lib/minitasn1/parser_aux.c | 97 +------------------ lib/minitasn1/parser_aux.h | 21 ++++ lib/minitasn1/structure.h | 21 ++++ lib/minitasn1/version.c | 52 ++++++++++ 10 files changed, 295 insertions(+), 301 deletions(-) create mode 100644 lib/minitasn1/version.c (limited to 'lib/minitasn1') diff --git a/lib/minitasn1/Makefile.am b/lib/minitasn1/Makefile.am index 9490d82235..2d43be2083 100644 --- a/lib/minitasn1/Makefile.am +++ b/lib/minitasn1/Makefile.am @@ -30,4 +30,4 @@ noinst_LTLIBRARIES = libminitasn1.la libminitasn1_la_SOURCES = libtasn1.h gstr.h int.h parser_aux.h \ structure.h element.h decoding.c gstr.c errors.c parser_aux.c \ - structure.c element.c coding.c + structure.c element.c coding.c version.c diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c index 9a28b12947..31b5ebb176 100644 --- a/lib/minitasn1/coding.c +++ b/lib/minitasn1/coding.c @@ -384,7 +384,7 @@ _asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der, p = node->down; /* When there are nested tags we must complete them reverse to the order they were created. This is because completing a tag - modifies all data within it, including the incomplete tags + modifies all data within it, including the incomplete tags which store buffer positions -- simon@josefsson.org 2002-09-06 */ while (p->right) diff --git a/lib/minitasn1/decoding.c b/lib/minitasn1/decoding.c index 648911a4b2..8c8b01fd32 100644 --- a/lib/minitasn1/decoding.c +++ b/lib/minitasn1/decoding.c @@ -54,7 +54,7 @@ _asn1_error_description_tag_error (ASN1_TYPE node, char *ErrorDescription) * * Extract a length field from DER data. * - * Return value: Return the decoded length value, or -1 on indefinite + * Returns: Return the decoded length value, or -1 on indefinite * length, or -2 when the value was too big. **/ signed long @@ -101,7 +101,6 @@ asn1_get_length_der (const unsigned char *der, int der_len, int *len) } } - /** * asn1_get_tag_der: * @der: DER data to decode. @@ -112,7 +111,7 @@ asn1_get_length_der (const unsigned char *der, int der_len, int *len) * * Decode the class and TAG from DER code. * - * Return value: Returns %ASN1_SUCCESS on success, or an error. + * Returns: Returns %ASN1_SUCCESS on success, or an error. **/ int asn1_get_tag_der (const unsigned char *der, int der_len, @@ -169,8 +168,8 @@ asn1_get_tag_der (const unsigned char *der, int der_len, * asn1_get_length_der() is that this function will return a length * even if the value has indefinite encoding. * - * Return value: Return the decoded length value, or negative value - * when the value was too big. + * Returns: Return the decoded length value, or negative value when + * the value was too big. * * Since: 2.0 **/ @@ -203,7 +202,7 @@ asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len) * * Extract an OCTET SEQUENCE from DER data. * - * Return value: Returns %ASN1_SUCCESS on success, or an error. + * Returns: Returns %ASN1_SUCCESS on success, or an error. **/ int asn1_get_octet_der (const unsigned char *der, int der_len, @@ -232,8 +231,6 @@ asn1_get_octet_der (const unsigned char *der, int der_len, return ASN1_SUCCESS; } - - /* Returns ASN1_SUCCESS on success or an error code on error. */ static int @@ -254,8 +251,6 @@ _asn1_get_time_der (const unsigned char *der, int der_len, int *ret_len, return ASN1_SUCCESS; } - - static int _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len, char *str, int str_size) @@ -288,8 +283,6 @@ _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len, leading = 1; for (k = 1; k < len; k++) { - - /* X.690 mandates that the leading byte must never be 0x80 */ if (leading != 0 && der[len_len + k] == 0x80) @@ -330,7 +323,7 @@ _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len, * * Extract a BIT SEQUENCE from DER data. * - * Return value: Return %ASN1_SUCCESS on success, or an error. + * Returns: Return %ASN1_SUCCESS on success, or an error. **/ int asn1_get_bit_der (const unsigned char *der, int der_len, @@ -358,9 +351,6 @@ asn1_get_bit_der (const unsigned char *der, int der_len, return ASN1_SUCCESS; } - - - static int _asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len, int *ret_len) @@ -559,7 +549,6 @@ _asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len, return ASN1_SUCCESS; } - static int _asn1_delete_not_used (ASN1_TYPE node) { @@ -664,7 +653,6 @@ _asn1_extract_der_octet (ASN1_TYPE node, const unsigned char *der, return ASN1_SUCCESS; } - static asn1_retCode _asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len) { @@ -798,7 +786,6 @@ _asn1_get_indefinite_length_string (const unsigned char *der, int *len) } - /** * asn1_der_decoding: * @element: pointer to an ASN1 structure. @@ -807,20 +794,16 @@ _asn1_get_indefinite_length_string (const unsigned char *der, int *len) * @errorDescription: null-terminated string contains details when an * error occurred. * - * Fill the structure *ELEMENT with values of a DER encoding + * Fill the structure *@ELEMENT with values of a DER encoding * string. The structure must just be created with function - * 'asn1_create_element'. If an error occurs during the decoding - * procedure, the *ELEMENT is deleted and set equal to + * asn1_create_element(). If an error occurs during the decoding + * procedure, the *@ELEMENT is deleted and set equal to * %ASN1_TYPE_EMPTY. * - * Returns: - * - * %ASN1_SUCCESS: DER encoding OK. - * - * %ASN1_ELEMENT_NOT_FOUND: ELEMENT is ASN1_TYPE_EMPTY. - * - * %ASN1_TAG_ERROR,ASN1_DER_ERROR: The der encoding doesn't match - * the structure NAME. *ELEMENT deleted. + * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND + * if @ELEMENT is %ASN1_TYPE_EMPTY, and %ASN1_TAG_ERROR or + * %ASN1_DER_ERROR if the der encoding doesn't match the structure + * name (*@ELEMENT deleted). **/ asn1_retCode asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len, @@ -1350,7 +1333,6 @@ asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len, return ASN1_SUCCESS; } - #define FOUND 1 #define SAME_BRANCH 2 #define OTHER_BRANCH 3 @@ -1365,22 +1347,17 @@ asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len, * @errorDescription: null-terminated string contains details when an * error occurred. * - * Fill the element named ELEMENTNAME with values of a DER encoding + * Fill the element named @ELEMENTNAME with values of a DER encoding * string. The structure must just be created with function - * 'asn1_create_element'. The DER vector must contain the encoding - * string of the whole STRUCTURE. If an error occurs during the - * decoding procedure, the *STRUCTURE is deleted and set equal to + * asn1_create_element(). The DER vector must contain the encoding + * string of the whole @STRUCTURE. If an error occurs during the + * decoding procedure, the *@STRUCTURE is deleted and set equal to * %ASN1_TYPE_EMPTY. * - * Returns: - * - * %ASN1_SUCCESS: DER encoding OK. - * - * %ASN1_ELEMENT_NOT_FOUND: ELEMENT is ASN1_TYPE_EMPTY or - * elementName == NULL. - * - * %ASN1_TAG_ERROR,ASN1_DER_ERROR: The der encoding doesn't match - * the structure STRUCTURE. *ELEMENT deleted. + * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND + * if ELEMENT is %ASN1_TYPE_EMPTY or @elementName == NULL, and + * %ASN1_TAG_ERROR or %ASN1_DER_ERROR if the der encoding doesn't + * match the structure @structure (*ELEMENT deleted). **/ asn1_retCode asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, @@ -2127,8 +2104,6 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, return ASN1_SUCCESS; } - - /** * asn1_der_decoding_startEnd: * @element: pointer to an ASN1 element @@ -2142,21 +2117,17 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, * * Find the start and end point of an element in a DER encoding * string. I mean that if you have a der encoding and you have already - * used the function "asn1_der_decoding" to fill a structure, it may + * used the function asn1_der_decoding() to fill a structure, it may * happen that you want to find the piece of string concerning an * element of the structure. * - * Example: the sequence "tbsCertificate" inside an X509 certificate. - * - * Returns: + * One example is the sequence "tbsCertificate" inside an X509 + * certificate. * - * %ASN1_SUCCESS: DER encoding OK. - * - * %ASN1_ELEMENT_NOT_FOUND: ELEMENT is ASN1_TYPE EMPTY or - * NAME_ELEMENT is not a valid element. - * - * %ASN1_TAG_ERROR,ASN1_DER_ERROR: the der encoding doesn't match - * the structure ELEMENT. + * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND + * if ELEMENT is %ASN1_TYPE EMPTY or @name_element is not a valid + * element, %ASN1_TAG_ERROR or %ASN1_DER_ERROR if the der encoding + * doesn't match the structure ELEMENT. **/ asn1_retCode asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, @@ -2479,7 +2450,6 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, return ASN1_ELEMENT_NOT_FOUND; } - /** * asn1_expand_any_defined_by: * @definitions: ASN1 definitions @@ -2491,14 +2461,10 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, * expand the element ANY is the first one following the definition of * the actual value of the OBJECT IDENTIFIER. * - * Returns: - * - * %ASN1_SUCCESS: Substitution OK. - * - * %ASN1_ERROR_TYPE_ANY: Some "ANY DEFINED BY" element couldn't be - * expanded due to a problem in OBJECT_ID -> TYPE association. - * - * other errors: Result of der decoding process. + * Returns: %ASN1_SUCCESS if Substitution OK, %ASN1_ERROR_TYPE_ANY if + * some "ANY DEFINED BY" element couldn't be expanded due to a + * problem in OBJECT_ID -> TYPE association, or other error codes + * depending on DER decoding. **/ asn1_retCode asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) @@ -2599,7 +2565,7 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) if ((result == ASN1_SUCCESS) && (!strcmp (p3->value, value))) { - p2 = p2->right; /* pointer to the structure to + p2 = p2->right; /* pointer to the structure to use for expansion */ while ((p2) && (p2->type & CONST_ASSIGN)) p2 = p2->right; @@ -2712,8 +2678,6 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) return retCode; } - - /** * asn1_expand_octet_string: * @definitions: ASN1 definitions @@ -2723,20 +2687,14 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) * the type for expansion. * * Expands an "OCTET STRING" element of a structure created from a DER - * decoding process (asn1_der_decoding function). The type used for - * expansion is the first one following the definition of the actual - * value of the OBJECT IDENTIFIER indicated by OBJECTNAME. - * - * Returns: - * - * %ASN1_SUCCESS: Substitution OK. - * - * %ASN1_ELEMENT_NOT_FOUND: @objectName or @octetName are not correct. - * - * %ASN1_VALUE_NOT_VALID: Wasn't possible to find the type to use - * for expansion. + * decoding process (the asn1_der_decoding() function). The type used + * for expansion is the first one following the definition of the + * actual value of the OBJECT IDENTIFIER indicated by OBJECTNAME. * - * other errors: result of der decoding process. + * Returns: %ASN1_SUCCESS if substitution OK, %ASN1_ELEMENT_NOT_FOUND + * if @objectName or @octetName are not correct, + * %ASN1_VALUE_NOT_VALID if it wasn't possible to find the type to + * use for expansion, or other errors depending on DER decoding. **/ asn1_retCode asn1_expand_octet_string (ASN1_TYPE definitions, ASN1_TYPE * element, @@ -2789,7 +2747,7 @@ asn1_expand_octet_string (ASN1_TYPE definitions, ASN1_TYPE * element, && (!strcmp (objectNode->value, value))) { - p2 = p2->right; /* pointer to the structure to + p2 = p2->right; /* pointer to the structure to use for expansion */ while ((p2) && (p2->type & CONST_ASSIGN)) p2 = p2->right; diff --git a/lib/minitasn1/element.h b/lib/minitasn1/element.h index b5d9eb9e55..95c382a176 100644 --- a/lib/minitasn1/element.h +++ b/lib/minitasn1/element.h @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010 + * Free Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ #ifndef _ELEMENT_H #define _ELEMENT_H diff --git a/lib/minitasn1/gstr.h b/lib/minitasn1/gstr.h index 5452fa4683..bffb912332 100644 --- a/lib/minitasn1/gstr.h +++ b/lib/minitasn1/gstr.h @@ -1,3 +1,25 @@ +/* + * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Free Software + * Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ + 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); diff --git a/lib/minitasn1/libtasn1.h b/lib/minitasn1/libtasn1.h index fea5cea532..fd3a1393f5 100644 --- a/lib/minitasn1/libtasn1.h +++ b/lib/minitasn1/libtasn1.h @@ -45,7 +45,7 @@ extern "C" { #endif -#define ASN1_VERSION "2.5" +#define ASN1_VERSION "2.6" typedef int asn1_retCode; /* type returned by libtasn1 functions */ @@ -159,138 +159,126 @@ extern "C" /* Functions definitions */ /***********************************/ - ASN1_API asn1_retCode - asn1_parser2tree (const char *file_name, - ASN1_TYPE * definitions, - char *errorDescription); - - ASN1_API asn1_retCode - asn1_parser2array (const char *inputFileName, - const char *outputFileName, - const char *vectorName, - char *errorDescription); - - ASN1_API asn1_retCode - asn1_array2tree (const ASN1_ARRAY_TYPE * array, - ASN1_TYPE * definitions, - char *errorDescription); - - ASN1_API 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_API asn1_retCode - asn1_delete_structure (ASN1_TYPE * structure); - - ASN1_API asn1_retCode - asn1_delete_element (ASN1_TYPE structure, - const char *element_name); - - ASN1_API asn1_retCode - asn1_write_value (ASN1_TYPE node_root, const char *name, - const void *ivalue, int len); - - ASN1_API asn1_retCode - asn1_read_value (ASN1_TYPE root, const char *name, - void *ivalue, int *len); - - ASN1_API asn1_retCode - asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num); - - ASN1_API asn1_retCode - asn1_der_coding (ASN1_TYPE element, const char *name, - void *ider, int *len, - char *ErrorDescription); - - ASN1_API asn1_retCode - asn1_der_decoding (ASN1_TYPE * element, const void *ider, - 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); - - ASN1_API asn1_retCode - asn1_der_decoding_startEnd (ASN1_TYPE element, - const void *ider, int len, - const char *name_element, - int *start, int *end); - - ASN1_API asn1_retCode - asn1_expand_any_defined_by (ASN1_TYPE definitions, - ASN1_TYPE * element); - - ASN1_API asn1_retCode - asn1_expand_octet_string (ASN1_TYPE definitions, - ASN1_TYPE * element, - const char *octetName, - const char *objectName); - - ASN1_API asn1_retCode - asn1_read_tag (ASN1_TYPE root, const char *name, - int *tagValue, int *classValue); - - ASN1_API const char * - asn1_find_structure_from_oid (ASN1_TYPE definitions, - const char *oidValue); - - ASN1_API const char * - asn1_check_version (const char *req_version); - - ASN1_API const char * - asn1_strerror (asn1_retCode error); - - ASN1_API void - asn1_perror (asn1_retCode error); + extern ASN1_API asn1_retCode + asn1_parser2tree (const char *file_name, + ASN1_TYPE * definitions, char *errorDescription); + + extern ASN1_API asn1_retCode + asn1_parser2array (const char *inputFileName, + const char *outputFileName, + const char *vectorName, char *errorDescription); + + extern ASN1_API asn1_retCode + asn1_array2tree (const ASN1_ARRAY_TYPE * array, + ASN1_TYPE * definitions, char *errorDescription); + + extern ASN1_API void + asn1_print_structure (FILE * out, ASN1_TYPE structure, + const char *name, int mode); + + extern ASN1_API asn1_retCode + asn1_create_element (ASN1_TYPE definitions, + const char *source_name, ASN1_TYPE * element); + + extern ASN1_API asn1_retCode asn1_delete_structure (ASN1_TYPE * structure); + + extern ASN1_API asn1_retCode + asn1_delete_element (ASN1_TYPE structure, const char *element_name); + + extern ASN1_API asn1_retCode + asn1_write_value (ASN1_TYPE node_root, const char *name, + const void *ivalue, int len); + + extern ASN1_API asn1_retCode + asn1_read_value (ASN1_TYPE root, const char *name, + void *ivalue, int *len); + + extern ASN1_API asn1_retCode + asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num); + + extern ASN1_API asn1_retCode + asn1_der_coding (ASN1_TYPE element, const char *name, + void *ider, int *len, char *ErrorDescription); + + extern ASN1_API asn1_retCode + asn1_der_decoding (ASN1_TYPE * element, const void *ider, + int len, char *errorDescription); + + extern ASN1_API asn1_retCode + asn1_der_decoding_element (ASN1_TYPE * structure, + const char *elementName, + const void *ider, int len, + char *errorDescription); + + extern ASN1_API asn1_retCode + asn1_der_decoding_startEnd (ASN1_TYPE element, + const void *ider, int len, + const char *name_element, + int *start, int *end); + + extern ASN1_API asn1_retCode + asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element); + + extern ASN1_API asn1_retCode + asn1_expand_octet_string (ASN1_TYPE definitions, + ASN1_TYPE * element, + const char *octetName, const char *objectName); + + extern ASN1_API asn1_retCode + asn1_read_tag (ASN1_TYPE root, const char *name, + int *tagValue, int *classValue); + + extern ASN1_API const char *asn1_find_structure_from_oid (ASN1_TYPE + definitions, + const char + *oidValue); + + extern ASN1_API const char *asn1_check_version (const char *req_version); + + extern ASN1_API const char *asn1_strerror (asn1_retCode error); + + extern ASN1_API void asn1_perror (asn1_retCode error); /* DER utility functions. */ - ASN1_API int - asn1_get_tag_der (const unsigned char *der, int der_len, - unsigned char *cls, int *len, - unsigned long *tag); + extern ASN1_API int + asn1_get_tag_der (const unsigned char *der, int der_len, + 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); + extern ASN1_API void + asn1_octet_der (const unsigned char *str, int str_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); + extern 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); - ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len, - unsigned char *der, int *der_len); + extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_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); + extern 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); - ASN1_API signed long - asn1_get_length_der (const unsigned char *der, int der_len, int *len); + extern ASN1_API signed long + asn1_get_length_der (const unsigned char *der, int der_len, int *len); - ASN1_API signed long - asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len); + extern ASN1_API signed long + asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len); - ASN1_API void - asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len); + extern ASN1_API void + asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len); /* Other utility functions. */ - ASN1_API ASN1_TYPE - asn1_find_node (ASN1_TYPE pointer, const char *name); + extern ASN1_API 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); + extern ASN1_API asn1_retCode + asn1_copy_node (ASN1_TYPE dst, const char *dst_name, + ASN1_TYPE src, const char *src_name); /* Deprecated stuff. */ @@ -314,14 +302,12 @@ extern "C" #endif /* Use asn1_strerror instead. */ - ASN1_API const char * - libtasn1_strerror (asn1_retCode error) + extern ASN1_API const char *libtasn1_strerror (asn1_retCode error) __attribute__ ((deprecated)); /* Use asn1_perror instead. */ - ASN1_API void - libtasn1_perror (asn1_retCode error) - __attribute__ ((deprecated)); + extern ASN1_API void + libtasn1_perror (asn1_retCode error) __attribute__ ((deprecated)); #endif diff --git a/lib/minitasn1/parser_aux.c b/lib/minitasn1/parser_aux.c index b740a1e997..a3150a8e22 100644 --- a/lib/minitasn1/parser_aux.c +++ b/lib/minitasn1/parser_aux.c @@ -83,12 +83,12 @@ _asn1_add_node (unsigned int type) * @pointer: NODE_ASN element pointer. * @name: null terminated string with the element's name to find. * - * Searches for an element called NAME starting from POINTER. The + * Searches for an element called @name starting from @pointer. The * name is composed by differents identifiers separated by dots. When - * *POINTER has a name, the first identifier must be the name of - * *POINTER, otherwise it must be the name of one child of *POINTER. + * *@pointer has a name, the first identifier must be the name of + * *@pointer, otherwise it must be the name of one child of *@pointer. * - * Return value: the searching result. NULL if not found. + * Returns: the search result, or %NULL if not found. **/ ASN1_TYPE asn1_find_node (ASN1_TYPE pointer, const char *name) @@ -160,7 +160,7 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) p = p->down; - /* The identifier "?LAST" indicates the last element + /* The identifier "?LAST" indicates the last element in the right chain. */ if (!strcmp (n, "?LAST")) { @@ -1095,90 +1095,3 @@ _asn1_set_default_tag (ASN1_TYPE node) return ASN1_SUCCESS; } - - - -static const char * -parse_version_number (const char *s, int *number) -{ - int val = 0; - - if (*s == '0' && isdigit (s[1])) - return NULL; /* leading zeros are not allowed */ - for (; isdigit (*s); s++) - { - val *= 10; - val += *s - '0'; - } - *number = val; - return val < 0 ? NULL : s; -} - -/* The parse version functions were copied from libgcrypt. - */ -static const char * -parse_version_string (const char *s, int *major, int *minor, int *micro) -{ - s = parse_version_number (s, major); - if (!s || *s != '.') - return NULL; - s++; - s = parse_version_number (s, minor); - if (!s) - return NULL; - if (*s != '.') - { - *micro = 0; - return s; - } - s++; - s = parse_version_number (s, micro); - if (!s) - return NULL; - return s; /* patchlevel */ -} - -/** - * asn1_check_version: - * @req_version: Required version number, or NULL. - * - * Check that the version of the library is at minimum the - * requested one and return the version string; return %NULL if the - * condition is not satisfied. If a %NULL is passed to this function, - * no check is done, but the version string is simply returned. - * - * See %ASN1_VERSION for a suitable @req_version string. - * - * Return value: Version string of run-time library, or %NULL if the - * run-time library does not meet the required version number. - */ -const char * -asn1_check_version (const char *req_version) -{ - const char *ver = ASN1_VERSION; - int my_major, my_minor, my_micro; - int rq_major, rq_minor, rq_micro; - const char *my_plvl, *rq_plvl; - - if (!req_version) - return ver; - - my_plvl = parse_version_string (ver, &my_major, &my_minor, &my_micro); - if (!my_plvl) - return NULL; /* very strange our own version is bogus */ - rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor, - &rq_micro); - if (!rq_plvl) - return NULL; /* req version string is invalid */ - - if (my_major > rq_major - || (my_major == rq_major && my_minor > rq_minor) - || (my_major == rq_major && my_minor == rq_minor - && my_micro > rq_micro) - || (my_major == rq_major && my_minor == rq_minor - && my_micro == rq_micro && strcmp (my_plvl, rq_plvl) >= 0)) - { - return ver; - } - return NULL; -} diff --git a/lib/minitasn1/parser_aux.h b/lib/minitasn1/parser_aux.h index 564f64ecf6..def52edcf3 100644 --- a/lib/minitasn1/parser_aux.h +++ b/lib/minitasn1/parser_aux.h @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free + * Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ #ifndef _PARSER_AUX_H #define _PARSER_AUX_H diff --git a/lib/minitasn1/structure.h b/lib/minitasn1/structure.h index 7257986ba0..3885afc314 100644 --- a/lib/minitasn1/structure.h +++ b/lib/minitasn1/structure.h @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 Free + * Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ /*************************************************/ /* File: structure.h */ diff --git a/lib/minitasn1/version.c b/lib/minitasn1/version.c new file mode 100644 index 0000000000..ad7b43eb36 --- /dev/null +++ b/lib/minitasn1/version.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free + * Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include /* for strverscmp */ + +#include "libtasn1.h" + +/** + * asn1_check_version: + * @req_version: Required version number, or %NULL. + * + * Check that the version of the library is at minimum the + * requested one and return the version string; return %NULL if the + * condition is not satisfied. If a %NULL is passed to this function, + * no check is done, but the version string is simply returned. + * + * See %ASN1_VERSION for a suitable @req_version string. + * + * Returns: Version string of run-time library, or %NULL if the + * run-time library does not meet the required version number. + */ +const char * +asn1_check_version (const char *req_version) +{ + if (!req_version || strverscmp (req_version, ASN1_VERSION) <= 0) + return ASN1_VERSION; + + return NULL; +} -- cgit v1.2.1