shishi-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS shishi/asn1


From: shishi-commit
Subject: CVS shishi/asn1
Date: Thu, 16 Dec 2004 03:16:37 +0100

Update of /home/cvs/shishi/asn1
In directory dopio:/tmp/cvs-serv10884

Modified Files:
        coding.c decoding.c element.c errors.c int.h libtasn1.h 
        parser_aux.c structure.c 
Log Message:
Update.

--- /home/cvs/shishi/asn1/coding.c      2004/11/09 19:00:53     1.3
+++ /home/cvs/shishi/asn1/coding.c      2004/12/16 02:16:36     1.4
@@ -1,5 +1,6 @@
 /*
  *      Copyright (C) 2002  Fabio Fiorina
+ *      Copyright (C) 2004  Simon Josefsson
  *
  * This file is part of LIBASN1.
  *
@@ -246,7 +247,7 @@
 
   max_len=*der_len;
 
-  temp=(char *) _asn1_alloca(strlen(str)+2);
+  temp= (char *) _asn1_alloca(strlen(str)+2);
   if(temp==NULL) return ASN1_MEM_ALLOC_ERROR;
 
   strcpy(temp, str);
@@ -716,33 +717,37 @@
 /**
   * asn1_der_coding - Creates the DER encoding for the NAME structure
   * @element: pointer to an ASN1 element
-  * @name: the name of the structure you want to encode (it must be inside 
*POINTER).
-  * @ider: vector that will contain the DER encoding. DER must be a pointer to 
memory cells already allocated.
-  * @len: number of bytes of *der: der[0]..der[len-1], Initialy holds the 
sizeof of der vector.
-  * @errorDescription : return the error description or an empty string if 
success.
-  * Description:
+  * @name: the name of the structure you want to encode (it must be
+  *   inside *POINTER).
+  * @ider: vector that will contain the DER encoding. DER must be a
+  *   pointer to memory cells already allocated.
+  * @len: number of bytes of address@hidden: @address@hidden, Initialy
+  *   holds the sizeof of der vector.
+  * @errorDescription : return the error description or an empty
+  *   string if success.
+  *
+  * Creates the DER encoding for the NAME structure (inside *POINTER
+  * structure).
   *
-  * Creates the DER encoding for the NAME structure (inside *POINTER 
structure).
-  * 
   * Returns:
   *
-  *   ASN1_SUCCESS\: DER encoding OK
+  *   ASN1_SUCCESS: DER encoding OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: NAME is not a valid element.
+  *   ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
   *
-  *   ASN1_VALUE_NOT_FOUND\: there is an element without a value.
+  *   ASN1_VALUE_NOT_FOUND: There is an element without a value.
   *
-  *   ASN1_MEM_ERROR\: der vector isn't big enough. Also in this case LEN
-  *   will contain the length needed.
+  *   ASN1_MEM_ERROR: @ider vector isn't big enough. Also in this case
+  *     LEN will contain the length needed.
   *
   **/
-asn1_retCode 
+asn1_retCode
 asn1_der_coding(ASN1_TYPE element,const char *name,void *ider,int *len,
                 char *ErrorDescription)
 {
   node_asn *node,*p,*p2;
   char temp[SIZEOF_UNSIGNED_LONG_INT*3+1];
-  int counter,counter_old,len2,len3,move,max_len,max_len_old;
+  int counter,counter_old,len2,len3,tlen,move,max_len,max_len_old;
   asn1_retCode ris;
   unsigned char* der = ider;
 
@@ -875,7 +880,9 @@
     case TYPE_SEQUENCE: case TYPE_SET: 
       if(move!=UP){
        _asn1_ltostr(counter,temp);
-       _asn1_set_value(p,temp,strlen(temp)+1);
+       tlen = strlen(temp);
+       if (tlen > 0)
+          _asn1_set_value(p,temp,tlen+1);
        if(p->down==NULL){
          move=UP;
          continue;
@@ -910,7 +917,10 @@
     case TYPE_SEQUENCE_OF: case TYPE_SET_OF:
       if(move!=UP){
        _asn1_ltostr(counter,temp);
-       _asn1_set_value(p,temp,strlen(temp)+1);
+       tlen = strlen(temp);
+       
+       if (tlen > 0)
+          _asn1_set_value(p,temp,tlen+1);
        p=p->down;
        while((type_field(p->type)==TYPE_TAG) || 
(type_field(p->type)==TYPE_SIZE)) p=p->right;
        if(p->right){
--- /home/cvs/shishi/asn1/decoding.c    2004/11/09 19:00:53     1.5
+++ /home/cvs/shishi/asn1/decoding.c    2004/12/16 02:16:36     1.6
@@ -1,5 +1,6 @@
 /*
  *      Copyright (C) 2002 Fabio Fiorina
+ *      Copyright (C) 2004 Simon Josefsson
  *
  * This file is part of LIBASN1.
  *
@@ -489,23 +490,26 @@
 
 /**
   * asn1_der_decoding - Fill the structure *ELEMENT with values of a DER 
encoding string.
-  * @element: pointer to an ASN1 structure
-  * @ider: vector that contains the DER encoding. 
-  * @len: number of bytes of *der: der[0]..der[len-1]
-  * @errorDescription: null-terminated string contains details when an error 
occurred.
-  *
-  * Fill the structure *ELEMENT with values of a DER encoding string. The 
sructure must just be
-  * created with function 'create_stucture'.
-  * If an error occurs during the decoding procedure, the *ELEMENT is deleted
-  * and set equal to ASN1_TYPE_EMPTY.
+  * @element: pointer to an ASN1 structure.
+  * @ider: vector that contains the DER encoding.
+  * @len: number of bytes of address@hidden: @address@hidden
+  * @errorDescription: null-terminated string contains details when an
+  *   error occurred.
+  *
+  * Fill the structure *ELEMENT with values of a DER encoding
+  * string. The sructure must just be created with function
+  * 'create_stucture'.  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_SUCCESS: DER encoding OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: ELEMENT is ASN1_TYPE_EMPTY.
+  *   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. 
+  *   ASN1_TAG_ERROR,ASN1_DER_ERROR: The der encoding doesn't match
+  *     the structure NAME. *ELEMENT deleted.
   **/
 
 asn1_retCode
@@ -514,7 +518,7 @@
 {
   node_asn *node,*p,*p2,*p3;
   char temp[128];
-  int counter,len2,len3,len4,move,ris;
+  int counter,len2,len3,len4,move,ris,tlen;
   unsigned char class,*temp2;
   unsigned int tag;
   int indefinite, result;
@@ -686,7 +690,9 @@
        break;
       case TYPE_OBJECT_ID:
        _asn1_get_objectid_der(der+counter,&len2, temp, sizeof(temp));
-       _asn1_set_value(p,temp,strlen(temp)+1);
+       tlen = strlen(temp);
+       if( tlen > 0)
+          _asn1_set_value(p,temp,tlen+1);
        counter+=len2;
        move=RIGHT;
       break;
@@ -696,7 +702,9 @@
                asn1_delete_structure(element);
                return result;
        }
-       _asn1_set_value(p,temp,strlen(temp)+1);
+       tlen = strlen(temp);
+       if (tlen > 0)
+          _asn1_set_value(p,temp,tlen+1);
        counter+=len2;
        move=RIGHT;
        break;
@@ -743,7 +751,9 @@
          counter+=len2;
          if(len3>0){
            _asn1_ltostr(counter+len3,temp);
-           _asn1_set_value(p,temp,strlen(temp)+1);
+           tlen = strlen(temp);
+           if (tlen > 0)
+              _asn1_set_value(p,temp,tlen+1);
            move=DOWN; 
          }
          else if(len3==0){
@@ -801,7 +811,10 @@
          if(len3){
            if(len3>0){ /* definite length method */
            _asn1_ltostr(counter+len3,temp);
-           _asn1_set_value(p,temp,strlen(temp)+1);
+           tlen = strlen(temp);
+           
+           if (tlen > 0)
+              _asn1_set_value(p,temp,tlen+1);
            }
            else { /* indefinite length method */
              _asn1_set_value(p,"-1",3);              
@@ -910,25 +923,27 @@
   * asn1_der_decoding_element - Fill the element named ELEMENTNAME of the 
structure STRUCTURE with values of a DER encoding string.
   * @structure: pointer to an ASN1 structure
   * @elementName: name of the element to fill
-  * @ider: vector that contains the DER encoding of the whole structure. 
+  * @ider: vector that contains the DER encoding of the whole structure.
   * @len: number of bytes of *der: der[0]..der[len-1]
-  * @errorDescription: null-terminated string contains details when an error 
occurred.
-  * 
-  * Description:
-  *
-  * Fill the element named ELEMENTNAME with values of a DER encoding string. 
-  * The sructure must just be created with function 'create_stucture'.
-  * 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.
+  * @errorDescription: null-terminated string contains details when an
+  *   error occurred.
+  *
+  * Fill the element named ELEMENTNAME with values of a DER encoding
+  * string.  The sructure must just be created with function
+  * 'create_stucture'.  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_SUCCESS: DER encoding OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: ELEMENT is ASN1_TYPE_EMPTY or elementName == 
NULL.
+  *   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_TAG_ERROR,ASN1_DER_ERROR: The der encoding doesn't match
+  *   the structure STRUCTURE. *ELEMENT deleted.
   *
   **/
 asn1_retCode
@@ -938,7 +953,7 @@
   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;
-  int counter,len2,len3,len4,move,ris;
+  int counter,len2,len3,len4,move,ris, tlen;
   unsigned char class,*temp2;
   unsigned int tag;
   int indefinite, result;
@@ -1153,7 +1168,10 @@
       case TYPE_OBJECT_ID:
        if(state==FOUND){
          _asn1_get_objectid_der(der+counter,&len2, temp, sizeof(temp));
-         _asn1_set_value(p,temp,strlen(temp)+1);
+         tlen = strlen(temp);
+         
+         if (tlen > 0)
+            _asn1_set_value(p,temp,tlen+1);
          
          if(p==nodeFound) state=EXIT;
        }
@@ -1173,7 +1191,9 @@
                return result;
          }
 
-         _asn1_set_value(p,temp,strlen(temp)+1);
+         tlen = strlen(temp);
+         if (tlen > 0)
+            _asn1_set_value(p,temp,tlen+1);
          
          if(p==nodeFound) state=EXIT;
        }
@@ -1249,7 +1269,10 @@
            counter+=len2;
            if(len3>0){
              _asn1_ltostr(counter+len3,temp);
-             _asn1_set_value(p,temp,strlen(temp)+1);
+             tlen = strlen(temp);
+             
+             if(tlen > 0)
+                 _asn1_set_value(p,temp,tlen+1);
              move=DOWN;
            }
            else if(len3==0){
@@ -1301,7 +1324,10 @@
            counter+=len2;
            if(len3){
              _asn1_ltostr(counter+len3,temp);
-             _asn1_set_value(p,temp,strlen(temp)+1);
+             tlen = strlen(temp);
+             
+             if (tlen > 0)
+                 _asn1_set_value(p,temp,tlen+1);
              p2=p->down;
              while((type_field(p2->type)==TYPE_TAG) || 
(type_field(p2->type)==TYPE_SIZE)) p2=p2->right;
              if(p2->right==NULL) _asn1_append_sequence_set(p);
@@ -1489,26 +1515,31 @@
 /**
   * asn1_der_decoding_startEnd - Find the start and end point of an element in 
a DER encoding string.
   * @element: pointer to an ASN1 element
-  * @ider: vector that contains the DER encoding. 
-  * @len: number of bytes of *der: der[0]..der[len-1]
+  * @ider: vector that contains the DER encoding.
+  * @len: number of bytes of address@hidden: @address@hidden
   * @name_element: an element of NAME structure.
-  * @start: the position of the first byte of NAME_ELEMENT decoding 
(der[*start]) 
-  * @end: the position of the last byte of NAME_ELEMENT decoding (der[*end])
-  * Description:
-  * 
-  * 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
-  * happen that you want to find the piece of string concerning an element of 
the structure.
-  * 
+  * @start: the position of the first byte of NAME_ELEMENT decoding
+  *   (@ider[*start])
+  * @end: the position of the last byte of NAME_ELEMENT decoding
+  *  (@ider[*end])
+  *
+  * 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 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:
   *
-  *   ASN1_SUCCESS\: DER encoding OK
+  *   ASN1_SUCCESS: DER encoding OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: ELEMENT is ASN1_TYPE EMPTY  or NAME_ELEMENT is 
not a valid element.
+  *   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.
+  *   ASN1_TAG_ERROR,ASN1_DER_ERROR: the der encoding doesn't match
+  *   the structure ELEMENT.
   *
   **/
 asn1_retCode
@@ -1745,7 +1776,6 @@
   * asn1_expand_any_defined_by - Expand "ANY DEFINED BY" fields in structure.
   * @definitions: ASN1 definitions
   * @element: pointer to an ASN1 structure
-  * Description:
   *
   * Expands every "ANY DEFINED BY" element of a structure created from
   * a DER decoding process (asn1_der_decoding function). The element ANY
@@ -1756,11 +1786,12 @@
   *
   * Returns:
   *
-  *   ASN1_SUCCESS\: substitution OK
+  *   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.
   *
-  *   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. 
+  *   other errors: Result of der decoding process.
   **/
 
 asn1_retCode
@@ -1943,28 +1974,26 @@
   * @octetName: name of the OCTECT STRING field to expand.
   * @objectName: name of the OBJECT IDENTIFIER field to use to define
   *    the type for expansion.
-  * 
-  * Description:
   *
-  * 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.
+  * 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_SUCCESS: Substitution OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: OBJECTNAME or OCTETNAME are not correct.
+  *   ASN1_ELEMENT_NOT_FOUND: OBJECTNAME or OCTETNAME are not correct.
   *
-  *   ASN1_VALUE_NOT_VALID\: wasn't possible to find the type to use
+  *   ASN1_VALUE_NOT_VALID: Wasn't possible to find the type to use
   *       for expansion.
-  *    
-  *   other errors\: result of der decoding process. 
+  *
+  *   other errors: result of der decoding process.
   **/
 asn1_retCode
 asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
-                         const char *octetName,const char *objectName)
+                        const char *octetName,const char *objectName)
 {
   char name[2*MAX_NAME_SIZE+1],value[MAX_NAME_SIZE];
   asn1_retCode retCode=ASN1_SUCCESS,result;
--- /home/cvs/shishi/asn1/element.c     2004/11/09 19:00:53     1.3
+++ /home/cvs/shishi/asn1/element.c     2004/12/16 02:16:36     1.4
@@ -1,15 +1,16 @@
 /*
- *      Copyright (C) 2000,2001,2002,2003 Fabio Fiorina
+ *      Copyright (C) 2000, 2001, 2002, 2003 Fabio Fiorina
+ *      Copyright (C) 2004 Simon Josefsson
  *
  * This file is part of LIBASN1.
  *
  * 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 
+ * 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 
+ * 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.
  *
@@ -151,99 +152,115 @@
   * asn1_write_value - Set the value of one element inside a structure.
   * @node_root: pointer to a structure
   * @name: the name of the element inside the structure that you want to set.
-  * @ivalue: vector used to specify the value to set. If len is >0, 
-  * VALUE must be a two's complement form integer.
-  * if len=0 *VALUE must be a null terminated string with an integer value. 
-  * @len: number of bytes of *value to use to set the value: 
value[0]..value[len-1]
-  *  or 0 if value is a null terminated string
-  * Description:
+  * @ivalue: vector used to specify the value to set. If len is >0,
+  *   VALUE must be a two's complement form integer.  if len=0 *VALUE
+  *   must be a null terminated string with an integer value.
+  * @len: number of bytes of *value to use to set the value:
+  *   value[0]..value[len-1] or 0 if value is a null terminated string
   *
   * Set the value of one element inside a structure.
-  * 
-  * Returns:
-  * 
-  *   ASN1_SUCCESS\: set value OK
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: NAME is not a valid element.
+  * If an element is OPTIONAL and you want to delete it, you must use
+  * the value=NULL and len=0.  Using "pkix.asn":
+  *
+  * result=asn1_write_value(cert, "tbsCertificate.issuerUniqueID",
+  * NULL, 0);
+  *
+  * Description for each type:
+  *
+  * INTEGER: VALUE must contain a two's complement form integer.
+  *
+  *            value[0]=0xFF ,               len=1 -> integer=-1.
+  *            value[0]=0xFF value[1]=0xFF , len=2 -> integer=-1.
+  *            value[0]=0x01 ,               len=1 -> integer= 1.
+  *            value[0]=0x00 value[1]=0x01 , len=2 -> integer= 1.
+  *            value="123"                 , len=0 -> integer= 123.
+  *
+  * ENUMERATED: As INTEGER (but only with not negative numbers).
+  *
+  * BOOLEAN: VALUE must be the null terminated string "TRUE" or
+  *   "FALSE" and LEN != 0.
+  *
+  *            value="TRUE" , len=1 -> boolean=TRUE.
+  *            value="FALSE" , len=1 -> boolean=FALSE.
+  *
+  * OBJECT IDENTIFIER: VALUE must be a null terminated string with
+  *   each number separated by a dot (e.g. "1.2.3.543.1").  LEN != 0.
+  *
+  *            value="1 2 840 10040 4 3" , len=1 -> OID=dsa-with-sha.
   *
-  *   ASN1_VALUE_NOT_VALID\: VALUE has a wrong format.
-  * 
-  * Examples:  
-  *   description for each type
+  * UTCTime: VALUE must be a null terminated string in one of these
+  *   formats: "YYMMDDhhmmssZ", "YYMMDDhhmmssZ",
+  *   "YYMMDDhhmmss+hh'mm'", "YYMMDDhhmmss-hh'mm'",
+  *   "YYMMDDhhmm+hh'mm'", or "YYMMDDhhmm-hh'mm'".  LEN != 0.
   *
-  *\begin{itemize}
-  * \item INTEGER\: VALUE must contain a two's complement form integer.
-  *            value[0]=0xFF ,               len=1 -> integer=-1
-  *            value[0]=0xFF value[1]=0xFF , len=2 -> integer=-1
-  *            value[0]=0x01 ,               len=1 -> integer= 1
-  *            value[0]=0x00 value[1]=0x01 , len=2 -> integer= 1
-  *            value="123"                 , len=0 -> integer= 123
+  *            value="9801011200Z" , len=1 -> time=Jannuary 1st, 1998
+  *            at 12h 00m Greenwich Mean Time
   *
-  * \item ENUMERATED\: as INTEGER (but only with not negative numbers)
+  * GeneralizedTime: VALUE must be in one of this format:
+  *   "YYYYMMDDhhmmss.sZ", "YYYYMMDDhhmmss.sZ",
+  *   "YYYYMMDDhhmmss.s+hh'mm'", "YYYYMMDDhhmmss.s-hh'mm'",
+  *   "YYYYMMDDhhmm+hh'mm'", or "YYYYMMDDhhmm-hh'mm'" where ss.s
+  *   indicates the seconds with any precision like "10.1" or "01.02".
+  *   LEN != 0
   *
-  * \item BOOLEAN\: VALUE must be the null terminated string "TRUE" or "FALSE" 
and LEN != 0
-  *            value="TRUE" , len=1 -> boolean=TRUE
-  *            value="FALSE" , len=1 -> boolean=FALSE
+  *            value="2001010112001.12-0700" , len=1 -> time=Jannuary
+  *            1st, 2001 at 12h 00m 01.12s Pacific Daylight Time
   *
-  * \item OBJECT IDENTIFIER\: VALUE must be a null terminated string with each 
number separated by
-  *                      a dot (e.g. "1.2.3.543.1"). 
-  *                      LEN != 0
-  *            value="1 2 840 10040 4 3" , len=1 -> OID=dsa-with-sha
+  * OCTET STRING: VALUE contains the octet string and LEN is the
+  *   number of octets.
   *
-  * \item UTCTime\: VALUE must be a null terminated string in one of these 
formats\:
-  *            "YYMMDDhhmmssZ" "YYMMDDhhmmssZ" "YYMMDDhhmmss+hh'mm'" 
"YYMMDDhhmmss-hh'mm'"
-  *            "YYMMDDhhmm+hh'mm'" "YYMMDDhhmm-hh'mm'".  
-  *            LEN != 0
-  *            value="9801011200Z" , len=1 -> time=Jannuary 1st, 1998 at 12h 
00m  Greenwich Mean Time
+  *            value="$\backslash$x01$\backslash$x02$\backslash$x03" ,
+  *            len=3 -> three bytes octet string
   *
-  * \item GeneralizedTime\: VALUE must be in one of this format\:
-  *                    "YYYYMMDDhhmmss.sZ" "YYYYMMDDhhmmss.sZ" 
"YYYYMMDDhhmmss.s+hh'mm'" 
-  *                    "YYYYMMDDhhmmss.s-hh'mm'" "YYYYMMDDhhmm+hh'mm'" 
"YYYYMMDDhhmm-hh'mm'" 
-  *                    where ss.s indicates the seconds with any precision 
like "10.1" or "01.02".
-  *                    LEN != 0
-  *            value="2001010112001.12-0700" , len=1 -> time=Jannuary 1st, 
2001 at 12h 00m 01.12s 
-  *                                                     Pacific Daylight Time
+  * GeneralString: VALUE contains the generalstring and LEN is the
+  *   number of octets.
   *
-  * \item OCTET STRING\: VALUE contains the octet string and LEN is the number 
of octets.
-  *            value="$\backslash$x01$\backslash$x02$\backslash$x03" , len=3  
-> three bytes octet string
+  *            value="$\backslash$x01$\backslash$x02$\backslash$x03" ,
+  *            len=3 -> three bytes generalstring
   *
-  * \item GeneralString\: VALUE contains the generalstring and LEN is the 
number of octets.
-  *            value="$\backslash$x01$\backslash$x02$\backslash$x03" , len=3  
-> three bytes generalstring
+  * BIT STRING: VALUE contains the bit string organized by bytes and
+  *   LEN is the number of bits.
   *
-  * \item BIT STRING\: VALUE contains the bit string organized by bytes and 
LEN is the number of bits.
-  *            value="$\backslash$xCF" , len=6 -> bit string="110011" (six 
bits)
+  *   value="$\backslash$xCF" , len=6 -> bit string="110011" (six
+  *   bits)
   *
-  * \item CHOICE\: if NAME indicates a choice type, VALUE must specify one of 
the alternatives with a
-  *           null terminated string. LEN != 0
-  *           Using "pkix.asn"\:
-  *           
result=asn1_write_value(cert,"certificate1.tbsCertificate.subject","rdnSequence",1);
+  * CHOICE: if NAME indicates a choice type, VALUE must specify one of
+  *   the alternatives with a null terminated string. LEN != 0. Using
+  *   "pkix.asn"\:
   *
-  * \item ANY\: VALUE indicates the der encoding of a structure.
-  *        LEN != 0 
+  *           result=asn1_write_value(cert,
+  *           "certificate1.tbsCertificate.subject", "rdnSequence",
+  *           1);
   *
-  * \item SEQUENCE OF\: VALUE must be the null terminated string "NEW" and LEN 
!= 0. With this 
-  *                instruction another element is appended in the sequence. 
The name of this
-  *                element will be "?1" if it's the first one, "?2" for the 
second and so on.
+  * ANY: VALUE indicates the der encoding of a structure.  LEN != 0.
   *
-  *           Using "pkix.asn"\:   
+  * SEQUENCE OF: VALUE must be the null terminated string "NEW" and
+  *   LEN != 0. With this instruction another element is appended in
+  *   the sequence. The name of this element will be "?1" if it's the
+  *   first one, "?2" for the second and so on.
   *
-  *           
result=asn1_write_value(cert,"certificate1.tbsCertificate.subject.rdnSequence","NEW",1);
+  *   Using "pkix.asn"\:
   *
-  * \item SET OF\: the same as SEQUENCE OF. 
-  *           Using "pkix.asn":
+  *   result=asn1_write_value(cert,
+  *   "certificate1.tbsCertificate.subject.rdnSequence", "NEW", 1);
   *
-  *           
result=asn1_write_value(cert,"tbsCertificate.subject.rdnSequence.?LAST","NEW",1);
-  *\end{itemize}
+  * SET OF: the same as SEQUENCE OF.  Using "pkix.asn":
   *
-  * If an element is OPTIONAL and you want to delete it, you must use the 
value=NULL and len=0.
+  *           result=asn1_write_value(cert,
+  *           "tbsCertificate.subject.rdnSequence.?LAST", "NEW", 1);
   *
-  *           Using "pkix.asn"\:
+  * Returns:
+  *
+  *   ASN1_SUCCESS: Set value OK.
+  *
+  *   ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
+  *
+  *   ASN1_VALUE_NOT_VALID: VALUE has a wrong format.
   *
-  *           
result=asn1_write_value(cert,"tbsCertificate.issuerUniqueID",NULL,0);
-  * 
   **/
-asn1_retCode 
-asn1_write_value(node_asn *node_root,const char *name,
+asn1_retCode
+asn1_write_value(ASN1_TYPE node_root,const char *name,
                 const void *ivalue,int len)
 {
   node_asn *node,*p,*p2;
@@ -532,70 +549,72 @@
 
 /**
   * asn1_read_value - Returns the value of one element inside a structure
-  * @root: pointer to a structure
+  * @root: pointer to a structure.
   * @name: the name of the element inside a structure that you want to read.
-  * @ivalue: vector that will contain the element's content. 
-  * VALUE must be a pointer to memory cells already allocated.
-  * @len: number of bytes of *value: value[0]..value[len-1]. Initialy holds 
the sizeof value.
-  *
-  * Description:
+  * @ivalue: vector that will contain the element's content, must be a
+  *   pointer to memory cells already allocated.
+  * @len: number of bytes of *value: value[0]..value[len-1]. Initialy
+  *   holds the sizeof value.
   *
   * Returns the value of one element inside a structure.
-  * 
-  * Returns:
-  *
-  *   ASN1_SUCCESS\: set value OK
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: NAME is not a valid element.
+  * If an element is OPTIONAL and the function "read_value" returns
+  * %ASN1_ELEMENT_NOT_FOUND, it means that this element wasn't present
+  * in the der encoding that created the structure.  The first element
+  * of a SEQUENCE_OF or SET_OF is named "?1". The second one "?2" and
+  * so on.
   *
-  *   ASN1_VALUE_NOT_FOUND\: there isn't any value for the element selected.
+  * INTEGER: VALUE will contain a two's complement form integer.
   *
-  *   ASN1_MEM_ERROR\: the value vector isn't big enough to store the result.
-  *   In this case LEN will contain the number of bytes needed.
-  * 
-  * Examples: 
-  *   a description for each type
+  *            integer=-1  -> value[0]=0xFF , len=1.
+  *            integer=1   -> value[0]=0x01 , len=1.
   *
-  *\begin{itemize}
-  * \item INTEGER\: VALUE will contain a two's complement form integer.
-  *            integer=-1  -> value[0]=0xFF , len=1
-  *            integer=1   -> value[0]=0x01 , len=1
+  * ENUMERATED: As INTEGER (but only with not negative numbers).
   *
-  * \item ENUMERATED\: as INTEGER (but only with not negative numbers)
+  * BOOLEAN: VALUE will be the null terminated string "TRUE" or
+  *   "FALSE" and LEN=5 or LEN=6.
   *
-  * \item BOOLEAN\: VALUE will be the null terminated string "TRUE" or "FALSE" 
and LEN=5 or LEN=6
+  * OBJECT IDENTIFIER: VALUE will be a null terminated string with
+  *   each number separated by a dot (i.e. "1.2.3.543.1").
   *
-  * \item OBJECT IDENTIFIER\: VALUE will be a null terminated string with each 
number separated by
-  *                      a dot (i.e. "1.2.3.543.1"). 
   *                      LEN = strlen(VALUE)+1
   *
-  * \item UTCTime\: VALUE will be a null terminated string in one of these 
formats\: 
-  *            "YYMMDDhhmmss+hh'mm'" or "YYMMDDhhmmss-hh'mm'"
-  *            LEN=strlen(VALUE)+1
-  *
-  * \item GeneralizedTime\: VALUE will be a null terminated string in the same 
format used to set
-  *                    the value
-  *
-  * \item OCTET STRING\: VALUE will contain the octet string and LEN will be 
the number of octets.
-  *
-  * \item GeneralString\: VALUE will contain the generalstring and LEN will be 
the number of octets.
-  *
-  * \item BIT STRING\: VALUE will contain the bit string organized by bytes 
and LEN will be the 
-  *               number of bits.
-  *
-  * \item CHOICE\: if NAME indicates a choice type, VALUE will specify the 
alternative selected
-  *
-  * \item ANY\: if NAME indicates an any type, VALUE will indicate the DER 
encoding of the structure 
-  *        actually used.
-  *\end{itemize}
-  * 
-  * If an element is OPTIONAL and the function "read_value" returns 
ASN1_ELEMENT_NOT_FOUND, it 
-  * means that this element wasn't present in the der encoding that created 
the structure.
-  * The first element of a SEQUENCE_OF or SET_OF is named "?1". The second one 
"?2" and so on.
-  * 
+  * UTCTime: VALUE will be a null terminated string in one of these
+  *   formats: "YYMMDDhhmmss+hh'mm'" or "YYMMDDhhmmss-hh'mm'".
+  *   LEN=strlen(VALUE)+1.
+  *
+  * GeneralizedTime: VALUE will be a null terminated string in the
+  *   same format used to set the value.
+  *
+  * OCTET STRING: VALUE will contain the octet string and LEN will be
+  *   the number of octets.
+  *
+  * GeneralString: VALUE will contain the generalstring and LEN will
+  *   be the number of octets.
+  *
+  * BIT STRING: VALUE will contain the bit string organized by bytes
+  *   and LEN will be the number of bits.
+  *
+  * CHOICE: If NAME indicates a choice type, VALUE will specify the
+  *   alternative selected.
+  *
+  * ANY: If NAME indicates an any type, VALUE will indicate the DER
+  *   encoding of the structure actually used.
+  *
+  * Returns:
+  *
+  *   ASN1_SUCCESS: Set value OK.
+  *
+  *   ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
+  *
+  *   ASN1_VALUE_NOT_FOUND: There isn't any value for the element selected.
+  *
+  *   ASN1_MEM_ERROR: The value vector isn't big enough to store the result.
+  *   In this case LEN will contain the number of bytes needed.
+  *
   **/
-asn1_retCode 
-asn1_read_value(node_asn *root,const char *name,void* ivalue, int *len)
+asn1_retCode
+asn1_read_value(ASN1_TYPE root,const char *name,void* ivalue, int *len)
 {
   node_asn *node,*p,*p2;
   int len2,len3;
@@ -720,21 +739,20 @@
   * 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.
-  * @tagValue:  variable that will contain the TAG value. 
+  * @tagValue:  variable that will contain the TAG value.
   * @classValue: variable that will specify the TAG type.
   *
-  * Description:
-  *
   * Returns the TAG and the CLASS of one element inside a structure.
-  * CLASS can have one of these constants: ASN1_CLASS_APPLICATION,
-  * ASN1_CLASS_UNIVERSAL, ASN1_CLASS_PRIVATE or ASN1_CLASS_CONTEXT_SPECIFIC.
-  * 
+  * CLASS can have one of these constants: %ASN1_CLASS_APPLICATION,
+  * %ASN1_CLASS_UNIVERSAL, %ASN1_CLASS_PRIVATE or
+  * %ASN1_CLASS_CONTEXT_SPECIFIC.
+  *
   * Returns:
   *
-  *   ASN1_SUCCESS\: set value OK
+  *   ASN1_SUCCESS: Set value OK.
+  *
+  *   ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: NAME is not a valid element.
-  * 
   **/
 asn1_retCode 
 asn1_read_tag(node_asn *root,const char *name,int *tagValue, int *classValue)
--- /home/cvs/shishi/asn1/errors.c      2004/11/09 19:00:53     1.2
+++ /home/cvs/shishi/asn1/errors.c      2004/12/16 02:16:36     1.3
@@ -66,10 +66,10 @@
 
 /**
   * libtasn1_perror - prints a string to stderr with a description of an error
-  * @error: is an error returned by a libasn1 function. 
+  * @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. 
+  * This function is like perror(). The only difference is that it
+  * accepts an error returned by a libasn1 function.
   **/
 void libtasn1_perror(asn1_retCode error)
 {
@@ -88,8 +88,8 @@
   * 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.
+  * This function is similar to strerror(). The only difference is
+  * that it accepts an error (number) returned by a libasn1 function.
   *
   * Returns: Pointer to static zero-terminated string describing error
   *   code.
@@ -114,7 +114,7 @@
 
  va_start(args,fmt);
  vsprintf( str,fmt,args); /* Flawfinder: ignore */
- va_end(args);   
+ va_end(args);
 
  fprintf(stderr, str);
 
--- /home/cvs/shishi/asn1/int.h 2004/11/09 19:00:53     1.7
+++ /home/cvs/shishi/asn1/int.h 2004/12/16 02:16:36     1.8
@@ -1,4 +1,5 @@
 /*
+ *      Copyright (C) 2004 Simon Josefsson
  *      Copyright (C) 2002 Fabio Fiorina
  *
  * This file is part of LIBASN1.
@@ -19,9 +20,10 @@
  */
 
 #ifndef INT_H
-
 #define INT_H
 
+#include <libtasn1.h>
+
 #include <defines.h>
 
 /*
@@ -32,8 +34,6 @@
 
 #include <mem.h>
 
-#define LIBTASN1_VERSION "0.2.11"
-
 #define MAX32 4294967295
 #define MAX24 16777215
 #define MAX16 65535
@@ -42,73 +42,16 @@
 #define MAX_NAME_SIZE 128 /* maximum number of characters of a name inside an 
ASN1 file definiton */
 #define MAX_ERROR_DESCRIPTION_SIZE 128 /* maximum number of characters of a 
description message */
 
-/*****************************************/
-/* Constants returned by asn1_read_tag   */
-/*****************************************/
-#define ASN1_CLASS_UNIVERSAL        1
-#define ASN1_CLASS_APPLICATION      2
-#define ASN1_CLASS_CONTEXT_SPECIFIC 3
-#define ASN1_CLASS_PRIVATE          4
-
-
-/*****************************************/
-/* 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
-
-
 /* define used for visiting trees */
 #define UP     1
 #define RIGHT  2
 #define DOWN   3
 
-
-typedef int asn1_retCode;  /* type returned by libasn1 functions */
-
-
-/******************************************************/
-/* Structure definition used for the node of the tree */
-/* that represent an ASN.1 DEFINITION.               */
-/******************************************************/
-typedef struct node_asn_struct{
-  char *name;                    /* Node name */
-  unsigned int type;             /* Node type */
-  unsigned char *value;          /* Node value */
-  struct node_asn_struct *down;  /* Pointer to the son node */
-  struct node_asn_struct *right; /* Pointer to the brother node */
-  struct node_asn_struct *left;  /* Pointer to the next list element */ 
-} node_asn;
-
-typedef node_asn* ASN1_TYPE;
-
-#define ASN1_TYPE_EMPTY  NULL
-
-struct static_struct_asn{
-  char *name;                    /* Node name */
-  unsigned int type;             /* Node type */
-  unsigned char *value;          /* Node value */
-};
-
-typedef struct static_struct_asn ASN1_ARRAY_TYPE;
-
-
 /****************************************/
 /* Returns the first 8 bits.            */
 /* Used with the field type of node_asn */
 /****************************************/
-#define type_field(x)     (x&0xFF) 
-
+#define type_field(x)     (x&0xFF)
 
 /* List of constants for field type of typedef node_asn  */
 #define TYPE_CONSTANT       1
@@ -172,26 +115,4 @@
 #define CONST_DOWN        (1<<29)
 #define CONST_RIGHT       (1<<30)
 
-
-/* functions */
-asn1_retCode asn1_delete_structure(ASN1_TYPE *structure);
-
-asn1_retCode asn1_create_element(ASN1_TYPE definitions,const char *source_name,
-                                 ASN1_TYPE *element);
-
-asn1_retCode asn1_read_value(ASN1_TYPE element,const char *name,
-                            void *value,int *len);
-
-asn1_retCode
-asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
-                         const char *octetName,const char *objectName);
-
-asn1_retCode
-asn1_expand_any_defined_by(ASN1_TYPE definitions,ASN1_TYPE *element);
-
-asn1_retCode
-asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len,
-                 char *errorDescription);
-
-
 #endif /* INT_H */
--- /home/cvs/shishi/asn1/libtasn1.h    2004/11/09 19:00:53     1.7
+++ /home/cvs/shishi/asn1/libtasn1.h    2004/12/16 02:16:36     1.8
@@ -1,5 +1,6 @@
 /*
  *      Copyright (C) 2002 Fabio Fiorina
+ *      Copyright (C) 2004 Simon Josefsson
  *
  * This file is part of LIBTASN1.
  *
@@ -28,7 +29,7 @@
 extern "C" {
 #endif
 
-#define LIBTASN1_VERSION "0.2.11"
+#define LIBTASN1_VERSION "0.2.13"
 
 #include <sys/types.h>
 #include <time.h>
@@ -147,10 +148,10 @@
 
 asn1_retCode asn1_delete_element(ASN1_TYPE structure,const char *element_name);
 
-asn1_retCode asn1_write_value(ASN1_TYPE *node_root,const char *name,
+asn1_retCode asn1_write_value(ASN1_TYPE node_root,const char *name,
                              const void *ivalue,int len);
 
-asn1_retCode asn1_read_value(ASN1_TYPE *root,const char *name,
+asn1_retCode asn1_read_value(ASN1_TYPE root,const char *name,
                             void* ivalue,int *len);
 
 asn1_retCode asn1_number_of_elements(ASN1_TYPE element,const char *name,int 
*num);
--- /home/cvs/shishi/asn1/parser_aux.c  2004/11/09 19:00:53     1.2
+++ /home/cvs/shishi/asn1/parser_aux.c  2004/12/16 02:16:36     1.3
@@ -1,5 +1,6 @@
 /*
  *      Copyright (C) 2000,2001 Fabio Fiorina
+ *      Copyright (C) 2004 Simon Josefsson
  *
  * This file is part of LIBASN1.
  *
@@ -519,7 +520,7 @@
 {
   node_asn *p,*p2,*p3,*p4,*p5;
   char name_root[MAX_NAME_SIZE],name2[2*MAX_NAME_SIZE+1];
-  int move;
+  int move, tlen;
  
   if(node==NULL) return ASN1_ELEMENT_NOT_FOUND;
 
@@ -548,7 +549,9 @@
              if(type_field(p4->type)==TYPE_CONSTANT){
                p5=_asn1_add_node_only(TYPE_CONSTANT);
                _asn1_set_name(p5,p4->name);
-               _asn1_set_value(p5,p4->value,strlen(p4->value)+1);
+               tlen = strlen( p4->value);
+               if (tlen > 0)
+                   _asn1_set_value(p5,p4->value,tlen+1);
                if(p2==p){
                  _asn1_set_right(p5,p->down);
                  _asn1_set_down(p,p5);
@@ -612,7 +615,9 @@
            }
            p4=p4->right;
          }
-         _asn1_set_value(p2,name2,strlen(name2)+1);
+         tlen = strlen(name2);
+         if (tlen > 0)
+             _asn1_set_value(p2,name2,tlen+1);
        }
       }
       move=DOWN;
@@ -868,17 +873,19 @@
 }
 
 /**
-  * asn1_check_version - This function checks the library's version
-  * @req_version: the version to check
-  *
-  * Check library version.
-  *
-  * Return value: Check that the the version of the library is at
-  *   minimum the one given as a string in @req_version and return the
-  *   actual version string of the library; return NULL if the
-  *   condition is not met.  If %NULL is passed to this function no
-  *   check is done and only the version string is returned.
-  **/
+ * asn1_check_version - check for library version
+ * @req_version: Required version number, or NULL.
+ *
+ * Check that the 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 %LIBTASN1_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 )
 {
--- /home/cvs/shishi/asn1/structure.c   2004/11/09 19:00:53     1.3
+++ /home/cvs/shishi/asn1/structure.c   2004/12/16 02:16:36     1.4
@@ -1,15 +1,16 @@
 /*
  *      Copyright (C) 2002  Fabio Fiorina
+ *      Copyright (C) 2004  Simon Josefsson
  *
  * This file is part of LIBASN1.
  *
  * 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 
+ * 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 
+ * 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.
  *
@@ -39,7 +40,7 @@
 
 /******************************************************/
 /* Function : _asn1_add_node_only                     */
-/* Description: creates a new NODE_ASN element.       */ 
+/* Description: creates a new NODE_ASN element.       */
 /* Parameters:                                        */
 /*   type: type of the new element (see TYPE_         */
 /*         and CONST_ constants).                     */
@@ -55,10 +56,10 @@
   
   punt->left=NULL;
   punt->name=NULL;
-  punt->type=type; 
+  punt->type=type;
   punt->value=NULL;
   punt->down=NULL;
-  punt->right=NULL; 
+  punt->right=NULL;
 
   return punt;
 }
@@ -75,22 +76,22 @@
 node_asn *
 _asn1_find_left(node_asn *node)
 {
-  if((node==NULL) || (node->left==NULL) || 
+  if((node==NULL) || (node->left==NULL) ||
      (node->left->down==node)) return NULL;
 
-  return node->left;  
+  return node->left;
 }
 
 
 asn1_retCode
 _asn1_create_static_structure(ASN1_TYPE pointer,char* output_file_name,char 
*vector_name)
 {
-  FILE *file;  
+  FILE *file;
   node_asn *p;
   unsigned long t;
 
   file=fopen( output_file_name,"w");
-  
+
   if(file==NULL) return ASN1_FILE_NOT_FOUND;
 
   fprintf(file,"\n#include \"libtasn1.h\"\n\n");
@@ -103,13 +104,13 @@
 
     if(p->name) fprintf(file,"\"%s\",",p->name);
     else fprintf(file,"0,");
-    
+
    t=p->type;
    if(p->down) t|=CONST_DOWN;
    if(p->right) t|=CONST_RIGHT;
-   
+
    fprintf(file,"%lu,",t);
-   
+
    if(p->value) fprintf(file,"\"%s\"},\n",p->value);
    else fprintf(file,"0},\n");
 
@@ -145,26 +146,27 @@
 /**
   * asn1_array2tree - Creates the structures needed to manage the ASN1 
definitions.
   * @array: specify the array that contains ASN.1 declarations
-  * @definitions: return the pointer to the structure created by *ARRAY ASN.1 
declarations
-  * @errorDescription : return the error description.
-  * Description:
+  * @definitions: return the pointer to the structure created by
+  *   *ARRAY ASN.1 declarations
+  * @errorDescription: return the error description.
   *
-  * Creates the structures needed to manage the ASN1 definitions. ARRAY is a 
vector created by
-  * 'asn1_parser_asn1_file_c' function.
+  * Creates the structures needed to manage the ASN.1 definitions.
+  * @array is a vector created by asn1_parser2array().
   *
   * Returns:
   *
-  *  ASN1_SUCCESS\: structure created correctly. 
+  * ASN1_SUCCESS: Structure created correctly.
   *
-  * ASN1_ELEMENT_NOT_EMPTY\: *DEFINITIONS not ASN1_TYPE_EMPTY
+  * ASN1_ELEMENT_NOT_EMPTY: address@hidden not ASN1_TYPE_EMPTY.
   *
-  * ASN1_IDENTIFIER_NOT_FOUND\: in the file there is an identifier that is not 
defined (see ERRORDESCRIPTION for more information).
+  * ASN1_IDENTIFIER_NOT_FOUND: In the file there is an identifier that
+  *   is not defined (see @errorDescription for more information).
   *
-  *  ASN1_ARRAY_ERROR\: the array pointed by ARRAY is wrong.  
+  * ASN1_ARRAY_ERROR: The array pointed by @array is wrong.
   **/
 asn1_retCode
 asn1_array2tree(const ASN1_ARRAY_TYPE *array,ASN1_TYPE *definitions,
-                 char *errorDescription)
+               char *errorDescription)
 {
   node_asn *p,*p_last=NULL;
   unsigned long k;
@@ -182,7 +184,7 @@
     p=_asn1_add_node(array[k].type&(~CONST_DOWN));
     if(array[k].name) _asn1_set_name(p,array[k].name);
     if(array[k].value) _asn1_set_value(p,array[k].value,
-                                       strlen(array[k].value)+1);
+                                      strlen(array[k].value)+1);
 
     if(*definitions==NULL) *definitions=p;
 
@@ -196,7 +198,7 @@
     else{
       while(1){
        if(p_last==*definitions) break;
-   
+
        p_last= _asn1_find_up(p_last);
 
        if(p_last==NULL) break;
@@ -231,7 +233,7 @@
    else
      errorDescription[0]=0;
   }
-  
+
   if(result != ASN1_SUCCESS){
     _asn1_delete_list_and_nodes();
     *definitions=ASN1_TYPE_EMPTY;
@@ -244,18 +246,17 @@
 
 
 /**
-  * asn1_delete_structure - Deletes the structure pointed by *ROOT. 
+  * asn1_delete_structure - Deletes the structure pointed by *ROOT.
   * @structure: pointer to the structure that you want to delete.
-  * Description:
-  * 
-  * Deletes the structure *ROOT. 
-  * At the end *ROOT is setted to ASN1_TYPE_EMPTY. 
-  * 
+  *
+  * Deletes the structure address@hidden  At the end, address@hidden is set
+  * to ASN1_TYPE_EMPTY.
+  *
   * Returns:
   *
-  *   ASN1_SUCCESS\: everything OK
+  * ASN1_SUCCESS: Everything OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND\: *root==ASN1_TYPE_EMPTY.
+  * ASN1_ELEMENT_NOT_FOUND: address@hidden was ASN1_TYPE_EMPTY.
   *
   **/
 asn1_retCode
@@ -300,18 +301,18 @@
 
 
 /**
-  * asn1_delete_element - Deletes the element of a structure. 
-  * @structure: pointer to the structure that contains the element you want to 
delete.
+  * asn1_delete_element - Deletes the element of a structure.
+  * @structure: pointer to the structure that contains the element you
+  *   want to delete.
   * @element_name: element's name you want to delete.
-  * Description:
-  * 
-  * Deletes the element named *element_name inside *structure. 
+  *
+  * Deletes the element named address@hidden inside address@hidden
   *
   * Returns:
   *
-  *   ASN1_SUCCESS\: everything OK
+  * ASN1_SUCCESS: Everything OK.
   *
-  *   ASN1_ELEMENT_NOT_FOUND
+  * ASN1_ELEMENT_NOT_FOUND: The name element was not found.
   *
   **/
 asn1_retCode
@@ -327,7 +328,7 @@
   p3=_asn1_find_left(source_node);
   if(!p3){
     p3=_asn1_find_up(source_node);
-    if(p3) 
+    if(p3)
       _asn1_set_down(p3,p2);
     else
       if(source_node->right) source_node->right->left=NULL;
@@ -342,7 +343,7 @@
 _asn1_copy_structure3(node_asn *source_node)
 {
   node_asn *dest_node,*p_s,*p_d,*p_d_prev;
-  int len,len2,move;
+  int len,len2,move, tlen;
 
   if(source_node==NULL) return NULL;
 
@@ -358,14 +359,17 @@
       if(p_s->name) _asn1_set_name(p_d,p_s->name);
       if(p_s->value){
        switch(type_field(p_s->type)){
-       case TYPE_OCTET_STRING: case TYPE_BIT_STRING: case TYPE_GENERALSTRING: 
-       case TYPE_INTEGER:    
+       case TYPE_OCTET_STRING: case TYPE_BIT_STRING: case TYPE_GENERALSTRING:
+       case TYPE_INTEGER:
          len2=-1;
          len=_asn1_get_length_der(p_s->value,&len2);
          _asn1_set_value(p_d,p_s->value,len+len2);
          break;
        default:
-         _asn1_set_value(p_d,p_s->value,strlen(p_s->value)+1);
+         tlen = strlen(p_s->value);
+
+         if (tlen > 0)
+             _asn1_set_value(p_d,p_s->value,tlen+1);
        }
       }
       move=DOWN;
@@ -375,13 +379,13 @@
     if(move==DOWN){
       if(p_s->down){
        p_s=p_s->down;
-       p_d_prev=p_d;      
+       p_d_prev=p_d;
        p_d=_asn1_add_node_only(p_s->type);
        _asn1_set_down(p_d_prev,p_d);
       }
       else move=RIGHT;
     }
-  
+
     if(p_s==source_node) break;
 
     if(move==RIGHT){
@@ -409,18 +413,18 @@
   node_asn *source_node;
 
   source_node=_asn1_find_node(root,source_name);
-  
+
   return _asn1_copy_structure3(source_node);
 
 }
 
 
-asn1_retCode 
+asn1_retCode
 _asn1_type_choice_config(node_asn *node)
 {
   node_asn *p,*p2,*p3,*p4;
-  int move;
- 
+  int move,tlen;
+
   if(node==NULL) return ASN1_ELEMENT_NOT_FOUND;
 
   p=node;
@@ -438,7 +442,9 @@
            while(p3){
              if(type_field(p3->type)==TYPE_TAG){
                p4=_asn1_add_node_only(p3->type);
-               _asn1_set_value(p4,p3->value,strlen(p3->value)+1);
+               tlen = strlen(p3->value);
+               if (tlen > 0)
+                   _asn1_set_value(p4,p3->value,tlen+1);
                _asn1_set_right(p4,p2->down);
                _asn1_set_down(p2,p4);
              }
@@ -458,32 +464,32 @@
       move=DOWN;
     }
     else move=RIGHT;
-    
+
     if(move==DOWN){
       if(p->down) p=p->down;
       else move=RIGHT;
     }
-    
+
     if(p==node) {move=UP; continue;}
-    
+
     if(move==RIGHT){
       if(p->right) p=p->right;
       else move=UP;
     }
     if(move==UP) p=_asn1_find_up(p);
   }
-  
+
   return ASN1_SUCCESS;
 }
 
 
-asn1_retCode 
+asn1_retCode
 _asn1_expand_identifier(node_asn **node,node_asn *root)
 {
   node_asn *p,*p2,*p3;
   char name2[MAX_NAME_SIZE+2];
   int move;
- 
+
   if(node==NULL) return ASN1_ELEMENT_NOT_FOUND;
 
   p=*node;
@@ -509,7 +515,7 @@
          _asn1_set_right(p3,p2->down);
          _asn1_set_down(p2,p->down);
        }
-       
+
        p3=_asn1_find_left(p);
        if(p3) _asn1_set_right(p3,p2);
        else{
@@ -536,14 +542,14 @@
       move=DOWN;
     }
     else move=RIGHT;
-    
+
     if(move==DOWN){
       if(p->down) p=p->down;
       else move=RIGHT;
     }
-    
+
     if(p==*node) {move=UP; continue;}
-    
+
     if(move==RIGHT){
       if(p->right) p=p->right;
       else move=UP;
@@ -557,21 +563,22 @@
 
 /**
   * asn1_create_element - Creates a structure of type SOURCE_NAME.
-  * @definitions: pointer to the structure returned by "parser_asn1" function 
-  * @source_name: the name of the type of the new structure (must be inside 
p_structure).
-  * @element: pointer to the structure created. 
-  * Description:
+  * @definitions: pointer to the structure returned by "parser_asn1" function
+  * @source_name: the name of the type of the new structure (must be
+  *   inside p_structure).
+  * @element: pointer to the structure created.
+  *
+  * Creates a structure of type @source_name.  Example using
+  *  "pkix.asn":
   *
-  * Creates a structure called DEST_NAME of type SOURCE_NAME.
+  * rc = asn1_create_structure(cert_def, "PKIX1.Certificate",
+  * certptr);
   *
   * Returns:
   *
-  *  ASN1_SUCCESS\: creation OK
+  * ASN1_SUCCESS: Creation OK.
   *
-  *  ASN1_ELEMENT_NOT_FOUND\: SOURCE_NAME isn't known
-  * 
-  * Example: using "pkix.asn"
-  *  result=asn1_create_structure(cert_def,"PKIX1.Certificate",certptr);
+  * ASN1_ELEMENT_NOT_FOUND: SOURCE_NAME isn't known
   **/
 asn1_retCode
 asn1_create_element(ASN1_TYPE definitions,const char *source_name,
@@ -581,7 +588,7 @@
   int res;
 
   dest_node=_asn1_copy_structure2(definitions,source_name);
- 
+
   if(dest_node==NULL) return ASN1_ELEMENT_NOT_FOUND;

[127 lines skipped]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]