** Fix warnings and build GnuTLS with more warnings enabled.
+** minitasn1: Internal copy updated to libtasn1 v1.7.
+
** API and ABI modifications:
gnutls_certificate_set_x509_simple_pkcs12_mem: ADDED
GNUTLS_VERSION: ADDED, replaces LIBGNUTLS_VERSION.
/* Return: */
/******************************************************/
void
-_asn1_error_description_value_not_found (node_asn * node,
+_asn1_error_description_value_not_found (ASN1_TYPE node,
char *ErrorDescription)
{
Estrcpy (ErrorDescription, ":: value of element '");
_asn1_hierarchical_name (node, ErrorDescription + strlen (ErrorDescription),
- MAX_ERROR_DESCRIPTION_SIZE - 40);
+ ASN1_MAX_ERROR_DESCRIPTION_SIZE - 40);
Estrcat (ErrorDescription, "' not found");
}
/* otherwise ASN1_SUCCESS. */
/******************************************************/
asn1_retCode
-_asn1_complete_explicit_tag (node_asn * node, unsigned char *der,
+_asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der,
int *counter, int *max_len)
{
- node_asn *p;
+ ASN1_TYPE p;
int is_tag_implicit, len2, len3;
unsigned char temp[SIZEOF_UNSIGNED_INT];
/* otherwise ASN1_SUCCESS. */
/******************************************************/
asn1_retCode
-_asn1_insert_tag_der (node_asn * node, unsigned char *der, int *counter,
+_asn1_insert_tag_der (ASN1_TYPE node, unsigned char *der, int *counter,
int *max_len)
{
- node_asn *p;
+ ASN1_TYPE p;
int tag_len, is_tag_implicit;
unsigned char class, class_implicit = 0, temp[SIZEOF_UNSIGNED_INT * 3 + 1];
unsigned long tag_implicit = 0;
/* Return: */
/******************************************************/
void
-_asn1_ordering_set (unsigned char *der, int der_len, node_asn * node)
+_asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node)
{
struct vet
{
int counter, len, len2;
struct vet *first, *last, *p_vet, *p2_vet;
- node_asn *p;
+ ASN1_TYPE p;
unsigned char class, *temp;
unsigned long tag;
/* Return: */
/******************************************************/
void
-_asn1_ordering_set_of (unsigned char *der, int der_len, node_asn * node)
+_asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node)
{
struct vet
{
int counter, len, len2, change;
struct vet *first, *last, *p_vet, *p2_vet;
- node_asn *p;
+ ASN1_TYPE p;
unsigned char *temp, class;
unsigned long k, max;
asn1_der_coding (ASN1_TYPE element, const char *name, void *ider, int *len,
char *ErrorDescription)
{
- node_asn *node, *p, *p2;
+ ASN1_TYPE node, p, p2;
char temp[SIZEOF_UNSIGNED_LONG_INT * 3 + 1];
int counter, counter_old, len2, len3, tlen, move, max_len, max_len_old;
asn1_retCode err;
_asn1_get_indefinite_length_string (const unsigned char *der, int *len);
static void
-_asn1_error_description_tag_error (node_asn * node, char *ErrorDescription)
+_asn1_error_description_tag_error (ASN1_TYPE node, char *ErrorDescription)
{
Estrcpy (ErrorDescription, ":: tag error near element '");
_asn1_hierarchical_name (node, ErrorDescription + strlen (ErrorDescription),
- MAX_ERROR_DESCRIPTION_SIZE - 40);
+ ASN1_MAX_ERROR_DESCRIPTION_SIZE - 40);
Estrcat (ErrorDescription, "'");
}
* @ber_len: Length of BER data to decode.
* @len: Output variable containing the length of the BER length field.
*
- * Extract a length field from BER data.
+ * Extract a length field from BER data. The difference to
+ * 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. The difference with asn1_get_length_der()
- * is that it will return length even if the value has indefinite encoding.
+ * when the value was too big.
*
+ * Since: 2.0
**/
-long
+signed long
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);
- if (ret == -1)
+ if (ret == -1)
{ /* indefinite length method */
ret = ber_len;
err = _asn1_get_indefinite_length_string (ber+1, &ret);
if (err != ASN1_SUCCESS)
- return -3;
+ return -3;
}
-
+
return ret;
}
int
-_asn1_extract_tag_der (node_asn * node, const unsigned char *der, int der_len,
+_asn1_extract_tag_der (ASN1_TYPE node, const unsigned char *der, int der_len,
int *ret_len)
{
- node_asn *p;
+ ASN1_TYPE p;
int counter, len2, len3, is_tag_implicit;
unsigned long tag, tag_implicit = 0;
unsigned char class, class2, class_implicit = 0;
int
-_asn1_delete_not_used (node_asn * node)
+_asn1_delete_not_used (ASN1_TYPE node)
{
- node_asn *p, *p2;
+ ASN1_TYPE p, p2;
if (node == NULL)
return ASN1_ELEMENT_NOT_FOUND;
return ASN1_SUCCESS;
}
-asn1_retCode _asn1_extract_der_octet(node_asn * node, const unsigned char *der, int der_len)
+asn1_retCode _asn1_extract_der_octet(ASN1_TYPE node, const unsigned char *der, int der_len)
{
int len2, len3;
int counter2, counter_end;
asn1_retCode
-_asn1_get_octet_string (const unsigned char *der, node_asn * node, int *len)
+_asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len)
{
int len2, len3, counter, tot_len, indefinite;
asn1_der_decoding (ASN1_TYPE * element, const void *ider, int len,
char *errorDescription)
{
- node_asn *node, *p, *p2, *p3;
+ ASN1_TYPE node, p, p2, p3;
char temp[128];
int counter, len2, len3, len4, move, ris, tlen;
unsigned char class;
asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName,
const void *ider, int len, char *errorDescription)
{
- node_asn *node, *p, *p2, *p3, *nodeFound = ASN1_TYPE_EMPTY;
- char temp[128], currentName[MAX_NAME_SIZE * 10], *dot_p, *char_p;
- int nameLen = MAX_NAME_SIZE * 10 - 1, state;
+ ASN1_TYPE node, p, p2, p3, nodeFound = ASN1_TYPE_EMPTY;
+ char temp[128], currentName[ASN1_MAX_NAME_SIZE * 10], *dot_p, *char_p;
+ int nameLen = ASN1_MAX_NAME_SIZE * 10 - 1, state;
int counter, len2, len3, len4, move, ris, tlen;
unsigned char class, *temp2;
unsigned long tag;
asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len,
const char *name_element, int *start, int *end)
{
- node_asn *node, *node_to_find, *p, *p2, *p3;
+ ASN1_TYPE node, node_to_find, p, p2, p3;
int counter, len2, len3, len4, move, ris;
unsigned char class;
unsigned long tag;
asn1_retCode
asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element)
{
- char definitionsName[MAX_NAME_SIZE], name[2 * MAX_NAME_SIZE + 1],
- value[MAX_NAME_SIZE];
+ char definitionsName[ASN1_MAX_NAME_SIZE], name[2 * ASN1_MAX_NAME_SIZE + 1],
+ value[ASN1_MAX_NAME_SIZE];
asn1_retCode retCode = ASN1_SUCCESS, result;
int len, len2, len3;
ASN1_TYPE p, p2, p3, aux = ASN1_TYPE_EMPTY;
- char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
+ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
if ((definitions == ASN1_TYPE_EMPTY) || (*element == ASN1_TYPE_EMPTY))
return ASN1_ELEMENT_NOT_FOUND;
strcpy (name, definitionsName);
strcat (name, p2->name);
- len = MAX_NAME_SIZE;
+ len = ASN1_MAX_NAME_SIZE;
result =
asn1_read_value (definitions, name, value, &len);
asn1_expand_octet_string (ASN1_TYPE definitions, ASN1_TYPE * element,
const char *octetName, const char *objectName)
{
- char name[2 * MAX_NAME_SIZE + 1], value[MAX_NAME_SIZE];
+ char name[2 * ASN1_MAX_NAME_SIZE + 1], value[ASN1_MAX_NAME_SIZE];
asn1_retCode retCode = ASN1_SUCCESS, result;
int len, len2, len3;
ASN1_TYPE p2, aux = ASN1_TYPE_EMPTY;
ASN1_TYPE octetNode = ASN1_TYPE_EMPTY, objectNode = ASN1_TYPE_EMPTY;
- char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
+ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
if ((definitions == ASN1_TYPE_EMPTY) || (*element == ASN1_TYPE_EMPTY))
return ASN1_ELEMENT_NOT_FOUND;
#include "structure.h"
void
-_asn1_hierarchical_name (node_asn * node, char *name, int name_size)
+_asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size)
{
- node_asn *p;
+ ASN1_TYPE p;
char tmp_name[64];
p = node;
int
-_asn1_append_sequence_set (node_asn * node)
+_asn1_append_sequence_set (ASN1_TYPE node)
{
- node_asn *p, *p2;
+ ASN1_TYPE p, p2;
char temp[10];
long n;
asn1_write_value (ASN1_TYPE node_root, const char *name,
const void *ivalue, int len)
{
- node_asn *node, *p, *p2;
+ ASN1_TYPE node, p, p2;
unsigned char *temp, *value_temp = NULL, *default_temp = NULL;
int len2, k, k2, negative;
const unsigned char *value = ivalue;
asn1_retCode
asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len)
{
- node_asn *node, *p, *p2;
+ ASN1_TYPE node, p, p2;
int len2, len3;
int value_size = *len;
unsigned char *value = ivalue;
*
**/
asn1_retCode
-asn1_read_tag (node_asn * root, const char *name, int *tagValue,
+asn1_read_tag (ASN1_TYPE root, const char *name, int *tagValue,
int *classValue)
{
- node_asn *node, *p, *pTag;
+ ASN1_TYPE node, p, pTag;
node = asn1_find_node (root, name);
if (node == NULL)
#define _ELEMENT_H
-asn1_retCode _asn1_append_sequence_set(node_asn *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);
-void _asn1_hierarchical_name(node_asn *node,char *name,int name_size);
+void _asn1_hierarchical_name(ASN1_TYPE node,char *name,int name_size);
#endif
/*
- * Copyright (C) 2006 Free Software Foundation, Inc.
+ * Copyright (C) 2006, 2008 Free Software Foundation, Inc.
* Copyright (C) 2002, 2005 Fabio Fiorina
*
* This file is part of LIBTASN1.
# include <stdarg.h>
#endif
-
-#define LIBTASN1_ERROR_ENTRY(name) \
- { #name, name }
+#define LIBTASN1_ERROR_ENTRY(name) { #name, name }
struct libtasn1_error_entry
{
{0}
};
-#define LIBTASN1_ERROR_LOOP(b) \
- const libtasn1_error_entry *p; \
- for(p = error_algorithms; p->name != NULL; p++) { b ; }
-
-#define LIBTASN1_ERROR_ALG_LOOP(a) \
- LIBTASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
-
-
-
/**
- * libtasn1_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
- * accepts an error returned by a libtasn1 function.
- **/
+ * 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
+ * accepts an error returned by a libtasn1 function.
+ *
+ * Since: 1.6
+ **/
void
-libtasn1_perror (asn1_retCode error)
+asn1_perror (asn1_retCode error)
{
- const char *ret = NULL;
-
- /* avoid prefix */
- LIBTASN1_ERROR_ALG_LOOP (ret = p->name + sizeof ("ASN1_") - 1);
-
- fprintf (stderr, "LIBTASN1 ERROR: %s\n", ret);
-
+ const char *str = asn1_strerror (error);
+ fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
}
-
/**
- * libtasn1_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
- * that it accepts an error (number) returned by a libtasn1 function.
- *
- * Returns: Pointer to static zero-terminated string describing error
- * code.
- **/
+ * 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
+ * that it accepts an error (number) returned by a libtasn1 function.
+ *
+ * Returns: Pointer to static zero-terminated string describing error
+ * code.
+ *
+ * Since: 1.6
+ **/
const char *
-libtasn1_strerror (asn1_retCode error)
+asn1_strerror (asn1_retCode error)
{
- const char *ret = NULL;
+ const libtasn1_error_entry *p;
- /* avoid prefix */
- LIBTASN1_ERROR_ALG_LOOP (ret = p->name + sizeof ("ASN1_") - 1);
+ for (p = error_algorithms; p->name != NULL; p++)
+ if (p->number == error)
+ return p->name + sizeof ("ASN1_") - 1;
- return ret;
+ return NULL;
}
-/* this function will output a message.
- */
-#ifdef LIBTASN1_DEBUG
-void
-_libtasn1_log (const char *fmt, ...)
-{
- va_list args;
- char str[MAX_LOG_SIZE];
-
- va_start (args, fmt);
- vsprintf (str, fmt, args); /* Flawfinder: ignore */
- va_end (args);
+#ifndef ASN1_DISABLE_DEPRECATED
- fprintf (stderr, str);
+/* Compatibility mappings to preserve ABI. */
- return;
-}
-#else /* not DEBUG */
+/**
+ * libtasn1_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
+ * accepts an error returned by a libtasn1 function.
+ *
+ * Deprecated: Use asn1_perror() instead.
+ **/
void
-_libtasn1_log (const char *fmt, ...)
+libtasn1_perror (asn1_retCode error)
+{
+ asn1_perror (error);
+}
+
+/**
+ * libtasn1_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
+ * that it accepts an error (number) returned by a libtasn1 function.
+ *
+ * Returns: Pointer to static zero-terminated string describing error
+ * code.
+ *
+ * Deprecated: Use asn1_strerror() instead.
+ **/
+const char *
+libtasn1_strerror (asn1_retCode error)
{
- return;
+ return asn1_strerror (error);
}
-#endif /* DEBUG */
+
+#endif
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,MAX_ERROR_DESCRIPTION_SIZE,y)
-#define Estrcat(x,y) _asn1_str_cat(x,MAX_ERROR_DESCRIPTION_SIZE,y)
+#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)
# define LIBTASN1_H
#include <stdio.h> /* for FILE* */
+#include <sys/types.h>
+#include <time.h>
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
-#define LIBTASN1_VERSION "1.5"
-
-#include <sys/types.h>
-#include <time.h>
+#define ASN1_VERSION "1.7"
-#define MAX_NAME_SIZE 128 /* maximum number of characters of a name */
- /* inside a file with ASN1 definitons */
-#define MAX_ERROR_DESCRIPTION_SIZE 128 /* maximum number of characters */
- /* of a description message */
- /* (null character included) */
+ typedef int asn1_retCode; /* type returned by libtasn1 functions */
+ /*****************************************/
+ /* Errors returned by libtasn1 functions */
+ /*****************************************/
+#define ASN1_SUCCESS 0
+#define ASN1_FILE_NOT_FOUND 1
+#define ASN1_ELEMENT_NOT_FOUND 2
+#define ASN1_IDENTIFIER_NOT_FOUND 3
+#define ASN1_DER_ERROR 4
+#define ASN1_VALUE_NOT_FOUND 5
+#define ASN1_GENERIC_ERROR 6
+#define ASN1_VALUE_NOT_VALID 7
+#define ASN1_TAG_ERROR 8
+#define ASN1_TAG_IMPLICIT 9
+#define ASN1_ERROR_TYPE_ANY 10
+#define ASN1_SYNTAX_ERROR 11
+#define ASN1_MEM_ERROR 12
+#define ASN1_MEM_ALLOC_ERROR 13
+#define ASN1_DER_OVERFLOW 14
+#define ASN1_NAME_TOO_LONG 15
+#define ASN1_ARRAY_ERROR 16
+#define ASN1_ELEMENT_NOT_EMPTY 17
+
+ /*************************************/
+ /* Constants used in asn1_visit_tree */
+ /*************************************/
+#define ASN1_PRINT_NAME 1
+#define ASN1_PRINT_NAME_TYPE 2
+#define ASN1_PRINT_NAME_TYPE_VALUE 3
+#define ASN1_PRINT_ALL 4
- typedef int asn1_retCode; /* type returned by libtasn1 functions */
+ /*****************************************/
+ /* Constants returned by asn1_read_tag */
+ /*****************************************/
+#define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */
+#define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */
+#define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */
+#define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */
+#define ASN1_CLASS_STRUCTURED 0x20
/*****************************************/
- /* Errors returned by libtasn1 functions */
+ /* Constants returned by asn1_read_tag */
/*****************************************/
-#define ASN1_SUCCESS 0
-#define ASN1_FILE_NOT_FOUND 1
-#define ASN1_ELEMENT_NOT_FOUND 2
-#define ASN1_IDENTIFIER_NOT_FOUND 3
-#define ASN1_DER_ERROR 4
-#define ASN1_VALUE_NOT_FOUND 5
-#define ASN1_GENERIC_ERROR 6
-#define ASN1_VALUE_NOT_VALID 7
-#define ASN1_TAG_ERROR 8
-#define ASN1_TAG_IMPLICIT 9
-#define ASN1_ERROR_TYPE_ANY 10
-#define ASN1_SYNTAX_ERROR 11
-#define ASN1_MEM_ERROR 12
-#define ASN1_MEM_ALLOC_ERROR 13
-#define ASN1_DER_OVERFLOW 14
-#define ASN1_NAME_TOO_LONG 15
-#define ASN1_ARRAY_ERROR 16
-#define ASN1_ELEMENT_NOT_EMPTY 17
-
-/*************************************/
-/* Constants used in asn1_visit_tree */
-/*************************************/
-#define ASN1_PRINT_NAME 1
-#define ASN1_PRINT_NAME_TYPE 2
-#define ASN1_PRINT_NAME_TYPE_VALUE 3
-#define ASN1_PRINT_ALL 4
-
-/*****************************************/
-/* Constants returned by asn1_read_tag */
-/*****************************************/
-#define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */
-#define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */
-#define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */
-#define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */
-#define ASN1_CLASS_STRUCTURED 0x20
-
-/*****************************************/
-/* Constants returned by asn1_read_tag */
-/*****************************************/
-#define ASN1_TAG_BOOLEAN 0x01
-#define ASN1_TAG_INTEGER 0x02
-#define ASN1_TAG_SEQUENCE 0x10
-#define ASN1_TAG_SET 0x11
-#define ASN1_TAG_OCTET_STRING 0x04
-#define ASN1_TAG_BIT_STRING 0x03
-#define ASN1_TAG_UTCTime 0x17
-#define ASN1_TAG_GENERALIZEDTime 0x18
-#define ASN1_TAG_OBJECT_ID 0x06
-#define ASN1_TAG_ENUMERATED 0x0A
-#define ASN1_TAG_NULL 0x05
-#define ASN1_TAG_GENERALSTRING 0x1B
-
-/******************************************************/
-/* Structure definition used for the node of the tree */
-/* that represent an ASN.1 DEFINITION. */
-/******************************************************/
-
-#define SMALL_VALUE_SIZE 16
+#define ASN1_TAG_BOOLEAN 0x01
+#define ASN1_TAG_INTEGER 0x02
+#define ASN1_TAG_SEQUENCE 0x10
+#define ASN1_TAG_SET 0x11
+#define ASN1_TAG_OCTET_STRING 0x04
+#define ASN1_TAG_BIT_STRING 0x03
+#define ASN1_TAG_UTCTime 0x17
+#define ASN1_TAG_GENERALIZEDTime 0x18
+#define ASN1_TAG_OBJECT_ID 0x06
+#define ASN1_TAG_ENUMERATED 0x0A
+#define ASN1_TAG_NULL 0x05
+#define ASN1_TAG_GENERALSTRING 0x1B
+
+ /******************************************************/
+ /* Structure definition used for the node of the tree */
+ /* that represent an ASN.1 DEFINITION. */
+ /******************************************************/
struct node_asn_struct
{
char *name; /* Node name */
unsigned int type; /* Node type */
unsigned char *value; /* Node value */
- unsigned char small_value[SMALL_VALUE_SIZE]; /* if value is less than that store it here */
int value_len;
struct node_asn_struct *down; /* Pointer to the son node */
struct node_asn_struct *right; /* Pointer to the brother node */
#define ASN1_TYPE_EMPTY NULL
+ /*****************************************/
+ /* For the on-disk format of ASN.1 trees */
+ /*****************************************/
struct static_struct_asn
{
- const char *name; /* Node name */
- unsigned int type; /* Node type */
+ const char *name; /* Node name */
+ unsigned int type; /* Node type */
const void *value; /* Node value */
};
-
typedef struct static_struct_asn ASN1_ARRAY_TYPE;
+ /***********************************/
+ /* Fixed constants */
+ /***********************************/
+ /* maximum number of characters of a name */
+ /* inside a file with ASN1 definitons */
+#define ASN1_MAX_NAME_SIZE 128
+
+ /* maximum number of characters */
+ /* of a description message */
+ /* (null character included) */
+#define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128
/***********************************/
/* Functions definitions */
const char *octetName,
const char *objectName);
- asn1_retCode asn1_read_tag (node_asn * root, const char *name,
+ asn1_retCode asn1_read_tag (ASN1_TYPE root, const char *name,
int *tagValue, int *classValue);
const char *asn1_find_structure_from_oid (ASN1_TYPE definitions,
const char *asn1_check_version (const char *req_version);
- const char *libtasn1_strerror (asn1_retCode error);
-
- void libtasn1_perror (asn1_retCode error);
+ const char *asn1_strerror (asn1_retCode error);
+ void asn1_perror (asn1_retCode error);
/* DER utility functions. */
signed long asn1_get_length_der (const unsigned char *der, int der_len,
int *len);
- long asn1_get_length_ber (const unsigned char *ber, int ber_len,
+ signed long asn1_get_length_ber (const unsigned char *ber, int ber_len,
int *len);
void asn1_length_der (unsigned long int len, unsigned char *ans,
asn1_retCode asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
ASN1_TYPE src, const char *src_name);
+
+ /* Deprecated stuff. */
+
+#ifndef ASN1_DISABLE_DEPRECATED
+
+#define LIBTASN1_VERSION ASN1_VERSION
+
+#ifndef MAX_NAME_SIZE
+# define MAX_NAME_SIZE ASN1_MAX_NAME_SIZE
+#endif
+
+#ifndef MAX_ERROR_DESCRIPTION_SIZE
+# define MAX_ERROR_DESCRIPTION_SIZE ASN1_MAX_ERROR_DESCRIPTION_SIZE
+#endif
+
+#ifndef __attribute__
+ /* This feature is available in gcc versions 2.5 and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define __attribute__(Spec) /* empty */
+# endif
+#endif
+
+ /* Use asn1_strerror instead. */
+ const char *libtasn1_strerror (asn1_retCode error)
+ __attribute__ ((deprecated));
+
+ /* Use asn1_perror instead. */
+ void libtasn1_perror (asn1_retCode error)
+ __attribute__ ((deprecated));
+
+#endif
+
#ifdef __cplusplus
}
#endif
/*
- * Copyright (C) 2004, 2006, 2007 Free Software Foundation
+ * Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation
* Copyright (C) 2000,2001 Fabio Fiorina
*
* This file is part of LIBTASN1.
#include "structure.h"
#include "element.h"
-char _asn1_identifierMissing[MAX_NAME_SIZE + 1]; /* identifier name not found */
+char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */
/***********************************************/
/* Type: list_type */
/***********************************************/
typedef struct list_struct
{
- node_asn *node;
+ ASN1_TYPE node;
struct list_struct *next;
} list_type;
/* and CONST_ constants). */
/* Return: pointer to the new element. */
/******************************************************/
-node_asn *
+ASN1_TYPE
_asn1_add_node (unsigned int type)
{
list_type *listElement;
- node_asn *punt;
+ ASN1_TYPE punt;
- punt = (node_asn *) _asn1_calloc (1, sizeof (node_asn));
+ punt = (ASN1_TYPE) _asn1_calloc (1, sizeof (struct node_asn_struct));
if (punt == NULL)
return NULL;
ASN1_TYPE
asn1_find_node (ASN1_TYPE pointer, const char *name)
{
- node_asn *p;
- char *n_end, n[MAX_NAME_SIZE + 1];
+ ASN1_TYPE p;
+ char *n_end, n[ASN1_MAX_NAME_SIZE + 1];
const char *n_start;
if (pointer == NULL)
/* len: character number of value. */
/* Return: pointer to the NODE_ASN element. */
/******************************************************************/
-node_asn *
-_asn1_set_value (node_asn * 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)
{
- if (node->value != node->small_value) _asn1_free (node->value);
+ _asn1_free (node->value);
node->value = NULL;
node->value_len = 0;
}
if (!len)
return node;
- 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 = (unsigned char *) _asn1_malloc (len);
+ if (node->value == NULL)
+ return NULL;
node->value_len = len;
memcpy (node->value, value, len);
/* len: character number of value. */
/* Return: pointer to the NODE_ASN element. */
/******************************************************************/
-node_asn *
-_asn1_set_value_octet (node_asn * 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;
/* the same as _asn1_set_value except that it sets an already malloc'ed
* value.
*/
-node_asn *
-_asn1_set_value_m (node_asn * 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)
{
- if (node->value != node->small_value) _asn1_free (node->value);
+ _asn1_free (node->value);
node->value = NULL;
node->value_len = 0;
}
/* len: character number of value. */
/* Return: pointer to the NODE_ASN element. */
/******************************************************************/
-node_asn *
-_asn1_append_value (node_asn * 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 && node->value != node->small_value) /* value is allocated */
+ if (node->value != NULL) /* 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;
+ node->value_len = 0;
+ return NULL;
}
memcpy( &node->value[prev_len], value, len);
-
+
return node;
}
- 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);
}
/* to set. */
/* Return: pointer to the NODE_ASN element. */
/******************************************************************/
-node_asn *
-_asn1_set_name (node_asn * node, const char *name)
+ASN1_TYPE
+_asn1_set_name (ASN1_TYPE node, const char *name)
{
if (node == NULL)
return node;
/* by NODE. */
/* Return: pointer to *NODE. */
/******************************************************************/
-node_asn *
-_asn1_set_right (node_asn * node, node_asn * right)
+ASN1_TYPE
+_asn1_set_right (ASN1_TYPE node, ASN1_TYPE right)
{
if (node == NULL)
return node;
/* node: NODE_ASN element pointer. */
/* Return: field RIGHT of NODE. */
/******************************************************************/
-node_asn *
-_asn1_get_right (node_asn * node)
+ASN1_TYPE
+_asn1_get_right (ASN1_TYPE node)
{
if (node == NULL)
return NULL;
/* node: starting element pointer. */
/* Return: pointer to the last element along the right chain. */
/******************************************************************/
-node_asn *
-_asn1_get_last_right (node_asn * node)
+ASN1_TYPE
+_asn1_get_last_right (ASN1_TYPE node)
{
- node_asn *p;
+ ASN1_TYPE p;
if (node == NULL)
return NULL;
/* by NODE. */
/* Return: pointer to *NODE. */
/******************************************************************/
-node_asn *
-_asn1_set_down (node_asn * node, node_asn * down)
+ASN1_TYPE
+_asn1_set_down (ASN1_TYPE node, ASN1_TYPE down)
{
if (node == NULL)
return node;
/* node: NODE_ASN element pointer. */
/* Return: field DOWN of NODE. */
/******************************************************************/
-node_asn *
-_asn1_get_down (node_asn * node)
+ASN1_TYPE
+_asn1_get_down (ASN1_TYPE node)
{
if (node == NULL)
return NULL;
/* Return: a null terminated string. */
/******************************************************************/
char *
-_asn1_get_name (node_asn * node)
+_asn1_get_name (ASN1_TYPE node)
{
if (node == NULL)
return NULL;
/* value of field TYPE. */
/* Return: NODE pointer. */
/******************************************************************/
-node_asn *
-_asn1_mod_type (node_asn * node, unsigned int value)
+ASN1_TYPE
+_asn1_mod_type (ASN1_TYPE node, unsigned int value)
{
if (node == NULL)
return node;
/* node: NODE_ASN element pointer. */
/******************************************************************/
void
-_asn1_remove_node (node_asn * node)
+_asn1_remove_node (ASN1_TYPE node)
{
if (node == NULL)
return;
if (node->name != NULL)
_asn1_free (node->name);
- if (node->value != NULL && node->value != node->small_value)
+ if (node->value != NULL)
_asn1_free (node->value);
_asn1_free (node);
}
/* node: NODE_ASN element pointer. */
/* Return: Null if not found. */
/******************************************************************/
-node_asn *
-_asn1_find_up (node_asn * node)
+ASN1_TYPE
+_asn1_find_up (ASN1_TYPE node)
{
- node_asn *p;
+ ASN1_TYPE p;
if (node == NULL)
return NULL;
asn1_retCode
_asn1_change_integer_value (ASN1_TYPE node)
{
- node_asn *p;
+ ASN1_TYPE p;
unsigned char val[SIZEOF_UNSIGNED_LONG_INT];
unsigned char val2[SIZEOF_UNSIGNED_LONG_INT + 1];
int len;
asn1_retCode
_asn1_expand_object_id (ASN1_TYPE node)
{
- node_asn *p, *p2, *p3, *p4, *p5;
- char name_root[MAX_NAME_SIZE], name2[2 * MAX_NAME_SIZE + 1];
+ ASN1_TYPE p, p2, p3, p4, p5;
+ char name_root[ASN1_MAX_NAME_SIZE], name2[2 * ASN1_MAX_NAME_SIZE + 1];
int move, tlen;
if (node == NULL)
asn1_retCode
_asn1_type_set_config (ASN1_TYPE node)
{
- node_asn *p, *p2;
+ ASN1_TYPE p, p2;
int move;
if (node == NULL)
asn1_retCode
_asn1_check_identifier (ASN1_TYPE node)
{
- node_asn *p, *p2;
- char name2[MAX_NAME_SIZE * 2 + 2];
+ ASN1_TYPE p, p2;
+ char name2[ASN1_MAX_NAME_SIZE * 2 + 2];
if (node == NULL)
return ASN1_ELEMENT_NOT_FOUND;
asn1_retCode
_asn1_set_default_tag (ASN1_TYPE node)
{
- node_asn *p;
+ ASN1_TYPE p;
if ((node == NULL) || (type_field (node->type) != TYPE_DEFINITIONS))
return ASN1_ELEMENT_NOT_FOUND;
* condition is not satisfied. If a %NULL is passed to this function,
* no check is done, but the version string is simply returned.
*
- * See %LIBTASN1_VERSION for a suitable @req_version string.
+ * 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 = LIBTASN1_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;
/***************************************/
/* Functions used by ASN.1 parser */
/***************************************/
-node_asn *
+ASN1_TYPE
_asn1_add_node(unsigned int type);
-node_asn *
-_asn1_set_value(node_asn *node,const void *value,unsigned int len);
+ASN1_TYPE
+_asn1_set_value(ASN1_TYPE node,const void *value,unsigned int len);
-node_asn *
-_asn1_set_value_m(node_asn *node,void *value,unsigned int len);
+ASN1_TYPE
+_asn1_set_value_m(ASN1_TYPE node,void *value,unsigned int len);
-node_asn *
-_asn1_set_value_octet(node_asn *node,const void *value,unsigned int len);
+ASN1_TYPE
+_asn1_set_value_octet(ASN1_TYPE node,const void *value,unsigned int len);
-node_asn *
-_asn1_append_value(node_asn *node,const void *value,unsigned int len);
+ASN1_TYPE
+_asn1_append_value(ASN1_TYPE node,const void *value,unsigned int len);
-node_asn *
-_asn1_set_name(node_asn *node,const char *name);
+ASN1_TYPE
+_asn1_set_name(ASN1_TYPE node,const char *name);
-node_asn *
-_asn1_set_right(node_asn *node,node_asn *right);
+ASN1_TYPE
+_asn1_set_right(ASN1_TYPE node, ASN1_TYPE right);
-node_asn *
-_asn1_get_right(node_asn *node);
+ASN1_TYPE
+_asn1_get_right(ASN1_TYPE node);
-node_asn *
-_asn1_get_last_right(node_asn *node);
+ASN1_TYPE
+_asn1_get_last_right(ASN1_TYPE node);
-node_asn *
-_asn1_set_down(node_asn *node,node_asn *down);
+ASN1_TYPE
+_asn1_set_down(ASN1_TYPE node, ASN1_TYPE down);
char *
-_asn1_get_name(node_asn *node);
+_asn1_get_name(ASN1_TYPE node);
-node_asn *
-_asn1_get_down(node_asn *node);
+ASN1_TYPE
+_asn1_get_down(ASN1_TYPE node);
-node_asn *
-_asn1_mod_type(node_asn *node,unsigned int value);
+ASN1_TYPE
+_asn1_mod_type(ASN1_TYPE node,unsigned int value);
void
-_asn1_remove_node(node_asn *node);
+_asn1_remove_node(ASN1_TYPE node);
void _asn1_delete_list(void);
char * _asn1_ltostr(long v,char *str);
-node_asn * _asn1_find_up(node_asn *node);
+ASN1_TYPE _asn1_find_up(ASN1_TYPE node);
asn1_retCode _asn1_change_integer_value(ASN1_TYPE node);
/* and CONST_ constants). */
/* Return: pointer to the new element. */
/******************************************************/
-node_asn *
+ASN1_TYPE
_asn1_add_node_only (unsigned int type)
{
- node_asn *punt;
+ ASN1_TYPE punt;
- punt = (node_asn *) _asn1_calloc (1, sizeof (node_asn));
+ punt = (ASN1_TYPE) _asn1_calloc (1, sizeof (struct node_asn_struct));
if (punt == NULL)
return NULL;
/* node: NODE_ASN element pointer. */
/* Return: NULL if not found. */
/******************************************************************/
-node_asn *
-_asn1_find_left (node_asn * node)
+ASN1_TYPE
+_asn1_find_left (ASN1_TYPE node)
{
if ((node == NULL) || (node->left == NULL) || (node->left->down == node))
return NULL;
char *vector_name)
{
FILE *file;
- node_asn *p;
+ ASN1_TYPE p;
unsigned long t;
file = fopen (output_file_name, "w");
asn1_array2tree (const ASN1_ARRAY_TYPE * array, ASN1_TYPE * definitions,
char *errorDescription)
{
- node_asn *p, *p_last = NULL;
+ ASN1_TYPE p, p_last = NULL;
unsigned long k;
int move;
asn1_retCode result;
asn1_retCode
asn1_delete_structure (ASN1_TYPE * structure)
{
- node_asn *p, *p2, *p3;
+ ASN1_TYPE p, p2, p3;
if (*structure == ASN1_TYPE_EMPTY)
return ASN1_ELEMENT_NOT_FOUND;
asn1_retCode
asn1_delete_element (ASN1_TYPE structure, const char *element_name)
{
- node_asn *p2, *p3, *source_node;
+ ASN1_TYPE p2, p3, source_node;
source_node = asn1_find_node (structure, element_name);
return asn1_delete_structure (&source_node);
}
-node_asn *
-_asn1_copy_structure3 (node_asn * source_node)
+ASN1_TYPE
+_asn1_copy_structure3 (ASN1_TYPE source_node)
{
- node_asn *dest_node, *p_s, *p_d, *p_d_prev;
+ ASN1_TYPE dest_node, p_s, p_d, p_d_prev;
int move;
if (source_node == NULL)
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
}
-node_asn *
-_asn1_copy_structure2 (node_asn * root, const char *source_name)
+static ASN1_TYPE
+_asn1_copy_structure2 (ASN1_TYPE root, const char *source_name)
{
- node_asn *source_node;
+ ASN1_TYPE source_node;
source_node = asn1_find_node (root, source_name);
asn1_retCode
-_asn1_type_choice_config (node_asn * node)
+_asn1_type_choice_config (ASN1_TYPE node)
{
- node_asn *p, *p2, *p3, *p4;
+ ASN1_TYPE p, p2, p3, p4;
int move, tlen;
if (node == NULL)
asn1_retCode
-_asn1_expand_identifier (node_asn ** node, node_asn * root)
+_asn1_expand_identifier (ASN1_TYPE * node, ASN1_TYPE root)
{
- node_asn *p, *p2, *p3;
- char name2[MAX_NAME_SIZE + 2];
+ ASN1_TYPE p, p2, p3;
+ char name2[ASN1_MAX_NAME_SIZE + 2];
int move;
if (node == NULL)
asn1_create_element (ASN1_TYPE definitions, const char *source_name,
ASN1_TYPE * element)
{
- node_asn *dest_node;
+ ASN1_TYPE dest_node;
int res;
dest_node = _asn1_copy_structure2 (definitions, source_name);
asn1_print_structure (FILE * out, ASN1_TYPE structure, const char *name,
int mode)
{
- node_asn *p, *root;
+ ASN1_TYPE p, root;
int k, indent = 0, len, len2, len3;
if (out == NULL)
asn1_retCode
asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num)
{
- node_asn *node, *p;
+ ASN1_TYPE node, p;
if (num == NULL)
return ASN1_GENERIC_ERROR;
const char *
asn1_find_structure_from_oid (ASN1_TYPE definitions, const char *oidValue)
{
- char definitionsName[MAX_NAME_SIZE], name[2 * MAX_NAME_SIZE + 1];
- char value[MAX_NAME_SIZE];
+ char definitionsName[ASN1_MAX_NAME_SIZE], name[2 * ASN1_MAX_NAME_SIZE + 1];
+ char value[ASN1_MAX_NAME_SIZE];
ASN1_TYPE p;
int len;
asn1_retCode result;
strcpy (name, definitionsName);
strcat (name, p->name);
- len = MAX_NAME_SIZE;
+ len = ASN1_MAX_NAME_SIZE;
result = asn1_read_value (definitions, name, value, &len);
if ((result == ASN1_SUCCESS) && (!strcmp (oidValue, value)))
#ifndef _STRUCTURE_H
#define _STRUCTURE_H
-asn1_retCode _asn1_create_static_structure(node_asn *pointer,
+asn1_retCode _asn1_create_static_structure(ASN1_TYPE pointer,
char* output_file_name,char *vector_name);
-node_asn* _asn1_copy_structure3(node_asn *source_node);
+ASN1_TYPE _asn1_copy_structure3(ASN1_TYPE source_node);
-node_asn* _asn1_copy_structure2(node_asn *root,const char *source_name);
+ASN1_TYPE _asn1_add_node_only(unsigned int type);
-node_asn * _asn1_add_node_only(unsigned int type);
-
-node_asn * _asn1_find_left(node_asn *node);
+ASN1_TYPE _asn1_find_left(ASN1_TYPE node);
#endif