+Version 0.1.2
+- Added GeneralString type
+- Fixed a DER encoding bug when nested tags are used
+
Version 0.1.1
- Renamed to libtasn1
- Functions which return a string for error description
-$(LN_S) ../lib/asn1-api.tex .
-latex asn1.tex && latex asn1.tex && dvips asn1.dvi -o asn1.ps
-asn1.html: $(TEX_OBJECTS)
+asn1.html: asn1.ps $(TEX_OBJECTS)
-latex2html asn1.tex -no_navigation -split 0 -local_icons -html_version 3.2,math \
-info "" -white
if(node->type&CONST_TAG){
p=node->down;
- while(p){
+ /* When there are nested tags we must complete them reverse to
+ the order they were created. This is because completing a tag
+ modifies alla date within it, including the incomplete tags
+ which store buffer positions -- simon@josefsson.org 2002-09-06
+ */
+ while(p->right)
+ p=p->right;
+ while(p && p!=node->down->left){
if(type_field(p->type)==TYPE_TAG){
if(p->type&CONST_EXPLICIT){
len2=strtol(p->name,NULL,10);
}
}
}
- p=p->right;
+ p=p->left;
}
}
}
counter+=len3+len2;
move=RIGHT;
break;
+ case TYPE_GENERALSTRING:
+ len2=_asn1_get_length_der(der+counter,&len3);
+ if(state==FOUND){
+ _asn1_set_value(p,der+counter,len3+len2);
+
+ if(p==nodeFound) state=EXIT;
+ }
+ counter+=len3+len2;
+ move=RIGHT;
+ break;
case TYPE_BIT_STRING:
len2=_asn1_get_length_der(der+counter,&len3);
if(state==FOUND){
*len=SIZEOF_UNSIGNED_LONG_INT-k;
-#ifdef DEBUG_INTEGER
+#ifdef LIBTASN1_DEBUG_INTEGER
_libasn1_log("_asn1_convert_integer: valueIn=%s, lenOut=%d",value,*len);
for(k=0;k<SIZEOF_UNSIGNED_LONG_INT;k++)
_libasn1_log(", vOut[%d]=%d",k,value_out[k]);
#endif
-#define LIBASN1_ERROR_ENTRY(name) \
+#define LIBTASN1_ERROR_ENTRY(name) \
{ #name, name }
-struct libasn1_error_entry {
+struct libtasn1_error_entry {
char *name;
int number;
};
-typedef struct libasn1_error_entry libasn1_error_entry;
-
-static libasn1_error_entry error_algorithms[] = {
- LIBASN1_ERROR_ENTRY( ASN1_SUCCESS ),
- LIBASN1_ERROR_ENTRY( ASN1_FILE_NOT_FOUND ),
- LIBASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_FOUND ),
- LIBASN1_ERROR_ENTRY( ASN1_IDENTIFIER_NOT_FOUND ),
- LIBASN1_ERROR_ENTRY( ASN1_DER_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_VALUE_NOT_FOUND ),
- LIBASN1_ERROR_ENTRY( ASN1_GENERIC_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_VALUE_NOT_VALID ),
- LIBASN1_ERROR_ENTRY( ASN1_TAG_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_TAG_IMPLICIT ),
- LIBASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
- LIBASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
- LIBASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
- LIBASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
- LIBASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_EMPTY ),
+typedef struct libtasn1_error_entry libtasn1_error_entry;
+
+static libtasn1_error_entry error_algorithms[] = {
+ LIBTASN1_ERROR_ENTRY( ASN1_SUCCESS ),
+ LIBTASN1_ERROR_ENTRY( ASN1_FILE_NOT_FOUND ),
+ LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_FOUND ),
+ LIBTASN1_ERROR_ENTRY( ASN1_IDENTIFIER_NOT_FOUND ),
+ LIBTASN1_ERROR_ENTRY( ASN1_DER_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_FOUND ),
+ LIBTASN1_ERROR_ENTRY( ASN1_GENERIC_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_VALUE_NOT_VALID ),
+ LIBTASN1_ERROR_ENTRY( ASN1_TAG_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_TAG_IMPLICIT ),
+ LIBTASN1_ERROR_ENTRY( ASN1_ERROR_TYPE_ANY ),
+ LIBTASN1_ERROR_ENTRY( ASN1_SYNTAX_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_MEM_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_DER_OVERFLOW ),
+ LIBTASN1_ERROR_ENTRY( ASN1_NAME_TOO_LONG ),
+ LIBTASN1_ERROR_ENTRY( ASN1_ARRAY_ERROR ),
+ LIBTASN1_ERROR_ENTRY( ASN1_ELEMENT_NOT_EMPTY ),
{0}
};
-#define LIBASN1_ERROR_LOOP(b) \
- libasn1_error_entry *p; \
+#define LIBTASN1_ERROR_LOOP(b) \
+ libtasn1_error_entry *p; \
for(p = error_algorithms; p->name != NULL; p++) { b ; }
-#define LIBASN1_ERROR_ALG_LOOP(a) \
- LIBASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
+#define LIBTASN1_ERROR_ALG_LOOP(a) \
+ LIBTASN1_ERROR_LOOP( if(p->number == error) { a; break; } )
/**
- * libasn1_perror - prints a string to stderr with a description of an error
+ * libtasn1_perror - prints a string to stderr with a description of an error
* @error: is an error returned by a libasn1 function.
*
* This function is like perror(). The only difference is that it accepts an
* error returned by a libasn1 function.
**/
-void libasn1_perror(asn1_retCode error)
+void libtasn1_perror(asn1_retCode error)
{
char *ret = NULL;
/* avoid prefix */
- LIBASN1_ERROR_ALG_LOOP(ret =
+ LIBTASN1_ERROR_ALG_LOOP(ret =
_asn1_strdup(p->name + sizeof("ASN1_") - 1));
- _libasn1_log( "LIBASN1 ERROR: %s\n", ret);
+ _libtasn1_log( "LIBTASN1 ERROR: %s\n", ret);
_asn1_free( ret);
}
/**
- * libasn1_strerror - Returns a string with a description of an error
- * @error: is an error returned by a libasn1 function.
+ * libtasn1_strerror - Returns a string with a description of an error
+ * @error: is an error returned by a libtasn1 function.
*
* This function is similar to strerror(). The only difference is that it
* accepts an error (number) returned by a libasn1 function.
**/
-const char* libasn1_strerror(asn1_retCode error)
+const char* libtasn1_strerror(asn1_retCode error)
{
char *ret = NULL;
/* avoid prefix */
- LIBASN1_ERROR_ALG_LOOP(ret =
+ LIBTASN1_ERROR_ALG_LOOP(ret =
p->name + sizeof("ASN1_") - 1);
return ret;
/* this function will output a message.
*/
-#ifdef DEBUG
-void _libasn1_log( const char *fmt, ...) {
+#ifdef LIBTASN1_DEBUG
+void _libtasn1_log( const char *fmt, ...) {
va_list args;
char str[MAX_LOG_SIZE];
#include "int.h"
#include "errors_int.h"
-#ifdef DEBUG
+#ifdef LIBTASN1_DEBUG
# ifdef __FILE__
# ifdef __LINE__
-# define _libasn1_assert() fprintf(stderr, "LIBASN1_ASSERT: %s:%d\n", __FILE__,__LINE__);
+# define _libtasn1_assert() fprintf(stderr, "LIBTASN1_ASSERT: %s:%d\n", __FILE__,__LINE__);
# else
-# define _libasn1_assert()
+# define _libtasn1_assert()
# endif
# else /* __FILE__ defined */
-# define _libasn1_assert()
+# define _libtasn1_assert()
# endif
#else /* no debug */
-# define _libasn1_assert()
+# define _libtasn1_assert()
#endif
-const char* libasn1_strerror(int error);
-void libasn1_perror(int error);
+const char* libtasn1_strerror(int error);
+void libtasn1_perror(int error);
-#ifdef DEBUG
- void _libasn1_log( const char *fmt, ...);
+#ifdef LIBTASN1_DEBUG
+ void _libtasn1_log( const char *fmt, ...);
#else
-# define _libasn1_log ( ...)
+# define _libtasn1_log ( ...)
#endif
#endif /* ERRORS_H */
#include <defines.h>
-#define DEBUG
+#define LIBTASN1_DEBUG
/*
-#define DEBUG_PARSER
-#define DEBUG_INTEGER
+#define LIBTASN1_DEBUG_PARSER
+#define LIBTASN1_DEBUG_INTEGER
*/
asn1_retCode asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element,
const char *octetName,const char *objectName);
-const char* libasn1_strerror(asn1_retCode error);
+const char* libtasn1_strerror(asn1_retCode error);
-void libasn1_perror(asn1_retCode error);
+void libtasn1_perror(asn1_retCode error);
#ifdef __cplusplus
}
result=asn1_parser2tree("pkix.asn",&PKIX1Implicit88,errorDescription);
if(result != ASN1_SUCCESS){
- libasn1_perror(result);
+ libtasn1_perror(result);
printf("%s",errorDescription);
exit(1);
}
result=asn1_parser2tree("pkix.asn",&PKIX1Implicit88,errorDescription);
if(result != ASN1_SUCCESS){
- libasn1_perror(result);
+ libtasn1_perror(result);
printf("%s\n",errorDescription);
exit(1);
}
printf("asn1Coding: %s\n",errorDescription);
break;
default:
- printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+ printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
}
if(asn1_result != ASN1_SUCCESS){
asn1_result=asn1_write_value(structure,varName,value,0);
if(asn1_result != ASN1_SUCCESS){
- printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+ printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
asn1_delete_structure(&definitions);
asn1_delete_structure(&structure);
asn1_result=asn1_der_coding(structure,structureName,der,&der_len,
errorDescription);
- printf("\nCoding: %s\n\n",libasn1_strerror(asn1_result));
+ printf("\nCoding: %s\n\n",libtasn1_strerror(asn1_result));
if(asn1_result!=ASN1_SUCCESS){
printf("asn1Coding: %s\n",errorDescription);
printf("asn1Decoding: %s\n",errorDescription);
break;
default:
- printf("libasn1 ERROR: %s\n",libasn1_strerror(asn1_result));
+ printf("libasn1 ERROR: %s\n",libtasn1_strerror(asn1_result));
}
if(asn1_result != ASN1_SUCCESS){
asn1_result=asn1_create_element(definitions,typeName,&structure,varName);
if(asn1_result != ASN1_SUCCESS){
- printf("Structure creation: %s\n",libasn1_strerror(asn1_result));
+ printf("Structure creation: %s\n",libtasn1_strerror(asn1_result));
asn1_delete_structure(&definitions);
free(inputFileAsnName);
}
asn1_result=asn1_der_decoding(&structure,der,der_len,errorDescription);
- printf("\nDecoding: %s\n",libasn1_strerror(asn1_result));
+ printf("\nDecoding: %s\n",libtasn1_strerror(asn1_result));
if(asn1_result != ASN1_SUCCESS)
printf("asn1Decoding: %s\n",errorDescription);
printf("asn1Parser: %s\n",errorDescription);\r
break;\r
default:\r
- printf("libasn1 ERROR: %s\n",libasn1_strerror(parse_result));\r
+ printf("libasn1 ERROR: %s\n",libtasn1_strerror(parse_result));\r
}\r
\r
\r
Sequence1 ::= SEQUENCE{
int1 INTEGER,
- int2 INTEGER
-
+ int2 INTEGER,
+ generic GeneralString
}
{12,"const1 INTEGER ::= 10",ASN1_SUCCESS,""},
{12,"const1 INTEGER ::= v1",
ASN1_SYNTAX_ERROR,_FILE_":12: parse error near 'v1'"},
-
+ {16," generic generalstring",
+ ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'generalstring' not found"},
/* end */
if(result!=ASN1_SUCCESS){
printf("File '%s' not correct\n",fileCorrectName);
- libasn1_perror(result);
+ libtasn1_perror(result);
printf("ErrorDescription = %s\n\n",errorDescription);
exit(1);
}
errorCounter++;
printf("ERROR N. %d:\n",errorCounter);
printf(" Line %d - %s\n",test->lineNumber,test->line);
- printf(" Error expected: %s - %s\n",libasn1_strerror(test->errorNumber),
+ printf(" Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),
test->errorDescription);
- printf(" Error detected: %s - %s\n\n",libasn1_strerror(result),
+ printf(" Error detected: %s - %s\n\n",libtasn1_strerror(result),
errorDescription);
}
UTF8String ::= [UNIVERSAL 12] IMPLICIT OCTET STRING
-- The content of this type conforms to RFC 2279.
+
+Test3 ::= SEQUENCE{
+ a INTEGER,
+ b [1] EXPLICIT GeneralString2
+}
+
+GeneralString2 ::= [2] EXPLICIT GeneralString
+
+
END
{ACT_VISIT,"Seq","",ASN1_PRINT_ALL,ASN1_SUCCESS},
{ACT_DELETE,"","",0,ASN1_SUCCESS},
+ /* Test GeneralString */
+ {ACT_CREATE,"TEST_TREE.Test3","test",0,ASN1_SUCCESS},
+ {ACT_WRITE,"test.a","1234",0,ASN1_SUCCESS},
+ {ACT_WRITE,"test.b","prova",5,ASN1_SUCCESS},
+ {ACT_ENCODING,"test",0,0,ASN1_SUCCESS},
+ {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
+ {ACT_DELETE,"","",0,ASN1_SUCCESS},
+ {ACT_CREATE,"TEST_TREE.Test3","test",0,ASN1_SUCCESS},
+ //{ACT_DECODING,0,0,0,ASN1_SUCCESS},
+ {ACT_DECODING_ELEMENT,"test.b",0,0,ASN1_SUCCESS},
+ {ACT_READ,"test.b","prova",5,ASN1_SUCCESS},
+ {ACT_VISIT,"test","",ASN1_PRINT_ALL,ASN1_SUCCESS},
+ {ACT_DELETE,"","",0,ASN1_SUCCESS},
+
+
/* end */
{ACT_NULL}
result=asn1_array2tree(Test_tree_asn1_tab,&definitions,errorDescription);
if(result!=ASN1_SUCCESS){
- libasn1_perror(result);
+ libtasn1_perror(result);
printf("ErrorDescription = %s\n\n",errorDescription);
exit(1);
}
printf("ERROR N. %d:\n",errorCounter);
printf(" Action %d - %s - %s - %d\n",test->action,test->par1,
test->par2,test->par3);
- printf(" Error expected: %s\n",libasn1_strerror(test->errorNumber));
- printf(" Error detected: %s\n\n",libasn1_strerror(result));
+ printf(" Error expected: %s\n",libtasn1_strerror(test->errorNumber));
+ printf(" Error detected: %s\n\n",libtasn1_strerror(result));
}
break;
errorCounter++;
printf("ERROR N. %d:\n",errorCounter);
printf(" Action %d - %s\n",test->action,test->par1);
- printf(" Error expected: %s - %d - ",libasn1_strerror(test->errorNumber),
+ printf(" Error expected: %s - %d - ",libtasn1_strerror(test->errorNumber),
test->par3);
for(k=0;k<test->par3;k++)
printf("%02x",test->par2[k]);
- printf("\n Error detected: %s - %d - ",libasn1_strerror(result),
+ printf("\n Error detected: %s - %d - ",libtasn1_strerror(result),
valueLen);
for(k=0;k<valueLen;k++)
printf("%02x",value[k]);