summaryrefslogtreecommitdiff
path: root/lib/minitasn1
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2005-01-18 16:30:56 +0000
committerSimon Josefsson <simon@josefsson.org>2005-01-18 16:30:56 +0000
commitdfce939c06a551370bbf6ff76365fc0325a9d7d2 (patch)
tree063116643e19f033e086b5977086b0c2797c2c4a /lib/minitasn1
parentfa2bbac93ccdd8600bd77fc778a7b32aa6470e31 (diff)
downloadgnutls-dfce939c06a551370bbf6ff76365fc0325a9d7d2.tar.gz
Sync with libtasn1 0.2.13.
Diffstat (limited to 'lib/minitasn1')
-rw-r--r--lib/minitasn1/coding.c31
-rw-r--r--lib/minitasn1/decoding.c115
-rw-r--r--lib/minitasn1/element.c272
-rw-r--r--lib/minitasn1/errors.c12
-rw-r--r--lib/minitasn1/int.h87
-rw-r--r--lib/minitasn1/libtasn1.h7
-rw-r--r--lib/minitasn1/parser_aux.c25
-rw-r--r--lib/minitasn1/structure.c201
8 files changed, 351 insertions, 399 deletions
diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c
index 0e922f0931..67accd757b 100644
--- a/lib/minitasn1/coding.c
+++ b/lib/minitasn1/coding.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2002 Fabio Fiorina
+ * Copyright (C) 2004 Simon Josefsson
*
* This file is part of LIBASN1.
*
@@ -716,27 +717,31 @@ _asn1_ordering_set_of(unsigned char *der,node_asn *node)
/**
* 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 *@ider: @ider[0]..@ider[len-1], 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)
{
diff --git a/lib/minitasn1/decoding.c b/lib/minitasn1/decoding.c
index cc01253e9c..a0ae7a9fb7 100644
--- a/lib/minitasn1/decoding.c
+++ b/lib/minitasn1/decoding.c
@@ -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_get_indefinite_length_string(const unsigned char* der,int* len)
/**
* 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.
+ * @element: pointer to an ASN1 structure.
+ * @ider: vector that contains the DER encoding.
+ * @len: number of bytes of *@ider: @ider[0]..@ider[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.
+ * 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
@@ -919,25 +923,27 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len,
* 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:
+ * @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.
+ * 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
@@ -1509,26 +1515,31 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName,
/**
* 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 *@ider: @ider[0]..@ider[len-1]
* @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
@@ -1765,7 +1776,6 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len,
* 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
@@ -1776,11 +1786,12 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len,
*
* 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
@@ -1963,28 +1974,26 @@ asn1_expand_any_defined_by(ASN1_TYPE definitions,ASN1_TYPE *element)
* @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;
diff --git a/lib/minitasn1/element.c b/lib/minitasn1/element.c
index 12792dbf17..f4b79e75f8 100644
--- a/lib/minitasn1/element.c
+++ b/lib/minitasn1/element.c
@@ -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_append_sequence_set(node_asn *node)
* 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.
*
- * ASN1_VALUE_NOT_VALID\: VALUE has a wrong format.
- *
- * Examples:
- * description for each type
+ * value="1 2 840 10040 4 3" , len=1 -> OID=dsa-with-sha.
*
- *\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
+ * 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.
*
- * \item ENUMERATED\: as INTEGER (but only with not negative numbers)
+ * value="9801011200Z" , len=1 -> time=Jannuary 1st, 1998
+ * at 12h 00m Greenwich Mean Time
*
- * \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
+ * 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 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
+ * value="2001010112001.12-0700" , len=1 -> time=Jannuary
+ * 1st, 2001 at 12h 00m 01.12s Pacific Daylight Time
*
- * \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
+ * OCTET STRING: VALUE contains the octet string and LEN is the
+ * number of octets.
*
- * \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
+ * value="$\backslash$x01$\backslash$x02$\backslash$x03" ,
+ * len=3 -> three bytes octet string
*
- * \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
+ * GeneralString: VALUE contains the generalstring and LEN is the
+ * number of octets.
*
- * \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
+ * value="$\backslash$x01$\backslash$x02$\backslash$x03" ,
+ * len=3 -> three bytes generalstring
*
- * \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)
+ * BIT STRING: VALUE contains the bit string organized by bytes and
+ * LEN is the number of 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);
+ * value="$\backslash$xCF" , len=6 -> bit string="110011" (six
+ * bits)
*
- * \item ANY\: VALUE indicates the der encoding of a structure.
- * LEN != 0
+ * 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 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",
+ * 1);
*
- * Using "pkix.asn"\:
+ * ANY: VALUE indicates the der encoding of a structure. LEN != 0.
*
- * result=asn1_write_value(cert,"certificate1.tbsCertificate.subject.rdnSequence","NEW",1);
+ * 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.
*
- * \item SET OF\: the same as SEQUENCE OF.
- * Using "pkix.asn":
+ * Using "pkix.asn"\:
*
- * result=asn1_write_value(cert,"tbsCertificate.subject.rdnSequence.?LAST","NEW",1);
- *\end{itemize}
+ * result=asn1_write_value(cert,
+ * "certificate1.tbsCertificate.subject.rdnSequence", "NEW", 1);
*
- * If an element is OPTIONAL and you want to delete it, you must use the value=NULL and len=0.
+ * SET OF: the same as SEQUENCE OF. Using "pkix.asn":
*
- * Using "pkix.asn"\:
+ * result=asn1_write_value(cert,
+ * "tbsCertificate.subject.rdnSequence.?LAST", "NEW", 1);
+ *
+ * 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_write_value(node_asn *node_root,const char *name,
/**
* 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
+ * 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_ELEMENT_NOT_FOUND\: NAME is not a valid element.
+ * INTEGER: VALUE will contain a two's complement form integer.
*
- * ASN1_VALUE_NOT_FOUND\: there isn't any value for the element selected.
+ * integer=-1 -> value[0]=0xFF , len=1.
+ * integer=1 -> value[0]=0x01 , len=1.
*
- * 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
+ * ENUMERATED: As INTEGER (but only with not negative numbers).
*
- *\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
+ * BOOLEAN: VALUE will be the null terminated string "TRUE" or
+ * "FALSE" and LEN=5 or LEN=6.
*
- * \item ENUMERATED\: as INTEGER (but only with not negative numbers)
+ * OBJECT IDENTIFIER: VALUE will be a null terminated string with
+ * each number separated by a dot (i.e. "1.2.3.543.1").
*
- * \item BOOLEAN\: VALUE will be the null terminated string "TRUE" or "FALSE" and LEN=5 or LEN=6
- *
- * \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
+ * 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.
*
- * \item 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.
*
- * \item 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.
*
- * \item 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:
*
- * \item BIT STRING\: VALUE will contain the bit string organized by bytes and LEN will be the
- * number of bits.
+ * ASN1_SUCCESS: Set value OK.
*
- * \item CHOICE\: if NAME indicates a choice type, VALUE will specify the alternative selected
+ * 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.
*
- * \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.
- *
**/
-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_value(node_asn *root,const char *name,void* ivalue, int *len)
* 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)
diff --git a/lib/minitasn1/errors.c b/lib/minitasn1/errors.c
index 17654f2cee..5bfb47c10f 100644
--- a/lib/minitasn1/errors.c
+++ b/lib/minitasn1/errors.c
@@ -66,10 +66,10 @@ static libtasn1_error_entry error_algorithms[] = {
/**
* 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 @@ void libtasn1_perror(asn1_retCode 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 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 @@ void _libtasn1_log( const char *fmt, ...) {
va_start(args,fmt);
vsprintf( str,fmt,args); /* Flawfinder: ignore */
- va_end(args);
+ va_end(args);
fprintf(stderr, str);
diff --git a/lib/minitasn1/int.h b/lib/minitasn1/int.h
index 3c9179f521..96252670ed 100644
--- a/lib/minitasn1/int.h
+++ b/lib/minitasn1/int.h
@@ -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 @@ typedef struct static_struct_asn ASN1_ARRAY_TYPE;
#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 */
diff --git a/lib/minitasn1/libtasn1.h b/lib/minitasn1/libtasn1.h
index 43ecef2de9..45991ef640 100644
--- a/lib/minitasn1/libtasn1.h
+++ b/lib/minitasn1/libtasn1.h
@@ -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_structure(ASN1_TYPE *structure);
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);
diff --git a/lib/minitasn1/parser_aux.c b/lib/minitasn1/parser_aux.c
index 1da3ea611a..05cf5d8e42 100644
--- a/lib/minitasn1/parser_aux.c
+++ b/lib/minitasn1/parser_aux.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2000,2001 Fabio Fiorina
+ * Copyright (C) 2004 Simon Josefsson
*
* This file is part of LIBASN1.
*
@@ -872,17 +873,19 @@ parse_version_string( const char *s, int *major, int *minor, int *micro )
}
/**
- * 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 )
{
diff --git a/lib/minitasn1/structure.c b/lib/minitasn1/structure.c
index 97f11d4cb9..0bc26f52f2 100644
--- a/lib/minitasn1/structure.c
+++ b/lib/minitasn1/structure.c
@@ -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 @@ extern char _asn1_identifierMissing[];
/******************************************************/
/* 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 @@ _asn1_add_node_only(unsigned int type)
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 @@ _asn1_add_node_only(unsigned int type)
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 @@ _asn1_create_static_structure(ASN1_TYPE pointer,char* output_file_name,char *vec
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_create_static_structure(ASN1_TYPE pointer,char* output_file_name,char *vec
/**
* 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: *@definitions 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 @@ asn1_array2tree(const ASN1_ARRAY_TYPE *array,ASN1_TYPE *definitions,
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 @@ asn1_array2tree(const ASN1_ARRAY_TYPE *array,ASN1_TYPE *definitions,
else{
while(1){
if(p_last==*definitions) break;
-
+
p_last= _asn1_find_up(p_last);
if(p_last==NULL) break;
@@ -231,7 +233,7 @@ asn1_array2tree(const ASN1_ARRAY_TYPE *array,ASN1_TYPE *definitions,
else
errorDescription[0]=0;
}
-
+
if(result != ASN1_SUCCESS){
_asn1_delete_list_and_nodes();
*definitions=ASN1_TYPE_EMPTY;
@@ -244,18 +246,17 @@ asn1_array2tree(const ASN1_ARRAY_TYPE *array,ASN1_TYPE *definitions,
/**
- * 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 *@structure. At the end, *@structure 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: *@structure was ASN1_TYPE_EMPTY.
*
**/
asn1_retCode
@@ -300,18 +301,18 @@ asn1_delete_structure(ASN1_TYPE *structure)
/**
- * 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 *@element_name inside *@structure.
*
* 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 @@ asn1_delete_element(ASN1_TYPE structure,const char *element_name)
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;
@@ -358,15 +359,15 @@ _asn1_copy_structure3(node_asn *source_node)
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:
tlen = strlen(p_s->value);
-
+
if (tlen > 0)
_asn1_set_value(p_d,p_s->value,tlen+1);
}
@@ -378,13 +379,13 @@ _asn1_copy_structure3(node_asn *source_node)
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){
@@ -412,18 +413,18 @@ _asn1_copy_structure2(node_asn *root,const char *source_name)
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,tlen;
-
+
if(node==NULL) return ASN1_ELEMENT_NOT_FOUND;
p=node;
@@ -463,32 +464,32 @@ _asn1_type_choice_config(node_asn *node)
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;
@@ -514,7 +515,7 @@ _asn1_expand_identifier(node_asn **node,node_asn *root)
_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{
@@ -541,14 +542,14 @@ _asn1_expand_identifier(node_asn **node,node_asn *root)
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;
@@ -562,21 +563,22 @@ _asn1_expand_identifier(node_asn **node,node_asn *root)
/**
* 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,
@@ -586,7 +588,7 @@ asn1_create_element(ASN1_TYPE definitions,const char *source_name,
int res;
dest_node=_asn1_copy_structure2(definitions,source_name);
-
+
if(dest_node==NULL) return ASN1_ELEMENT_NOT_FOUND;
_asn1_set_name(dest_node,"");
@@ -606,11 +608,11 @@ asn1_create_element(ASN1_TYPE definitions,const char *source_name,
* @structure: pointer to the structure that you want to visit.
* @name: an element of the structure
* @mode: specify how much of the structure to print, can be
- * ASN1_PRINT_NAME, ASN1_PRINT_NAME_TYPE,
- * ASN1_PRINT_NAME_TYPE_VALUE, or ASN1_PRINT_ALL.
- *
- * Prints on the standard output the structure's tree starting from the NAME element inside
- * the structure *POINTER.
+ * %ASN1_PRINT_NAME, %ASN1_PRINT_NAME_TYPE,
+ * %ASN1_PRINT_NAME_TYPE_VALUE, or %ASN1_PRINT_ALL.
+ *
+ * Prints on the @out file descriptor the structure's tree starting
+ * from the @name element inside the structure @structure.
**/
void
asn1_print_structure(FILE *out,ASN1_TYPE structure,const char *name,int mode)
@@ -620,7 +622,7 @@ asn1_print_structure(FILE *out,ASN1_TYPE structure,const char *name,int mode)
if(out==NULL) return;
- root=_asn1_find_node(structure,name);
+ root=_asn1_find_node(structure,name);
if(root==NULL) return;
@@ -864,21 +866,23 @@ asn1_print_structure(FILE *out,ASN1_TYPE structure,const char *name,int mode)
/**
* asn1_number_of_elements - Counts the number of elements of a structure.
- * @element: pointer to the root of an ASN1 structure.
+ * @element: pointer to the root of an ASN1 structure.
* @name: the name of a sub-structure of ROOT.
- * @num: pointer to an integer where the result will be stored
- * Description:
+ * @num: pointer to an integer where the result will be stored
*
- * Counts the number of elements of a sub-structure called NAME with names equal to "?1","?2", ...
+ * Counts the number of elements of a sub-structure called NAME with
+ * names equal to "?1","?2", ...
*
* Returns:
*
- * ASN1_SUCCESS\: creation OK
- * ASN1_ELEMENT_NOT_FOUND\: NAME isn't known
- * ASN1_GENERIC_ERROR\: pointer num equal to NULL
+ * ASN1_SUCCESS: Creation OK.
+ *
+ * ASN1_ELEMENT_NOT_FOUND: NAME isn't known.
+ *
+ * ASN1_GENERIC_ERROR: Pointer num equal to NULL.
*
**/
-asn1_retCode
+asn1_retCode
asn1_number_of_elements(ASN1_TYPE element,const char *name,int *num)
{
node_asn *node,*p;
@@ -893,7 +897,7 @@ asn1_number_of_elements(ASN1_TYPE element,const char *name,int *num)
p=node->down;
while(p){
- if((p->name) && (p->name[0]=='?')) (*num)++;
+ if((p->name) && (p->name[0]=='?')) (*num)++;
p=p->right;
}
@@ -905,21 +909,17 @@ asn1_number_of_elements(ASN1_TYPE element,const char *name,int *num)
* asn1_find_structure_from_oid - Locate structure defined by a specific OID.
* @definitions: ASN1 definitions
* @oidValue: value of the OID to search (e.g. "1.2.3.4").
- * Description:
*
* Search the structure that is defined just after an OID definition.
*
- * Returns:
- *
- * NULL when OIDVALUE not found,
- *
- * otherwise the pointer to a constant string that contains the element
- * name defined just after the OID.
+ * Returns: NULL when OIDVALUE not found, otherwise the pointer to a
+ * constant string that contains the element name defined just
+ * after the OID.
*
**/
const char*
-asn1_find_structure_from_oid(ASN1_TYPE definitions,
- const char *oidValue)
+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];
@@ -938,10 +938,10 @@ asn1_find_structure_from_oid(ASN1_TYPE definitions,
p=definitions->down;
while(p){
if((type_field(p->type)==TYPE_OBJECT_ID) &&
- (p->type & CONST_ASSIGN)){
+ (p->type & CONST_ASSIGN)){
strcpy(name,definitionsName);
strcat(name,p->name);
-
+
len=MAX_NAME_SIZE;
result=asn1_read_value(definitions,name,value,&len);
@@ -949,7 +949,7 @@ asn1_find_structure_from_oid(ASN1_TYPE definitions,
p=p->right;
if(p==NULL) /* reach the end of ASN1 definitions */
return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
-
+
return p->name;
}
}
@@ -958,8 +958,3 @@ asn1_find_structure_from_oid(ASN1_TYPE definitions,
return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
}
-
-
-
-
-