*** empty log message ***
authorFabio Fiorina <fiorinaf@gnutls.org>
Mon, 7 Oct 2002 19:34:30 +0000 (19:34 +0000)
committerFabio Fiorina <fiorinaf@gnutls.org>
Mon, 7 Oct 2002 19:34:30 +0000 (19:34 +0000)
18 files changed:
NEWS
doc/Makefile.am
lib/coding.c
lib/decoding.c
lib/element.c
lib/errors.c
lib/errors.h
lib/int.h
lib/libtasn1.h
src/CertificateExample.c
src/CrlExample.c
src/asn1Coding.c
src/asn1Decoding.c
src/asn1Parser.c
tests/Test_parser.asn
tests/Test_parser.c
tests/Test_tree.asn
tests/Test_tree.c

diff --git a/NEWS b/NEWS
index 880b199..778b63a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Version 0.1.2
+- Added GeneralString type
+- Fixed a DER encoding bug when nested tags are used
+
 Version 0.1.1
 - Renamed to libtasn1
 - Functions which return a string for error description
index 8b5fffe..6b07988 100644 (file)
@@ -8,7 +8,7 @@ asn1.ps: $(TEX_OBJECTS)
        -$(LN_S) ../lib/asn1-api.tex .
        -latex asn1.tex && latex asn1.tex && dvips asn1.dvi -o asn1.ps
 
-asn1.html: $(TEX_OBJECTS)
+asn1.html: asn1.ps $(TEX_OBJECTS)
        -latex2html asn1.tex -no_navigation -split 0 -local_icons -html_version 3.2,math \
        -info "" -white
 
index 685a124..1911f3e 100644 (file)
@@ -324,7 +324,14 @@ _asn1_complete_explicit_tag(node_asn *node,unsigned char *der,int *counter)
 
   if(node->type&CONST_TAG){
     p=node->down;
-    while(p){
+    /* When there are nested tags we must complete them reverse to
+       the order they were created. This is because completing a tag
+       modifies alla date within it, including the incomplete tags 
+       which store buffer positions -- simon@josefsson.org 2002-09-06
+    */
+    while(p->right)
+      p=p->right;
+    while(p && p!=node->down->left){
       if(type_field(p->type)==TYPE_TAG){
        if(p->type&CONST_EXPLICIT){
          len2=strtol(p->name,NULL,10);
@@ -341,7 +348,7 @@ _asn1_complete_explicit_tag(node_asn *node,unsigned char *der,int *counter)
          }
        }
       }
-      p=p->right;
+      p=p->left;
     }
   }
 }
index c7bacb1..6e079bb 100644 (file)
@@ -893,6 +893,16 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName,
        counter+=len3+len2;
        move=RIGHT;
        break;
+      case TYPE_GENERALSTRING:
+       len2=_asn1_get_length_der(der+counter,&len3);
+       if(state==FOUND){
+         _asn1_set_value(p,der+counter,len3+len2);
+        
+         if(p==nodeFound) state=EXIT;
+       }
+       counter+=len3+len2;
+       move=RIGHT;
+       break;
       case TYPE_BIT_STRING:
        len2=_asn1_get_length_der(der+counter,&len3);
        if(state==FOUND){
index bd3a5e8..d8c4315 100644 (file)
@@ -110,7 +110,7 @@ _asn1_convert_integer(const char *value,unsigned char *value_out,int value_out_s
   *len=SIZEOF_UNSIGNED_LONG_INT-k;
 
 
-#ifdef DEBUG_INTEGER
+#ifdef LIBTASN1_DEBUG_INTEGER
   _libasn1_log("_asn1_convert_integer: valueIn=%s, lenOut=%d",value,*len);
   for(k=0;k<SIZEOF_UNSIGNED_LONG_INT;k++)
     _libasn1_log(", vOut[%d]=%d",k,value_out[k]);
index 57a500f..321cdc5 100644 (file)
 #endif
 
 
-#define LIBASN1_ERROR_ENTRY(name) \
+#define LIBTASN1_ERROR_ENTRY(name) \
        { #name, name }
 
-struct libasn1_error_entry {
+struct libtasn1_error_entry {
        char *name;
        int  number;
 };
-typedef struct libasn1_error_entry libasn1_error_entry;
-
-static libasn1_error_entry error_algorithms[] = {
-       LIBASN1_ERROR_ENTRY( ASN1_SUCCESS ),
-       LIBASN1_ERROR_ENTRY( ASN1_FILE_NOT_FOUND ),
-       LIBASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_FOUND ),
-       LIBASN1_ERROR_ENTRY( ASN1_IDENTIFIER_NOT_FOUND ),
-       LIBASN1_ERROR_ENTRY( ASN1_DER_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_VALUE_NOT_FOUND ),
-       LIBASN1_ERROR_ENTRY( ASN1_GENERIC_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_VALUE_NOT_VALID ),
-       LIBASN1_ERROR_ENTRY( ASN1_TAG_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_TAG_IMPLICIT ),
-       LIBASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
-       LIBASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
-       LIBASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
-       LIBASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
-       LIBASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_EMPTY ),
+typedef struct libtasn1_error_entry libtasn1_error_entry;
+
+static libtasn1_error_entry error_algorithms[] = {
+       LIBTASN1_ERROR_ENTRY( ASN1_SUCCESS ),
+       LIBTASN1_ERROR_ENTRY( ASN1_FILE_NOT_FOUND ),
+       LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_FOUND ),
+       LIBTASN1_ERROR_ENTRY( ASN1_IDENTIFIER_NOT_FOUND ),
+       LIBTASN1_ERROR_ENTRY( ASN1_DER_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_FOUND ),
+       LIBTASN1_ERROR_ENTRY( ASN1_GENERIC_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_VALID ),
+       LIBTASN1_ERROR_ENTRY( ASN1_TAG_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_TAG_IMPLICIT ),
+       LIBTASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
+       LIBTASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
+       LIBTASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
+       LIBTASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
+       LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_EMPTY ),
        {0}
 };
 
-#define LIBASN1_ERROR_LOOP(b) \
-        libasn1_error_entry *p; \
+#define LIBTASN1_ERROR_LOOP(b) \
+        libtasn1_error_entry *p; \
                 for(p = error_algorithms; p->name != NULL; p++) { b ; }
 
-#define LIBASN1_ERROR_ALG_LOOP(a) \
-                        LIBASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
+#define LIBTASN1_ERROR_ALG_LOOP(a) \
+                        LIBTASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
 
 
 
 /**
-  * libasn1_perror - prints a string to stderr with a description of an error
+  * libtasn1_perror - prints a string to stderr with a description of an error
   * @error: is an error returned by a libasn1 function. 
   *
   * This function is like perror(). The only difference is that it accepts an 
   * error returned by a libasn1 function. 
   **/
-void libasn1_perror(asn1_retCode error)
+void libtasn1_perror(asn1_retCode error)
 {
        char *ret = NULL;
 
        /* avoid prefix */
-       LIBASN1_ERROR_ALG_LOOP(ret =
+       LIBTASN1_ERROR_ALG_LOOP(ret =
                              _asn1_strdup(p->name + sizeof("ASN1_") - 1));
 
-       _libasn1_log( "LIBASN1 ERROR: %s\n", ret);
+       _libtasn1_log( "LIBTASN1 ERROR: %s\n", ret);
        
        _asn1_free( ret);
 }
 
 
 /**
-  * libasn1_strerror - Returns a string with a description of an error
-  * @error: is an error returned by a libasn1 function.
+  * 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 libasn1 function. 
   **/
-const char* libasn1_strerror(asn1_retCode error)
+const char* libtasn1_strerror(asn1_retCode error)
 {
        char *ret = NULL;
 
        /* avoid prefix */
-       LIBASN1_ERROR_ALG_LOOP(ret =
+       LIBTASN1_ERROR_ALG_LOOP(ret =
                              p->name + sizeof("ASN1_") - 1);
 
        return ret;
@@ -104,8 +104,8 @@ const char* libasn1_strerror(asn1_retCode error)
 
 /* this function will output a message.
  */
-#ifdef DEBUG
-void _libasn1_log( const char *fmt, ...) {
+#ifdef LIBTASN1_DEBUG
+void _libtasn1_log( const char *fmt, ...) {
  va_list args;
  char str[MAX_LOG_SIZE];
 
index 1e09211..140e977 100644 (file)
 #include "int.h"
 #include "errors_int.h"
 
-#ifdef DEBUG
+#ifdef LIBTASN1_DEBUG
 # ifdef __FILE__
 #  ifdef __LINE__
-#   define _libasn1_assert() fprintf(stderr, "LIBASN1_ASSERT: %s:%d\n", __FILE__,__LINE__);
+#   define _libtasn1_assert() fprintf(stderr, "LIBTASN1_ASSERT: %s:%d\n", __FILE__,__LINE__);
 #  else
-#   define _libasn1_assert() 
+#   define _libtasn1_assert() 
 #  endif
 # else /* __FILE__ defined */
-#  define _libasn1_assert() 
+#  define _libtasn1_assert() 
 # endif
 #else /* no debug */
-# define _libasn1_assert() 
+# define _libtasn1_assert() 
 #endif
 
-const char* libasn1_strerror(int error);
-void libasn1_perror(int error);
+const char* libtasn1_strerror(int error);
+void libtasn1_perror(int error);
 
-#ifdef DEBUG
- void _libasn1_log( const char *fmt, ...);
+#ifdef LIBTASN1_DEBUG
+ void _libtasn1_log( const char *fmt, ...);
 #else
-# define _libasn1_log ( ...)
+# define _libtasn1_log ( ...)
 #endif
 
 #endif /* ERRORS_H */
index 8cb5a15..7ebf51f 100644 (file)
--- a/lib/int.h
+++ b/lib/int.h
 #include <defines.h>
 
 
-#define DEBUG
+#define LIBTASN1_DEBUG
 /*
-#define DEBUG_PARSER
-#define DEBUG_INTEGER
+#define LIBTASN1_DEBUG_PARSER
+#define LIBTASN1_DEBUG_INTEGER
 */
 
 
index a794f17..2a7dcf7 100644 (file)
@@ -145,9 +145,9 @@ asn1_retCode asn1_expand_any_defined_by(ASN1_TYPE definitions,
 asn1_retCode asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
               const char *octetName,const char *objectName);
 
-const char* libasn1_strerror(asn1_retCode error);
+const char* libtasn1_strerror(asn1_retCode error);
 
-void libasn1_perror(asn1_retCode error);
+void libtasn1_perror(asn1_retCode error);
 
 #ifdef __cplusplus
 }
index 5996858..549804a 100644 (file)
@@ -498,7 +498,7 @@ main(int argc,char *argv[])
     result=asn1_parser2tree("pkix.asn",&PKIX1Implicit88,errorDescription);
 
   if(result != ASN1_SUCCESS){
-    libasn1_perror(result);
+    libtasn1_perror(result);
     printf("%s",errorDescription);
     exit(1);
   }
index e652c5d..b88abb0 100644 (file)
@@ -420,7 +420,7 @@ main(int argc,char *argv[])
     result=asn1_parser2tree("pkix.asn",&PKIX1Implicit88,errorDescription);
 
   if(result != ASN1_SUCCESS){
-    libasn1_perror(result);
+    libtasn1_perror(result);
     printf("%s\n",errorDescription);
     exit(1);
   }
index 65785d7..5d5f13d 100644 (file)
@@ -235,7 +235,7 @@ main(int argc,char *argv[])
    printf("asn1Coding: %s\n",errorDescription);
    break;
  default:
-   printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+   printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
  }
 
  if(asn1_result != ASN1_SUCCESS){
@@ -267,7 +267,7 @@ main(int argc,char *argv[])
      asn1_result=asn1_write_value(structure,varName,value,0); 
 
    if(asn1_result != ASN1_SUCCESS){
-     printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+     printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
      
      asn1_delete_structure(&definitions);
      asn1_delete_structure(&structure);
@@ -286,7 +286,7 @@ main(int argc,char *argv[])
 
  asn1_result=asn1_der_coding(structure,structureName,der,&der_len,
                              errorDescription);
- printf("\nCoding: %s\n\n",libasn1_strerror(asn1_result));
+ printf("\nCoding: %s\n\n",libtasn1_strerror(asn1_result));
  if(asn1_result!=ASN1_SUCCESS){
    printf("asn1Coding: %s\n",errorDescription);
 
index 0445027..928cdfb 100644 (file)
@@ -178,7 +178,7 @@ main(int argc,char *argv[])
    printf("asn1Decoding: %s\n",errorDescription);
    break;
  default:
-   printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+   printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
  }
 
  if(asn1_result != ASN1_SUCCESS){
@@ -220,7 +220,7 @@ main(int argc,char *argv[])
     
  asn1_result=asn1_create_element(definitions,typeName,&structure,varName);
  if(asn1_result != ASN1_SUCCESS){
-   printf("Structure creation: %s\n",libasn1_strerror(asn1_result));
+   printf("Structure creation: %s\n",libtasn1_strerror(asn1_result));
    asn1_delete_structure(&definitions);
 
    free(inputFileAsnName);
@@ -231,7 +231,7 @@ main(int argc,char *argv[])
  }
 
  asn1_result=asn1_der_decoding(&structure,der,der_len,errorDescription);
- printf("\nDecoding: %s\n",libasn1_strerror(asn1_result));
+ printf("\nDecoding: %s\n",libtasn1_strerror(asn1_result));
  if(asn1_result != ASN1_SUCCESS)
    printf("asn1Decoding: %s\n",errorDescription);
 
index 3083578..52f08bf 100644 (file)
@@ -187,7 +187,7 @@ main(int argc,char *argv[])
    printf("asn1Parser: %s\n",errorDescription);\r
    break;\r
  default:\r
-   printf("libasn1 ERROR: %s\n",libasn1_strerror(parse_result));\r
+   printf("libasn1 ERROR: %s\n",libtasn1_strerror(parse_result));\r
  }\r
 \r
 \r
index d108853..8290dc7 100644 (file)
@@ -12,8 +12,8 @@ BEGIN
 
 Sequence1 ::= SEQUENCE{
     int1     INTEGER,
-    int2     INTEGER
-
+    int2     INTEGER,
+    generic  GeneralString
 }
 
 
index 8236844..7c3a397 100644 (file)
@@ -81,7 +81,8 @@ test_type test_array[]={
   {12,"const1 INTEGER ::= 10",ASN1_SUCCESS,""},
   {12,"const1 INTEGER ::= v1",
    ASN1_SYNTAX_ERROR,_FILE_":12: parse error near 'v1'"},
-  
+  {16," generic generalstring",
+   ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'generalstring' not found"},  
 
 
   /* end */
@@ -145,7 +146,7 @@ main(int argc,char *argv[])
 
   if(result!=ASN1_SUCCESS){
     printf("File '%s' not correct\n",fileCorrectName);
-    libasn1_perror(result);
+    libtasn1_perror(result);
     printf("ErrorDescription = %s\n\n",errorDescription);
     exit(1);
   }
@@ -172,9 +173,9 @@ main(int argc,char *argv[])
       errorCounter++;
       printf("ERROR N. %d:\n",errorCounter);
       printf("  Line %d - %s\n",test->lineNumber,test->line);
-      printf("  Error expected: %s - %s\n",libasn1_strerror(test->errorNumber),
+      printf("  Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),
              test->errorDescription);
-      printf("  Error detected: %s - %s\n\n",libasn1_strerror(result),
+      printf("  Error detected: %s - %s\n\n",libtasn1_strerror(result),
              errorDescription);
     }
  
index 68fa0bf..1026dff 100644 (file)
@@ -64,6 +64,15 @@ BMPString ::= [UNIVERSAL 30] IMPLICIT OCTET STRING
 UTF8String ::= [UNIVERSAL 12] IMPLICIT OCTET STRING
         -- The content of this type conforms to RFC 2279.
 
+
+Test3 ::= SEQUENCE{
+     a      INTEGER,
+     b      [1] EXPLICIT GeneralString2
+}
+
+GeneralString2 ::= [2] EXPLICIT GeneralString
+
+
 END
 
 
index 6629d22..d5613de 100644 (file)
@@ -106,6 +106,21 @@ test_type test_array[]={
   {ACT_VISIT,"Seq","",ASN1_PRINT_ALL,ASN1_SUCCESS},
   {ACT_DELETE,"","",0,ASN1_SUCCESS},
 
+  /* Test GeneralString */
+  {ACT_CREATE,"TEST_TREE.Test3","test",0,ASN1_SUCCESS},
+  {ACT_WRITE,"test.a","1234",0,ASN1_SUCCESS},
+  {ACT_WRITE,"test.b","prova",5,ASN1_SUCCESS},
+  {ACT_ENCODING,"test",0,0,ASN1_SUCCESS},
+  {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
+  {ACT_DELETE,"","",0,ASN1_SUCCESS},
+  {ACT_CREATE,"TEST_TREE.Test3","test",0,ASN1_SUCCESS},
+  //{ACT_DECODING,0,0,0,ASN1_SUCCESS},
+  {ACT_DECODING_ELEMENT,"test.b",0,0,ASN1_SUCCESS},
+  {ACT_READ,"test.b","prova",5,ASN1_SUCCESS},
+  {ACT_VISIT,"test","",ASN1_PRINT_ALL,ASN1_SUCCESS},
+  {ACT_DELETE,"","",0,ASN1_SUCCESS},
+
+
   /* end */
   {ACT_NULL}
 
@@ -136,7 +151,7 @@ main(int argc,char *argv[])
     result=asn1_array2tree(Test_tree_asn1_tab,&definitions,errorDescription);
 
   if(result!=ASN1_SUCCESS){
-    libasn1_perror(result);
+    libtasn1_perror(result);
     printf("ErrorDescription = %s\n\n",errorDescription);
     exit(1);
   }
@@ -231,8 +246,8 @@ main(int argc,char *argv[])
        printf("ERROR N. %d:\n",errorCounter);
        printf("  Action %d - %s - %s - %d\n",test->action,test->par1,
               test->par2,test->par3);
-       printf("  Error expected: %s\n",libasn1_strerror(test->errorNumber));
-       printf("  Error detected: %s\n\n",libasn1_strerror(result));
+       printf("  Error expected: %s\n",libtasn1_strerror(test->errorNumber));
+       printf("  Error detected: %s\n\n",libtasn1_strerror(result));
       }
       break;
 
@@ -250,11 +265,11 @@ main(int argc,char *argv[])
        errorCounter++;
        printf("ERROR N. %d:\n",errorCounter);
        printf("  Action %d - %s\n",test->action,test->par1);
-       printf("  Error expected: %s - %d - ",libasn1_strerror(test->errorNumber),
+       printf("  Error expected: %s - %d - ",libtasn1_strerror(test->errorNumber),
                                              test->par3);
        for(k=0;k<test->par3;k++)
          printf("%02x",test->par2[k]); 
-       printf("\n  Error detected: %s - %d - ",libasn1_strerror(result),
+       printf("\n  Error detected: %s - %d - ",libtasn1_strerror(result),
                                           valueLen);
        for(k=0;k<valueLen;k++)
          printf("%02x",value[k]);