From 15bc224d3ecdf8f7074d13eff46a1b06d699472f Mon Sep 17 00:00:00 2001 From: Fabio Fiorina Date: Thu, 18 Sep 2003 19:33:44 +0000 Subject: [PATCH] manage 'INTEGER(1 | 2)' syntax --- NEWS | 7 +++++++ configure.in | 2 +- lib/ASN1.y | 27 +++++++++++++++++++-------- lib/int.h | 2 +- lib/libtasn1.h | 2 +- src/asn1Coding.c | 1 + tests/Test_parser.asn | 4 ++-- tests/Test_tree.c | 2 +- 8 files changed, 33 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 041ea42..ccefa65 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +Version 0.2.6 +- ASN.1 parser accepts these kinds of integer definitions: + "INTEGER (5 | 10)" and + "INTEGER (5)" +- Comments start at "--" and finish at the "end of line" or + with another "--". + Version 0.2.5 - Bug fix in ordering procedure for SET OF and SEQUENCE OF types coding. diff --git a/configure.in b/configure.in index a197fc3..94c9f94 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ AC_DEFINE_UNQUOTED(T_OS, "$target_os") dnl libtasn1 Version ASN1_MAJOR_VERSION=0 ASN1_MINOR_VERSION=2 -ASN1_MICRO_VERSION=5 +ASN1_MICRO_VERSION=6 ASN1_VERSION=$ASN1_MAJOR_VERSION.$ASN1_MINOR_VERSION.$ASN1_MICRO_VERSION AC_DEFINE_UNQUOTED(ASN1_VERSION, "$ASN1_VERSION") diff --git a/lib/ASN1.y b/lib/ASN1.y index c90c8f8..136deac 100644 --- a/lib/ASN1.y +++ b/lib/ASN1.y @@ -16,7 +16,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - + /*****************************************************/ /* File: x509_ASN.y */ @@ -107,7 +107,8 @@ int _asn1_yylex(void); %type definitions_id Time bit_element bit_element_list set_def %type tag_type tag type_assig_right_tag generalstring_def %type type_assig_right_tag_default enumerated_def -%type pos_num neg_num pos_neg_num pos_neg_identifier num_identifier +%type pos_num neg_num pos_neg_num pos_neg_identifier pos_neg_list +%type num_identifier %type class explicit_implicit %% @@ -192,10 +193,17 @@ default : DEFAULT pos_neg_identifier {$$=_asn1_add_node(TYPE_DEFAULT); | DEFAULT FALSE {$$=_asn1_add_node(TYPE_DEFAULT|CONST_FALSE);} ; + +pos_neg_list: pos_neg_num + | pos_neg_list '|' pos_neg_num +; + + integer_def: INTEGER {$$=_asn1_add_node(TYPE_INTEGER);} | INTEGER'{'constant_list'}' {$$=_asn1_add_node(TYPE_INTEGER|CONST_LIST); _asn1_set_down($$,$3);} - | integer_def'('num_identifier'.''.'num_identifier')' + | INTEGER'(' pos_neg_list ')' {$$=_asn1_add_node(TYPE_INTEGER);} + | INTEGER'('num_identifier'.''.'num_identifier')' {$$=_asn1_add_node(TYPE_INTEGER|CONST_MIN_MAX); _asn1_set_down($$,_asn1_add_node(TYPE_SIZE)); _asn1_set_value(_asn1_get_down($$),$6,strlen($6)+1); @@ -412,7 +420,7 @@ const int key_word_token[]={ASSIG,OPTIONAL,INTEGER,SIZE,OCTET,STRING int _asn1_yylex() { - int c,counter=0,k; + int c,counter=0,k,lastc; char string[MAX_NAME_SIZE+1]; /* will contain the next token */ while(1) @@ -427,7 +435,7 @@ _asn1_yylex() if(c=='(' || c==')' || c=='[' || c==']' || c=='{' || c=='}' || c==',' || c=='.' || - c=='+'){ + c=='+' || c=='|'){ lastToken[0]=c;lastToken[1]=0; return c; } @@ -438,15 +446,18 @@ _asn1_yylex() return '-'; } else{ /* Comments */ + lastc=0; counter=0; - /* A comment finishes at the end of line */ - while((c=fgetc(file_asn1))!=EOF && c!='\n'); + /* A comment finishes at the next double hypen or the end of line */ + while((c=fgetc(file_asn1))!=EOF && c!='\n' && + (lastc!='-' || (lastc=='-' && c!='-'))) + lastc=c; if(c==EOF){ strcpy(lastToken,"End Of File"); return 0; } else{ - lineNumber++; + if(c=='\n') lineNumber++; continue; /* next char, please! (repeat the search) */ } } diff --git a/lib/int.h b/lib/int.h index 9aa0543..65d45eb 100644 --- a/lib/int.h +++ b/lib/int.h @@ -32,7 +32,7 @@ #include -#define LIBTASN1_VERSION "0.2.5" +#define LIBTASN1_VERSION "0.2.6" #define MAX32 4294967295 #define MAX24 16777215 diff --git a/lib/libtasn1.h b/lib/libtasn1.h index e1bb380..68d245a 100644 --- a/lib/libtasn1.h +++ b/lib/libtasn1.h @@ -28,7 +28,7 @@ extern "C" { #endif -#define LIBTASN1_VERSION "0.2.5" +#define LIBTASN1_VERSION "0.2.6" #include #include diff --git a/src/asn1Coding.c b/src/asn1Coding.c index aaefe07..774547b 100644 --- a/src/asn1Coding.c +++ b/src/asn1Coding.c @@ -77,6 +77,7 @@ int readAssignment(FILE *file,char *varName, char *value){ ret=fscanf(file,"%s",varName); if(ret==EOF) return ASSIGNMENT_EOF; + if(!strcmp(varName,"''")) varName[0]=0; ret=fscanf(file,"%s",value); if(ret==EOF) return ASSIGNMENT_ERROR; diff --git a/tests/Test_parser.asn b/tests/Test_parser.asn index e9b0ce9..42c6e4a 100644 --- a/tests/Test_parser.asn +++ b/tests/Test_parser.asn @@ -11,8 +11,8 @@ BEGIN Sequence1 ::= SEQUENCE{ - int1 INTEGER, - int2 INTEGER, + int1 -- Test -- INTEGER (5), + int2 INTEGER (10 | 12), generic GeneralString } diff --git a/tests/Test_tree.c b/tests/Test_tree.c index ea367c1..d25c28f 100644 --- a/tests/Test_tree.c +++ b/tests/Test_tree.c @@ -411,7 +411,7 @@ main(int argc,char *argv[]) printf( "/****************************************/\n\n"); /* Check version */ - if(asn1_check_version("0.2.5")==NULL) + if(asn1_check_version("0.2.6")==NULL) printf("\nLibrary version check ERROR:\n actual version: %s\n\n",asn1_check_version(NULL)); if(1) -- 2.11.4.GIT