+Version 0.2.3
+- Chenge asn1_find_structure_from_oid prototype
+- Add ASN1_MEM_ALLOC_ERROR return value
+
Version 0.2.2
- Add vector length check in asn1_der_coding function
+- Add vector length check in asn1_der_coding function
- Add vector length check in asn1_read_value function
- Add asn1_check_version function
dnl libtasn1 Version
ASN1_MAJOR_VERSION=0
ASN1_MINOR_VERSION=2
-ASN1_MICRO_VERSION=2
+ASN1_MICRO_VERSION=3
ASN1_VERSION=$ASN1_MAJOR_VERSION.$ASN1_MINOR_VERSION.$ASN1_MICRO_VERSION
AC_DEFINE_UNQUOTED(ASN1_VERSION, "$ASN1_VERSION")
AM_CONFIG_HEADER(config.h)
dnl This is the library version
-ASN1_MOST_RECENT_INTERFACE=1
+ASN1_MOST_RECENT_INTERFACE=2
ASN1_CURRENT_INTERFACE_IMPLEMENTATION_NUMBER=$ASN1_MICRO_VERSION
-ASN1_OLDEST_INTERFACE=1
+ASN1_OLDEST_INTERFACE=2
AC_SUBST(ASN1_MAJOR_VERSION)
\chapter{ASN.1 structures handling}
\section{Introduction}
- This document describes the version 0.2.2 of library 'libtasn1' developed
+ This document describes the version 0.2.3 of library 'libtasn1' developed
for ASN1 (Abstract Syntax Notation One) structures management.
The main features of this library are:
\begin{itemize}
temp2=(unsigned char *)_asn1_alloca(len2+len3+len4);
if (temp2==NULL){
asn1_delete_structure(element);
- return ASN1_MEM_ERROR;
+ return ASN1_MEM_ALLOC_ERROR;
}
_asn1_octet_der(der+counter,len2+len3,temp2,&len4);
* 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.
+ *
**/
asn1_retCode
asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName,
if(nameLen>0) strcpy(currentName,(*structure)->name);
else{
asn1_delete_structure(structure);
- return ASN1_MEM_ERROR;
+ return ASN1_MEM_ERROR;
}
if(!(strcmp(currentName,elementName))){
state=FOUND;
temp2=(unsigned char *)_asn1_alloca(len2+len3+len4);
if (temp2==NULL){
asn1_delete_structure(structure);
- return ASN1_MEM_ERROR;
+ return ASN1_MEM_ALLOC_ERROR;
}
_asn1_octet_der(der+counter,len2+len3,temp2,&len4);
if(len==0){
if((isdigit(value[0])) || (value[0]=='-')){
value_temp=(unsigned char *)_asn1_alloca(SIZEOF_UNSIGNED_LONG_INT);
- if (value_temp==NULL) return ASN1_MEM_ERROR;
+ if (value_temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_convert_integer(value,value_temp,SIZEOF_UNSIGNED_LONG_INT, &len);
}
if(type_field(p->type)==TYPE_CONSTANT){
if((p->name) && (!strcmp(p->name,value))){
value_temp=(unsigned char *)_asn1_alloca(SIZEOF_UNSIGNED_LONG_INT);
- if (value_temp==NULL) return ASN1_MEM_ERROR;
+ if (value_temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_convert_integer(p->value,value_temp,SIZEOF_UNSIGNED_LONG_INT, &len);
break;
}
else{ /* len != 0 */
value_temp=(unsigned char *)_asn1_alloca(len);
- if (value_temp==NULL) return ASN1_MEM_ERROR;
+ if (value_temp==NULL) return ASN1_MEM_ALLOC_ERROR;
memcpy(value_temp,value,len);
}
_asn1_length_der(len-k,NULL,&len2);
temp=(unsigned char *)_asn1_alloca(len-k+len2);
- if (temp==NULL) return ASN1_MEM_ERROR;
+ if (temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_octet_der(value_temp+k,len-k,temp,&len2);
_asn1_set_value(node,temp,len2);
while(type_field(p->type)!=TYPE_DEFAULT) p=p->right;
if((isdigit(p->value[0])) || (p->value[0]=='-')){
default_temp=(unsigned char *)_asn1_alloca(SIZEOF_UNSIGNED_LONG_INT);
- if (default_temp==NULL) return ASN1_MEM_ERROR;
+ if (default_temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_convert_integer(p->value,default_temp,SIZEOF_UNSIGNED_LONG_INT,&len2);
}
if(type_field(p2->type)==TYPE_CONSTANT){
if((p2->name) && (!strcmp(p2->name,p->value))){
default_temp=(unsigned char *)_asn1_alloca(SIZEOF_UNSIGNED_LONG_INT);
- if (default_temp==NULL) return ASN1_MEM_ERROR;
+ if (default_temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_convert_integer(p2->value,default_temp,SIZEOF_UNSIGNED_LONG_INT,&len2);
break;
len=strlen(value);
_asn1_length_der(len,NULL,&len2);
temp=(unsigned char *)_asn1_alloca(len+len2);
- if (temp==NULL) return ASN1_MEM_ERROR;
+ if (temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_octet_der(value,len,temp,&len2);
_asn1_set_value(node,temp,len2);
len=strlen(value);
_asn1_length_der(len,NULL,&len2);
temp=(unsigned char *)_asn1_alloca(len+len2);
- if (temp==NULL) return ASN1_MEM_ERROR;
+ if (temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_octet_der(value,len,temp,&len2);
_asn1_set_value(node,temp,len2);
len=strlen(value);
_asn1_length_der((len>>3)+2,NULL,&len2);
temp=(unsigned char *)_asn1_alloca((len>>3)+2+len2);
- if (temp==NULL) return ASN1_MEM_ERROR;
+ if (temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_bit_der(value,len,temp,&len2);
_asn1_set_value(node,temp,len2);
case TYPE_ANY:
_asn1_length_der(len,NULL,&len2);
temp=(unsigned char *)_asn1_alloca(len+len2);
- if (temp==NULL) return ASN1_MEM_ERROR;
+ if (temp==NULL) return ASN1_MEM_ALLOC_ERROR;
_asn1_octet_der(value,len,temp,&len2);
_asn1_set_value(node,temp,len2);
* asn1_read_tag - Returns the TAG of one element inside a structure
* @root: pointer to a structure
* @name: the name of the element inside a structure.
- * @tag: variable that will contain the TAG value.
- * @class: variable that will specify the TAG type.
+ * @tagValue: variable that will contain the TAG value.
+ * @classValue: variable that will specify the TAG type.
*
* Description:
*
*
**/
asn1_retCode
-asn1_read_tag(node_asn *root,const char *name,int *tag, int *class)
+asn1_read_tag(node_asn *root,const char *name,int *tagValue, int *classValue)
{
node_asn *node,*p,*pTag;
}
if(pTag){
- *tag=strtoul(pTag->value,NULL,10);
+ *tagValue=strtoul(pTag->value,NULL,10);
- if(pTag->type&CONST_APPLICATION) *class=ASN1_CLASS_APPLICATION;
- else if(pTag->type&CONST_UNIVERSAL) *class=ASN1_CLASS_UNIVERSAL;
- else if(pTag->type&CONST_PRIVATE) *class=ASN1_CLASS_PRIVATE;
- else *class=ASN1_CLASS_CONTEXT_SPECIFIC;
+ if(pTag->type&CONST_APPLICATION) *classValue=ASN1_CLASS_APPLICATION;
+ else if(pTag->type&CONST_UNIVERSAL) *classValue=ASN1_CLASS_UNIVERSAL;
+ else if(pTag->type&CONST_PRIVATE) *classValue=ASN1_CLASS_PRIVATE;
+ else *classValue=ASN1_CLASS_CONTEXT_SPECIFIC;
}
else{
- *class=ASN1_CLASS_UNIVERSAL;
+ *classValue=ASN1_CLASS_UNIVERSAL;
switch(type_field(node->type)){
case TYPE_NULL:
- *tag=ASN1_TAG_NULL;break;
+ *tagValue=ASN1_TAG_NULL;break;
case TYPE_BOOLEAN:
- *tag=ASN1_TAG_BOOLEAN;break;
+ *tagValue=ASN1_TAG_BOOLEAN;break;
case TYPE_INTEGER:
- *tag=ASN1_TAG_INTEGER;break;
+ *tagValue=ASN1_TAG_INTEGER;break;
case TYPE_ENUMERATED:
- *tag=ASN1_TAG_ENUMERATED;break;
+ *tagValue=ASN1_TAG_ENUMERATED;break;
case TYPE_OBJECT_ID:
- *tag=ASN1_TAG_OBJECT_ID;break;
+ *tagValue=ASN1_TAG_OBJECT_ID;break;
case TYPE_TIME:
if(node->type&CONST_UTC){
- *tag=ASN1_TAG_UTCTime;
+ *tagValue=ASN1_TAG_UTCTime;
}
- else *tag=ASN1_TAG_GENERALIZEDTime;
+ else *tagValue=ASN1_TAG_GENERALIZEDTime;
break;
case TYPE_OCTET_STRING:
- *tag=ASN1_TAG_OCTET_STRING;break;
+ *tagValue=ASN1_TAG_OCTET_STRING;break;
case TYPE_GENERALSTRING:
- *tag=ASN1_TAG_GENERALSTRING;break;
+ *tagValue=ASN1_TAG_GENERALSTRING;break;
case TYPE_BIT_STRING:
- *tag=ASN1_TAG_BIT_STRING;break;
+ *tagValue=ASN1_TAG_BIT_STRING;break;
case TYPE_SEQUENCE: case TYPE_SEQUENCE_OF:
- *tag=ASN1_TAG_SEQUENCE;break;
+ *tagValue=ASN1_TAG_SEQUENCE;break;
case TYPE_SET: case TYPE_SET_OF:
- *tag=ASN1_TAG_SET;break;
+ *tagValue=ASN1_TAG_SET;break;
case TYPE_TAG:
case TYPE_CHOICE:
case TYPE_ANY:
LIBTASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
LIBTASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
LIBTASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_MEM_ALLOC_ERROR ),
LIBTASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
LIBTASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
LIBTASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
#define ASN1_ERROR_TYPE_ANY 10
#define ASN1_SYNTAX_ERROR 11
#define ASN1_MEM_ERROR 12
-#define ASN1_DER_OVERFLOW 13
-#define ASN1_NAME_TOO_LONG 14
-#define ASN1_ARRAY_ERROR 15
-#define ASN1_ELEMENT_NOT_EMPTY 16
+#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
#include <mem.h>
-#define LIBTASN1_VERSION "0.2.2"
+#define LIBTASN1_VERSION "0.2.3"
#define MAX32 4294967295
#define MAX24 16777215
extern "C" {
#endif
-#define LIBTASN1_VERSION "0.2.2"
+#define LIBTASN1_VERSION "0.2.3"
#include <sys/types.h>
#include <time.h>
#define ASN1_ERROR_TYPE_ANY 10
#define ASN1_SYNTAX_ERROR 11
#define ASN1_MEM_ERROR 12
-#define ASN1_DER_OVERFLOW 13
-#define ASN1_NAME_TOO_LONG 14
-#define ASN1_ARRAY_ERROR 15
-#define ASN1_ELEMENT_NOT_EMPTY 16
+#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 */
asn1_retCode asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
const char *octetName,const char *objectName);
-asn1_retCode asn1_read_tag(node_asn *root,const char *name,int *tag,
- int *class);
+asn1_retCode asn1_read_tag(node_asn *root,const char *name,int *tagValue,
+ int *classValue);
-asn1_retCode asn1_find_structure_from_oid(ASN1_TYPE definitions,
- const char *oidValue,char *structureName);
+const char* asn1_find_structure_from_oid(ASN1_TYPE definitions,
+ const char *oidValue);
const char *asn1_check_version( const char *req_version );
* after an OID definition.
* @definitions: ASN1 definitions
* @oidValue: value of the OID to search (e.g. "1.2.3.4").
- * @structureName: name returned by the function, that is the structure
- * defined just after the OID of value equal to OIDVALUE.
- * It must be an array of MAX_NAME_SIZE char elements.
- *
* Description:
*
* Search the structure that is defined just after an OID definition.
*
* Returns:
*
- * ASN1_SUCCESS\: structure found.
+ * NULL when OIDVALUE not found,
*
- * ASN1_ELEMENT_NOT_FOUND\: OID equal to OIDVALUE not found.
+ * otherwise the pointer to a constant string that contains the element
+ * name defined just after the OID.
*
**/
-asn1_retCode
+const char*
asn1_find_structure_from_oid(ASN1_TYPE definitions,
- const char *oidValue,char *structureName)
+ const char *oidValue)
{
char definitionsName[MAX_NAME_SIZE],name[2*MAX_NAME_SIZE+1];
char value[MAX_NAME_SIZE];
asn1_retCode result;
if((definitions==ASN1_TYPE_EMPTY) || (oidValue==NULL))
- return ASN1_ELEMENT_NOT_FOUND;
+ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
strcpy(definitionsName,definitions->name);
if((result == ASN1_SUCCESS) && (!strcmp(oidValue,value))){
p=p->right;
if(p==NULL) /* reach the end of ASN1 definitions */
- return ASN1_ELEMENT_NOT_FOUND;
+ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
- strcpy(structureName,p->name);
- return ASN1_SUCCESS;
+ return p->name;
}
}
p=p->right;
}
- return ASN1_ELEMENT_NOT_FOUND;
+ return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
}
int valueLen,tag=0,class=0;
int k;
int start,end;
+ const char *str_p=NULL;
printf("\n\n/****************************************/\n");
printf( "/* Test sequence : Test_tree */\n");
test->par2);
break;
case ACT_OID_2_STRUCTURE:
- result=asn1_find_structure_from_oid(definitions,test->par1,value);
+ str_p=asn1_find_structure_from_oid(definitions,test->par1);
break;
case ACT_VISIT:
asn1_print_structure(out,asn1_element,test->par1,test->par3);
}
break;
case ACT_OID_2_STRUCTURE:
- if((result != test->errorNumber) ||
- ((result == ASN1_SUCCESS) && (strcmp(value,test->par2)))){
+ if(((test->errorNumber!=ASN1_SUCCESS) && (str_p!=NULL)) ||
+ ((test->errorNumber==ASN1_SUCCESS) && (str_p==NULL)) ||
+ ((test->errorNumber==ASN1_SUCCESS) && (strcmp(str_p,test->par2)))){
errorCounter++;
printf("ERROR N. %d:\n",errorCounter);
printf(" Action %d - %s\n",test->action,test->par1);
- printf(" Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),
- test->par2);
- printf("\n Error detected: %s - %s\n\n",libtasn1_strerror(result),
- value);
+ printf(" Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),test->par2);
+ printf(" Value detected: %s\n\n",str_p);
}
break;
case ACT_DECODING_START_END: