diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-22 01:41:31 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-22 18:19:33 +0100 |
commit | 63db52e21259ccb3910978af1d60d75699f478c0 (patch) | |
tree | cbb9801051e0b2291d7e25998f192ea1c77f8738 | |
parent | a26e0f5c84405ba760022749984bb73f1d548431 (diff) | |
download | libtasn1-63db52e21259ccb3910978af1d60d75699f478c0.tar.gz libtasn1-63db52e21259ccb3910978af1d60d75699f478c0.tar.bz2 libtasn1-63db52e21259ccb3910978af1d60d75699f478c0.zip |
Added more ASN.1 string types and several simplifications.
-rw-r--r-- | lib/ASN1.c | 1131 | ||||
-rw-r--r-- | lib/ASN1.y | 258 | ||||
-rw-r--r-- | lib/coding.c | 205 | ||||
-rw-r--r-- | lib/decoding.c | 299 | ||||
-rw-r--r-- | lib/element.c | 176 | ||||
-rw-r--r-- | lib/int.h | 32 | ||||
-rw-r--r-- | lib/libtasn1.h | 18 | ||||
-rw-r--r-- | lib/parser_aux.c | 44 | ||||
-rw-r--r-- | lib/structure.c | 152 |
9 files changed, 1275 insertions, 1040 deletions
@@ -109,7 +109,7 @@ #include <structure.h> static FILE *file_asn1; /* Pointer to file to parse */ -static int result_parse; /* result of the parser +static int result_parse = 0; /* result of the parser algorithm */ static asn1_node p_tree; /* pointer to the root of the structure created by the @@ -191,9 +191,17 @@ static int _asn1_yylex(void); UTCTime = 290, GeneralizedTime = 291, GeneralString = 292, - FROM = 293, - IMPORTS = 294, - ENUMERATED = 295 + NumericString = 293, + IA5String = 294, + TeletexString = 295, + PrintableString = 296, + UniversalString = 297, + BMPString = 298, + UTF8String = 299, + VisibleString = 300, + FROM = 301, + IMPORTS = 302, + ENUMERATED = 303 }; #endif /* Tokens. */ @@ -232,9 +240,17 @@ static int _asn1_yylex(void); #define UTCTime 290 #define GeneralizedTime 291 #define GeneralString 292 -#define FROM 293 -#define IMPORTS 294 -#define ENUMERATED 295 +#define NumericString 293 +#define IA5String 294 +#define TeletexString 295 +#define PrintableString 296 +#define UniversalString 297 +#define BMPString 298 +#define UTF8String 299 +#define VisibleString 300 +#define FROM 301 +#define IMPORTS 302 +#define ENUMERATED 303 @@ -253,7 +269,7 @@ typedef union YYSTYPE /* Line 293 of yacc.c */ -#line 257 "ASN1.c" +#line 273 "ASN1.c" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -265,7 +281,7 @@ typedef union YYSTYPE /* Line 343 of yacc.c */ -#line 269 "ASN1.c" +#line 285 "ASN1.c" #ifdef short # undef short @@ -484,20 +500,20 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 5 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 192 +#define YYLAST 217 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 52 +#define YYNTOKENS 60 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 43 +#define YYNNTS 51 /* YYNRULES -- Number of rules. */ -#define YYNRULES 100 +#define YYNRULES 125 /* YYNRULES -- Number of states. */ -#define YYNSTATES 190 +#define YYNSTATES 216 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 295 +#define YYMAXUTOK 303 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -509,15 +525,15 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 43, 44, 2, 41, 45, 42, 51, 2, 2, 2, + 51, 52, 2, 49, 53, 50, 59, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 46, 2, 47, 2, 2, 2, 2, 2, 2, + 2, 54, 2, 55, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 49, 48, 50, 2, 2, 2, 2, + 2, 2, 2, 57, 56, 58, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -534,7 +550,8 @@ static const yytype_uint8 yytranslate[] = 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40 + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48 }; #if YYDEBUG @@ -546,67 +563,77 @@ static const yytype_uint16 yyprhs[] = 28, 30, 32, 36, 41, 43, 47, 49, 54, 56, 59, 61, 63, 65, 69, 74, 76, 79, 82, 85, 88, 91, 93, 97, 99, 104, 109, 117, 119, 121, - 123, 128, 136, 138, 142, 144, 147, 150, 154, 159, - 161, 165, 168, 172, 178, 183, 186, 188, 191, 193, - 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, - 215, 217, 219, 222, 224, 227, 230, 233, 235, 239, - 244, 248, 253, 258, 262, 267, 272, 274, 279, 283, - 291, 298, 303, 305, 307, 309, 312, 317, 321, 323, - 325 + 123, 128, 136, 138, 142, 144, 147, 149, 152, 154, + 157, 159, 162, 164, 167, 169, 172, 174, 177, 179, + 182, 184, 187, 190, 194, 199, 201, 205, 208, 212, + 218, 223, 226, 228, 231, 233, 235, 237, 239, 241, + 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, + 263, 265, 267, 269, 271, 273, 275, 278, 280, 283, + 286, 289, 291, 295, 300, 304, 309, 314, 318, 323, + 328, 330, 335, 339, 342, 350, 357, 362, 364, 366, + 368, 371, 376, 380, 382, 384 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { - 53, 0, -1, 93, 31, 94, 32, 3, 33, 92, - 34, -1, 4, -1, 41, 4, -1, 42, 4, -1, - 54, -1, 55, -1, 4, -1, 5, -1, 56, -1, - 5, -1, 43, 56, 44, -1, 5, 43, 56, 44, - -1, 59, -1, 60, 45, 59, -1, 57, -1, 5, - 43, 4, 44, -1, 61, -1, 62, 61, -1, 13, - -1, 14, -1, 15, -1, 46, 4, 47, -1, 46, - 63, 4, 47, -1, 64, -1, 64, 29, -1, 64, - 30, -1, 16, 58, -1, 16, 22, -1, 16, 23, - -1, 56, -1, 67, 48, 56, -1, 7, -1, 7, - 49, 60, 50, -1, 68, 43, 67, 44, -1, 68, - 43, 57, 51, 51, 57, 44, -1, 21, -1, 35, - -1, 36, -1, 8, 43, 57, 44, -1, 8, 43, - 57, 51, 51, 57, 44, -1, 71, -1, 43, 71, - 44, -1, 37, -1, 37, 72, -1, 9, 10, -1, - 9, 10, 72, -1, 5, 43, 4, 44, -1, 75, - -1, 76, 45, 75, -1, 12, 10, -1, 12, 10, - 72, -1, 12, 10, 49, 76, 50, -1, 40, 49, - 76, 50, -1, 19, 20, -1, 5, -1, 5, 72, - -1, 68, -1, 78, -1, 69, -1, 70, -1, 74, - -1, 77, -1, 73, -1, 85, -1, 79, -1, 87, - -1, 88, -1, 86, -1, 24, -1, 80, -1, 65, - 80, -1, 81, -1, 81, 66, -1, 81, 6, -1, - 5, 82, -1, 83, -1, 84, 45, 83, -1, 11, - 49, 84, 50, -1, 11, 18, 80, -1, 11, 72, - 18, 80, -1, 28, 49, 84, 50, -1, 28, 18, - 80, -1, 28, 72, 18, 80, -1, 17, 49, 84, - 50, -1, 25, -1, 25, 26, 27, 5, -1, 5, - 3, 81, -1, 5, 19, 20, 3, 49, 62, 50, - -1, 5, 5, 3, 49, 62, 50, -1, 5, 7, - 3, 56, -1, 89, -1, 90, -1, 91, -1, 92, - 91, -1, 5, 49, 62, 50, -1, 5, 49, 50, - -1, 5, -1, 29, -1, 30, -1 + 61, 0, -1, 109, 31, 110, 32, 3, 33, 108, + 34, -1, 4, -1, 49, 4, -1, 50, 4, -1, + 62, -1, 63, -1, 4, -1, 5, -1, 64, -1, + 5, -1, 51, 64, 52, -1, 5, 51, 64, 52, + -1, 67, -1, 68, 53, 67, -1, 65, -1, 5, + 51, 4, 52, -1, 69, -1, 70, 69, -1, 13, + -1, 14, -1, 15, -1, 54, 4, 55, -1, 54, + 71, 4, 55, -1, 72, -1, 72, 29, -1, 72, + 30, -1, 16, 66, -1, 16, 22, -1, 16, 23, + -1, 64, -1, 75, 56, 64, -1, 7, -1, 7, + 57, 68, 58, -1, 76, 51, 75, 52, -1, 76, + 51, 65, 59, 59, 65, 52, -1, 21, -1, 35, + -1, 36, -1, 8, 51, 65, 52, -1, 8, 51, + 65, 59, 59, 65, 52, -1, 79, -1, 51, 79, + 52, -1, 37, -1, 37, 80, -1, 38, -1, 38, + 80, -1, 39, -1, 39, 80, -1, 40, -1, 40, + 80, -1, 41, -1, 41, 80, -1, 42, -1, 42, + 80, -1, 43, -1, 43, 80, -1, 44, -1, 44, + 80, -1, 45, -1, 45, 80, -1, 9, 10, -1, + 9, 10, 80, -1, 5, 51, 4, 52, -1, 91, + -1, 92, 53, 91, -1, 12, 10, -1, 12, 10, + 80, -1, 12, 10, 57, 92, 58, -1, 48, 57, + 92, 58, -1, 19, 20, -1, 5, -1, 5, 80, + -1, 76, -1, 94, -1, 77, -1, 78, -1, 90, + -1, 93, -1, 81, -1, 82, -1, 83, -1, 84, + -1, 85, -1, 86, -1, 87, -1, 88, -1, 89, + -1, 101, -1, 95, -1, 103, -1, 104, -1, 102, + -1, 24, -1, 96, -1, 73, 96, -1, 97, -1, + 97, 74, -1, 97, 6, -1, 5, 98, -1, 99, + -1, 100, 53, 99, -1, 11, 57, 100, 58, -1, + 11, 18, 96, -1, 11, 80, 18, 96, -1, 28, + 57, 100, 58, -1, 28, 18, 96, -1, 28, 80, + 18, 96, -1, 17, 57, 100, 58, -1, 25, -1, + 25, 26, 27, 5, -1, 5, 3, 97, -1, 1, + 97, -1, 5, 19, 20, 3, 57, 70, 58, -1, + 5, 5, 3, 57, 70, 58, -1, 5, 7, 3, + 64, -1, 105, -1, 106, -1, 107, -1, 108, 107, + -1, 5, 57, 70, 58, -1, 5, 57, 58, -1, + 5, -1, 29, -1, 30, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 118, 118, 131, 132, 135, 139, 140, 143, 144, - 147, 148, 151, 153, 158, 159, 163, 165, 170, 171, - 175, 176, 177, 180, 182, 186, 187, 188, 191, 193, - 194, 198, 199, 203, 204, 206, 207, 214, 217, 218, - 221, 223, 229, 230, 233, 234, 238, 239, 243, 248, - 249, 253, 254, 255, 260, 266, 269, 271, 274, 275, - 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, - 286, 289, 290, 295, 296, 299, 302, 305, 306, 310, - 312, 314, 319, 321, 323, 328, 332, 333, 338, 341, - 345, 350, 356, 357, 360, 361, 365, 368, 370, 394, - 395 + 0, 129, 129, 142, 143, 146, 150, 151, 154, 155, + 158, 159, 162, 164, 169, 170, 174, 176, 181, 182, + 186, 187, 188, 191, 193, 197, 198, 199, 202, 204, + 205, 209, 210, 214, 215, 217, 218, 225, 228, 229, + 232, 234, 240, 241, 244, 245, 249, 250, 254, 255, + 259, 260, 264, 265, 269, 270, 274, 275, 279, 280, + 284, 285, 289, 290, 294, 299, 300, 304, 305, 306, + 311, 317, 320, 322, 325, 326, 327, 328, 329, 330, + 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 348, 349, 354, 355, 358, + 361, 364, 365, 369, 371, 373, 378, 380, 382, 387, + 391, 392, 397, 398, 401, 405, 410, 416, 417, 420, + 421, 425, 428, 430, 454, 455 }; #endif @@ -621,19 +648,23 @@ static const char *const yytname[] = "OBJECT", "STR_IDENTIFIER", "BOOLEAN", "ASN1_TRUE", "ASN1_FALSE", "TOKEN_NULL", "ANY", "DEFINED", "BY", "SET", "EXPLICIT", "IMPLICIT", "DEFINITIONS", "TAGS", "BEGIN", "END", "UTCTime", "GeneralizedTime", - "GeneralString", "FROM", "IMPORTS", "ENUMERATED", "'+'", "'-'", "'('", + "GeneralString", "NumericString", "IA5String", "TeletexString", + "PrintableString", "UniversalString", "BMPString", "UTF8String", + "VisibleString", "FROM", "IMPORTS", "ENUMERATED", "'+'", "'-'", "'('", "')'", "','", "'['", "']'", "'|'", "'{'", "'}'", "'.'", "$accept", "definitions", "pos_num", "neg_num", "pos_neg_num", "num_identifier", "pos_neg_identifier", "constant", "constant_list", "obj_constant", "obj_constant_list", "class", "tag_type", "tag", "default", "pos_neg_list", "integer_def", "boolean_def", "Time", "size_def2", - "size_def", "generalstring_def", "octet_string_def", "bit_element", - "bit_element_list", "bit_string_def", "enumerated_def", "object_def", - "type_assig_right", "type_assig_right_tag", - "type_assig_right_tag_default", "type_assig", "type_assig_list", - "sequence_def", "set_def", "choise_def", "any_def", "type_def", - "constant_def", "type_constant", "type_constant_list", "definitions_id", - "explicit_implicit", 0 + "size_def", "generalstring_def", "numericstring_def", "ia5string_def", + "teletexstring_def", "printablestring_def", "universalstring_def", + "bmpstring_def", "utf8string_def", "visiblestring_def", + "octet_string_def", "bit_element", "bit_element_list", "bit_string_def", + "enumerated_def", "object_def", "type_assig_right", + "type_assig_right_tag", "type_assig_right_tag_default", "type_assig", + "type_assig_list", "sequence_def", "set_def", "choise_def", "any_def", + "type_def", "constant_def", "type_constant", "type_constant_list", + "definitions_id", "explicit_implicit", 0 }; #endif @@ -646,25 +677,27 @@ static const yytype_uint16 yytoknum[] = 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 43, 45, 40, 41, 44, 91, 93, 124, 123, - 125, 46 + 295, 296, 297, 298, 299, 300, 301, 302, 303, 43, + 45, 40, 41, 44, 91, 93, 124, 123, 125, 46 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 52, 53, 54, 54, 55, 56, 56, 57, 57, - 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, - 63, 63, 63, 64, 64, 65, 65, 65, 66, 66, - 66, 67, 67, 68, 68, 68, 68, 69, 70, 70, - 71, 71, 72, 72, 73, 73, 74, 74, 75, 76, - 76, 77, 77, 77, 78, 79, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 81, 81, 82, 82, 82, 83, 84, 84, 85, - 85, 85, 86, 86, 86, 87, 88, 88, 89, 90, - 90, 90, 91, 91, 92, 92, 93, 93, 93, 94, - 94 + 0, 60, 61, 62, 62, 63, 64, 64, 65, 65, + 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, + 71, 71, 71, 72, 72, 73, 73, 73, 74, 74, + 74, 75, 75, 76, 76, 76, 76, 77, 78, 78, + 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, + 84, 84, 85, 85, 86, 86, 87, 87, 88, 88, + 89, 89, 90, 90, 91, 92, 92, 93, 93, 93, + 94, 95, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 97, 97, 98, 98, 98, + 99, 100, 100, 101, 101, 101, 102, 102, 102, 103, + 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, + 108, 109, 109, 109, 110, 110 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -674,13 +707,15 @@ static const yytype_uint8 yyr2[] = 1, 1, 3, 4, 1, 3, 1, 4, 1, 2, 1, 1, 1, 3, 4, 1, 2, 2, 2, 2, 2, 1, 3, 1, 4, 4, 7, 1, 1, 1, - 4, 7, 1, 3, 1, 2, 2, 3, 4, 1, - 3, 2, 3, 5, 4, 2, 1, 2, 1, 1, + 4, 7, 1, 3, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 2, 3, 4, 1, 3, 2, 3, 5, + 4, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 1, 2, 2, 2, 1, 3, 4, - 3, 4, 4, 3, 4, 4, 1, 4, 3, 7, - 6, 4, 1, 1, 1, 2, 4, 3, 1, 1, - 1 + 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, + 2, 1, 3, 4, 3, 4, 4, 3, 4, 4, + 1, 4, 3, 2, 7, 6, 4, 1, 1, 1, + 2, 4, 3, 1, 1, 1 }; /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. @@ -688,71 +723,79 @@ static const yytype_uint8 yyr2[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 0, 98, 0, 0, 0, 1, 0, 8, 9, 97, - 16, 18, 0, 99, 100, 0, 0, 96, 19, 0, - 0, 0, 17, 0, 0, 92, 93, 94, 0, 0, - 0, 0, 0, 2, 95, 56, 33, 0, 0, 0, - 0, 0, 37, 70, 86, 0, 38, 39, 44, 0, - 0, 25, 0, 58, 60, 61, 64, 62, 63, 59, - 66, 71, 88, 65, 69, 67, 68, 0, 0, 0, - 0, 0, 42, 57, 0, 46, 0, 0, 0, 51, - 0, 55, 0, 0, 0, 0, 45, 0, 0, 20, - 21, 22, 0, 26, 27, 72, 0, 0, 3, 0, - 0, 6, 7, 91, 0, 0, 0, 0, 0, 14, - 0, 47, 80, 0, 77, 0, 0, 0, 52, 0, - 0, 83, 0, 0, 0, 49, 0, 23, 0, 3, - 9, 31, 0, 0, 0, 4, 5, 0, 0, 43, - 0, 0, 0, 34, 73, 76, 0, 79, 81, 0, - 85, 87, 82, 84, 0, 0, 54, 24, 0, 35, - 0, 90, 0, 40, 0, 0, 12, 15, 75, 0, - 74, 78, 53, 0, 50, 0, 32, 89, 0, 13, - 11, 29, 30, 10, 28, 48, 0, 0, 36, 41 + 0, 123, 0, 0, 0, 1, 0, 8, 9, 122, + 16, 18, 0, 124, 125, 0, 0, 121, 19, 0, + 0, 0, 17, 0, 0, 0, 117, 118, 119, 0, + 72, 33, 0, 0, 0, 0, 0, 37, 94, 110, + 0, 38, 39, 44, 46, 48, 50, 52, 54, 56, + 58, 60, 0, 0, 25, 0, 74, 76, 77, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 78, 79, + 75, 90, 95, 113, 89, 93, 91, 92, 0, 0, + 0, 0, 2, 120, 0, 0, 42, 73, 0, 62, + 0, 0, 0, 67, 0, 71, 0, 0, 0, 0, + 45, 47, 49, 51, 53, 55, 57, 59, 61, 0, + 0, 20, 21, 22, 0, 26, 27, 96, 0, 112, + 0, 0, 0, 0, 0, 0, 0, 14, 0, 63, + 104, 0, 101, 0, 0, 0, 68, 0, 0, 107, + 0, 0, 0, 65, 0, 23, 0, 3, 9, 0, + 0, 6, 7, 31, 0, 0, 0, 3, 116, 0, + 0, 43, 0, 0, 0, 34, 97, 100, 0, 103, + 105, 0, 109, 111, 106, 108, 0, 0, 70, 24, + 4, 5, 0, 35, 0, 0, 0, 40, 0, 0, + 12, 15, 99, 0, 98, 102, 69, 0, 66, 0, + 32, 115, 0, 0, 13, 11, 29, 30, 10, 28, + 64, 0, 114, 0, 36, 41 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 2, 101, 102, 103, 10, 184, 109, 110, 11, - 12, 92, 51, 52, 170, 133, 53, 54, 55, 72, - 73, 56, 57, 125, 126, 58, 59, 60, 61, 62, - 145, 114, 115, 63, 64, 65, 66, 25, 26, 27, - 28, 3, 15 + -1, 2, 151, 152, 153, 10, 209, 127, 128, 11, + 12, 114, 54, 55, 194, 155, 56, 57, 58, 86, + 87, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 143, 144, 69, 70, 71, 72, 73, 167, 132, + 133, 74, 75, 76, 77, 26, 27, 28, 29, 3, + 15 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -96 +#define YYPACT_NINF -118 static const yytype_int16 yypact[] = { - 24, -14, 48, 56, 0, -96, -10, -96, -2, -96, - -96, -96, 2, -96, -96, 71, 111, -96, -96, 117, - 83, 96, -96, 127, 42, -96, -96, -96, 10, 77, - 130, 131, 115, -96, -96, 8, 90, 132, 13, 135, - 92, 126, -96, -96, 122, 15, -96, -96, 8, 100, - 93, 49, 119, 94, -96, -96, -96, -96, -96, -96, - -96, -96, -96, -96, -96, -96, -96, 102, 28, 149, - 110, 150, -96, -96, 17, 8, 119, 152, 142, 22, - 152, -96, 134, 119, 152, 144, -96, 158, 118, -96, - -96, -96, 160, -96, -96, -96, 35, 88, -96, 162, - 163, -96, -96, -96, 120, 114, 124, 128, 28, -96, - -8, -96, -96, 77, -96, -7, 119, 158, -96, 18, - 165, -96, 50, 119, 129, -96, 54, -96, 133, 123, - -96, -96, 125, 37, 4, -96, -96, 88, -27, -96, - 28, 137, 17, -96, 20, -96, 152, -96, -96, 66, - -96, -96, -96, -96, 169, 158, -96, -96, 136, -96, - 28, -96, 7, -96, 138, 139, -96, -96, -96, 68, - -96, -96, -96, 140, -96, 114, -96, -96, 114, -96, - -96, -96, -96, -96, -96, -96, 141, 146, -96, -96 + 9, -25, 35, 61, 2, -118, 12, -118, 49, -118, + -118, -118, 6, -118, -118, 70, 100, -118, -118, 54, + 58, 112, -118, 45, 84, 44, -118, -118, -118, 32, + 31, 90, 144, 22, 145, 92, 137, -118, -118, 133, + 26, -118, -118, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 104, 103, 111, 139, 114, -118, -118, -118, + -118, -118, -118, -118, -118, -118, -118, -118, -118, -118, + -118, -118, -118, -118, -118, -118, -118, -118, 84, 159, + 163, 149, -118, -118, 117, 162, -118, -118, 21, 31, + 139, 166, 154, 5, 166, -118, 158, 139, 166, 168, + -118, -118, -118, -118, -118, -118, -118, -118, -118, 183, + 134, -118, -118, -118, 187, -118, -118, -118, 64, -118, + 135, 25, 190, 138, 142, 146, 25, -118, 1, -118, + -118, 84, -118, 41, 139, 183, -118, 53, 191, -118, + 77, 139, 147, -118, 78, -118, 140, 141, -118, 195, + 197, -118, -118, -118, 143, 34, 148, -118, -118, 150, + -21, -118, 25, 151, 21, -118, 42, -118, 166, -118, + -118, 81, -118, -118, -118, -118, 200, 183, -118, -118, + -118, -118, 152, -118, 25, 20, 148, -118, 153, 156, + -118, -118, -118, 48, -118, -118, -118, 157, -118, 138, + -118, -118, 23, 138, -118, -118, -118, -118, -118, -118, + -118, 161, -118, 164, -118, -118 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -96, -96, -96, -96, -94, -95, -96, 33, -96, -12, - -84, -96, -96, -96, -96, -96, -96, -96, -96, 106, - -20, -96, -96, 23, 62, -96, -96, -96, -49, 69, - -96, 40, 41, -96, -96, -96, -96, -96, -96, 164, - -96, -96, -96 + -118, -118, -118, -118, -117, -115, -118, 46, -118, -12, + -71, -118, -118, -118, -118, -118, -118, -118, -118, 120, + -28, -118, -118, -118, -118, -118, -118, -118, -118, -118, + -118, 29, 79, -118, -118, -118, -54, -76, -118, 47, + 39, -118, -118, -118, -118, -118, -118, 188, -118, -118, + -118 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -761,81 +804,88 @@ static const yytype_int16 yypgoto[] = #define YYTABLE_NINF -9 static const yytype_int16 yytable[] = { - 18, 132, 131, 95, 7, 8, 7, 8, 7, 8, - 138, 7, 8, 134, 141, 24, 70, 163, 78, 13, - 14, 70, 107, 70, 164, 85, 168, 112, 86, 1, - 70, 76, 98, 83, 121, 4, 169, 142, 146, 129, - 130, 16, 143, 147, 33, 29, 165, 30, 5, 31, - 9, 71, 17, 162, 161, 111, 71, 177, 71, 118, - 108, 32, 77, 146, 84, 71, 176, 148, 150, 99, - 100, 117, 98, 180, 153, 183, 99, 100, 93, 94, - 186, 159, 35, 187, 36, 160, 37, 6, 38, 39, - 181, 182, 7, 8, 40, 146, 41, 88, 42, 155, - 152, 43, 44, 19, 156, 45, 89, 90, 91, 99, - 100, 155, 46, 47, 48, 20, 172, 49, 7, 130, - 21, 119, 18, 50, 35, 122, 36, 22, 37, 23, - 38, 39, 24, 67, 68, 69, 40, 96, 41, 74, - 42, 80, 75, 43, 44, 79, 81, 45, 82, 87, - 18, 97, 104, 105, 46, 47, 48, 113, 70, 49, - 116, 120, 123, 124, 128, 127, 135, 136, 139, 137, - 151, 140, 154, 173, -8, 167, 158, 106, 174, 149, - 157, 166, 144, 179, 185, 188, 171, 175, 0, 178, - 189, 0, 34 + 18, 117, 119, 154, 158, 92, 7, 8, 160, 163, + 7, 8, 99, 84, 1, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 7, 8, 125, 7, 8, 157, + 84, 187, 4, 24, 84, 5, 130, 25, 188, 84, + 90, 13, 14, 139, 97, 189, 24, 78, 192, 79, + 25, 80, 157, 205, 164, 166, 85, 21, 193, 165, + 9, 129, 135, 81, 17, 136, 82, 200, 147, 148, + 206, 207, 126, 85, 149, 150, 208, 85, 201, 91, + 170, 212, 85, 98, 211, 185, 183, 175, 213, 30, + 184, 31, 6, 32, 168, 33, 34, 149, 150, 169, + 16, 35, 19, 36, 20, 37, 168, 110, 38, 39, + 22, 172, 40, 149, 150, 202, 111, 112, 113, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 168, 177, 52, 137, 177, 174, 178, 140, 53, 196, + 115, 116, 7, 148, 30, 23, 31, 88, 32, 94, + 33, 34, 7, 8, 89, 93, 35, 95, 36, 96, + 37, 109, 120, 38, 39, 118, 121, 40, 123, 122, + 84, 131, 134, 18, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 138, 141, 52, 142, 145, + 18, 146, 156, 159, 161, 179, 173, 162, 176, 180, + -8, 181, 182, 190, 197, 124, 198, 186, 204, 210, + 191, 199, 203, 214, 171, 195, 215, 83 }; #define yypact_value_is_default(yystate) \ - ((yystate) == (-96)) + ((yystate) == (-118)) #define yytable_value_is_error(yytable_value) \ YYID (0) -static const yytype_int16 yycheck[] = +static const yytype_uint8 yycheck[] = { - 12, 96, 96, 52, 4, 5, 4, 5, 4, 5, - 105, 4, 5, 97, 108, 5, 8, 44, 38, 29, - 30, 8, 5, 8, 51, 45, 6, 76, 48, 5, - 8, 18, 4, 18, 83, 49, 16, 45, 45, 4, - 5, 43, 50, 50, 34, 3, 140, 5, 0, 7, - 50, 43, 50, 137, 50, 75, 43, 50, 43, 79, - 43, 19, 49, 45, 49, 43, 160, 116, 50, 41, - 42, 49, 4, 5, 123, 169, 41, 42, 29, 30, - 175, 44, 5, 178, 7, 48, 9, 31, 11, 12, - 22, 23, 4, 5, 17, 45, 19, 4, 21, 45, - 50, 24, 25, 32, 50, 28, 13, 14, 15, 41, - 42, 45, 35, 36, 37, 4, 50, 40, 4, 5, - 3, 80, 134, 46, 5, 84, 7, 44, 9, 33, - 11, 12, 5, 3, 3, 20, 17, 43, 19, 49, - 21, 49, 10, 24, 25, 10, 20, 28, 26, 49, - 162, 49, 3, 43, 35, 36, 37, 5, 8, 40, - 18, 27, 18, 5, 4, 47, 4, 4, 44, 49, - 5, 43, 43, 4, 51, 142, 51, 71, 155, 117, - 47, 44, 113, 44, 44, 44, 146, 51, -1, 51, - 44, -1, 28 + 12, 55, 78, 118, 121, 33, 4, 5, 123, 126, + 4, 5, 40, 8, 5, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 4, 5, 5, 4, 5, 4, + 8, 52, 57, 1, 8, 0, 90, 5, 59, 8, + 18, 29, 30, 97, 18, 162, 1, 3, 6, 5, + 5, 7, 4, 5, 53, 131, 51, 3, 16, 58, + 58, 89, 57, 19, 58, 93, 34, 184, 4, 5, + 22, 23, 51, 51, 49, 50, 193, 51, 58, 57, + 134, 58, 51, 57, 199, 156, 52, 141, 203, 5, + 56, 7, 31, 9, 53, 11, 12, 49, 50, 58, + 51, 17, 32, 19, 4, 21, 53, 4, 24, 25, + 52, 58, 28, 49, 50, 186, 13, 14, 15, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 53, 53, 48, 94, 53, 58, 58, 98, 54, 58, + 29, 30, 4, 5, 5, 33, 7, 57, 9, 57, + 11, 12, 4, 5, 10, 10, 17, 20, 19, 26, + 21, 57, 3, 24, 25, 51, 3, 28, 51, 20, + 8, 5, 18, 185, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 27, 18, 48, 5, 55, + 202, 4, 57, 3, 52, 55, 5, 51, 51, 4, + 59, 4, 59, 52, 4, 85, 177, 57, 52, 52, + 164, 59, 59, 52, 135, 168, 52, 29 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 5, 53, 93, 49, 0, 31, 4, 5, 50, - 57, 61, 62, 29, 30, 94, 43, 50, 61, 32, - 4, 3, 44, 33, 5, 89, 90, 91, 92, 3, - 5, 7, 19, 34, 91, 5, 7, 9, 11, 12, - 17, 19, 21, 24, 25, 28, 35, 36, 37, 40, - 46, 64, 65, 68, 69, 70, 73, 74, 77, 78, - 79, 80, 81, 85, 86, 87, 88, 3, 3, 20, - 8, 43, 71, 72, 49, 10, 18, 49, 72, 10, - 49, 20, 26, 18, 49, 72, 72, 49, 4, 13, - 14, 15, 63, 29, 30, 80, 43, 49, 4, 41, - 42, 54, 55, 56, 3, 43, 71, 5, 43, 59, - 60, 72, 80, 5, 83, 84, 18, 49, 72, 84, - 27, 80, 84, 18, 5, 75, 76, 47, 4, 4, - 5, 56, 57, 67, 62, 4, 4, 49, 57, 44, - 43, 56, 45, 50, 81, 82, 45, 50, 80, 76, - 50, 5, 50, 80, 43, 45, 50, 47, 51, 44, - 48, 50, 62, 44, 51, 56, 44, 59, 6, 16, - 66, 83, 50, 4, 75, 51, 56, 50, 51, 44, - 5, 22, 23, 56, 58, 44, 57, 57, 44, 44 + 0, 5, 61, 109, 57, 0, 31, 4, 5, 58, + 65, 69, 70, 29, 30, 110, 51, 58, 69, 32, + 4, 3, 52, 33, 1, 5, 105, 106, 107, 108, + 5, 7, 9, 11, 12, 17, 19, 21, 24, 25, + 28, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 48, 54, 72, 73, 76, 77, 78, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 93, + 94, 95, 96, 97, 101, 102, 103, 104, 3, 5, + 7, 19, 34, 107, 8, 51, 79, 80, 57, 10, + 18, 57, 80, 10, 57, 20, 26, 18, 57, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 57, + 4, 13, 14, 15, 71, 29, 30, 96, 51, 97, + 3, 3, 20, 51, 79, 5, 51, 67, 68, 80, + 96, 5, 99, 100, 18, 57, 80, 100, 27, 96, + 100, 18, 5, 91, 92, 55, 4, 4, 5, 49, + 50, 62, 63, 64, 65, 75, 57, 4, 64, 3, + 65, 52, 51, 64, 53, 58, 97, 98, 53, 58, + 96, 92, 58, 5, 58, 96, 51, 53, 58, 55, + 4, 4, 59, 52, 56, 70, 57, 52, 59, 64, + 52, 67, 6, 16, 74, 99, 58, 4, 91, 59, + 64, 58, 70, 59, 52, 5, 22, 23, 64, 66, + 52, 65, 58, 65, 52, 52 }; #define yyerrok (yyerrstatus = 0) @@ -1672,8 +1722,8 @@ yyreduce: case 2: /* Line 1806 of yacc.c */ -#line 121 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_DEFINITIONS|(yyvsp[(3) - (8)].constant)); +#line 132 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_DEFINITIONS|(yyvsp[(3) - (8)].constant)); _asn1_set_name((yyval.node),_asn1_get_name((yyvsp[(1) - (8)].node))); _asn1_set_name((yyvsp[(1) - (8)].node),""); _asn1_set_right((yyvsp[(1) - (8)].node),(yyvsp[(7) - (8)].node)); @@ -1686,21 +1736,21 @@ yyreduce: case 3: /* Line 1806 of yacc.c */ -#line 131 "ASN1.y" +#line 142 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 4: /* Line 1806 of yacc.c */ -#line 132 "ASN1.y" +#line 143 "ASN1.y" {strcpy((yyval.str),(yyvsp[(2) - (2)].str));} break; case 5: /* Line 1806 of yacc.c */ -#line 135 "ASN1.y" +#line 146 "ASN1.y" {strcpy((yyval.str),"-"); strcat((yyval.str),(yyvsp[(2) - (2)].str));} break; @@ -1708,58 +1758,58 @@ yyreduce: case 6: /* Line 1806 of yacc.c */ -#line 139 "ASN1.y" +#line 150 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 7: /* Line 1806 of yacc.c */ -#line 140 "ASN1.y" +#line 151 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 8: /* Line 1806 of yacc.c */ -#line 143 "ASN1.y" +#line 154 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 9: /* Line 1806 of yacc.c */ -#line 144 "ASN1.y" +#line 155 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 10: /* Line 1806 of yacc.c */ -#line 147 "ASN1.y" +#line 158 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 11: /* Line 1806 of yacc.c */ -#line 148 "ASN1.y" +#line 159 "ASN1.y" {strcpy((yyval.str),(yyvsp[(1) - (1)].str));} break; case 12: /* Line 1806 of yacc.c */ -#line 151 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CONSTANT); +#line 162 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_value((yyval.node),(yyvsp[(2) - (3)].str),strlen((yyvsp[(2) - (3)].str))+1);} break; case 13: /* Line 1806 of yacc.c */ -#line 153 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CONSTANT); +#line 164 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str)); _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} break; @@ -1767,14 +1817,14 @@ yyreduce: case 14: /* Line 1806 of yacc.c */ -#line 158 "ASN1.y" +#line 169 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; case 15: /* Line 1806 of yacc.c */ -#line 159 "ASN1.y" +#line 170 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (3)].node); _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (3)].node)),(yyvsp[(3) - (3)].node));} break; @@ -1782,16 +1832,16 @@ yyreduce: case 16: /* Line 1806 of yacc.c */ -#line 163 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CONSTANT); +#line 174 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_value((yyval.node),(yyvsp[(1) - (1)].str),strlen((yyvsp[(1) - (1)].str))+1);} break; case 17: /* Line 1806 of yacc.c */ -#line 165 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CONSTANT); +#line 176 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str)); _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} break; @@ -1799,14 +1849,14 @@ yyreduce: case 18: /* Line 1806 of yacc.c */ -#line 170 "ASN1.y" +#line 181 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; case 19: /* Line 1806 of yacc.c */ -#line 171 "ASN1.y" +#line 182 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (2)].node); _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (2)].node)),(yyvsp[(2) - (2)].node));} break; @@ -1814,111 +1864,111 @@ yyreduce: case 20: /* Line 1806 of yacc.c */ -#line 175 "ASN1.y" +#line 186 "ASN1.y" {(yyval.constant)=CONST_UNIVERSAL;} break; case 21: /* Line 1806 of yacc.c */ -#line 176 "ASN1.y" +#line 187 "ASN1.y" {(yyval.constant)=CONST_PRIVATE;} break; case 22: /* Line 1806 of yacc.c */ -#line 177 "ASN1.y" +#line 188 "ASN1.y" {(yyval.constant)=CONST_APPLICATION;} break; case 23: /* Line 1806 of yacc.c */ -#line 180 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_TAG); +#line 191 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TAG); _asn1_set_value((yyval.node),(yyvsp[(2) - (3)].str),strlen((yyvsp[(2) - (3)].str))+1);} break; case 24: /* Line 1806 of yacc.c */ -#line 182 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_TAG | (yyvsp[(2) - (4)].constant)); +#line 193 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TAG | (yyvsp[(2) - (4)].constant)); _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} break; case 25: /* Line 1806 of yacc.c */ -#line 186 "ASN1.y" +#line 197 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; case 26: /* Line 1806 of yacc.c */ -#line 187 "ASN1.y" +#line 198 "ASN1.y" {(yyval.node)=_asn1_mod_type((yyvsp[(1) - (2)].node),CONST_EXPLICIT);} break; case 27: /* Line 1806 of yacc.c */ -#line 188 "ASN1.y" +#line 199 "ASN1.y" {(yyval.node)=_asn1_mod_type((yyvsp[(1) - (2)].node),CONST_IMPLICIT);} break; case 28: /* Line 1806 of yacc.c */ -#line 191 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_DEFAULT); +#line 202 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_DEFAULT); _asn1_set_value((yyval.node),(yyvsp[(2) - (2)].str),strlen((yyvsp[(2) - (2)].str))+1);} break; case 29: /* Line 1806 of yacc.c */ -#line 193 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_DEFAULT|CONST_TRUE);} +#line 204 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_TRUE);} break; case 30: /* Line 1806 of yacc.c */ -#line 194 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_DEFAULT|CONST_FALSE);} +#line 205 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_FALSE);} break; case 33: /* Line 1806 of yacc.c */ -#line 203 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_INTEGER);} +#line 214 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} break; case 34: /* Line 1806 of yacc.c */ -#line 204 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_INTEGER|CONST_LIST); +#line 215 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_LIST); _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} break; case 35: /* Line 1806 of yacc.c */ -#line 206 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_INTEGER);} +#line 217 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} break; case 36: /* Line 1806 of yacc.c */ -#line 208 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_INTEGER|CONST_MIN_MAX); - _asn1_set_down((yyval.node),_asn1_add_static_node(TYPE_SIZE)); +#line 219 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_MIN_MAX); + _asn1_set_down((yyval.node),_asn1_add_static_node(ASN1_ETYPE_SIZE)); _asn1_set_value(_asn1_get_down((yyval.node)),(yyvsp[(6) - (7)].str),strlen((yyvsp[(6) - (7)].str))+1); _asn1_set_name(_asn1_get_down((yyval.node)),(yyvsp[(3) - (7)].str));} break; @@ -1926,37 +1976,37 @@ yyreduce: case 37: /* Line 1806 of yacc.c */ -#line 214 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_BOOLEAN);} +#line 225 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BOOLEAN);} break; case 38: /* Line 1806 of yacc.c */ -#line 217 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_TIME|CONST_UTC);} +#line 228 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TIME|CONST_UTC);} break; case 39: /* Line 1806 of yacc.c */ -#line 218 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_TIME|CONST_GENERALIZED);} +#line 229 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TIME|CONST_GENERALIZED);} break; case 40: /* Line 1806 of yacc.c */ -#line 221 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SIZE|CONST_1_PARAM); +#line 232 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_1_PARAM); _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} break; case 41: /* Line 1806 of yacc.c */ -#line 224 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SIZE|CONST_MIN_MAX); +#line 235 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_MIN_MAX); _asn1_set_value((yyval.node),(yyvsp[(3) - (7)].str),strlen((yyvsp[(3) - (7)].str))+1); _asn1_set_name((yyval.node),(yyvsp[(6) - (7)].str));} break; @@ -1964,451 +2014,634 @@ yyreduce: case 42: /* Line 1806 of yacc.c */ -#line 229 "ASN1.y" +#line 240 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; case 43: /* Line 1806 of yacc.c */ -#line 230 "ASN1.y" +#line 241 "ASN1.y" {(yyval.node)=(yyvsp[(2) - (3)].node);} break; case 44: /* Line 1806 of yacc.c */ -#line 233 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_GENERALSTRING);} +#line 244 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING);} break; case 45: /* Line 1806 of yacc.c */ -#line 234 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_GENERALSTRING|CONST_SIZE); +#line 245 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING|CONST_SIZE); _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 46: /* Line 1806 of yacc.c */ -#line 238 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OCTET_STRING);} +#line 249 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_NUMERICSTRING|CONST_UNIVERSAL);} break; case 47: /* Line 1806 of yacc.c */ -#line 239 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OCTET_STRING|CONST_SIZE); - _asn1_set_down((yyval.node),(yyvsp[(3) - (3)].node));} +#line 250 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_NUMERICSTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 48: /* Line 1806 of yacc.c */ -#line 243 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CONSTANT); - _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str)); - _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} +#line 254 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_IA5STRING);} break; case 49: /* Line 1806 of yacc.c */ -#line 248 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 255 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_IA5STRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 50: /* Line 1806 of yacc.c */ -#line 249 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (3)].node); - _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (3)].node)),(yyvsp[(3) - (3)].node));} +#line 259 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TELETEXSTRING);} break; case 51: /* Line 1806 of yacc.c */ -#line 253 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_BIT_STRING);} +#line 260 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_TELETEXSTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 52: /* Line 1806 of yacc.c */ -#line 254 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_BIT_STRING|CONST_SIZE);} +#line 264 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_PRINTABLESTRING);} break; case 53: /* Line 1806 of yacc.c */ -#line 256 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_BIT_STRING|CONST_LIST); - _asn1_set_down((yyval.node),(yyvsp[(4) - (5)].node));} +#line 265 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_PRINTABLESTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 54: /* Line 1806 of yacc.c */ -#line 261 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_ENUMERATED|CONST_LIST); - _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} +#line 269 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_UNIVERSALSTRING);} break; case 55: /* Line 1806 of yacc.c */ -#line 266 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID);} +#line 270 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_UNIVERSALSTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 56: /* Line 1806 of yacc.c */ -#line 269 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_IDENTIFIER); - _asn1_set_value((yyval.node),(yyvsp[(1) - (1)].str),strlen((yyvsp[(1) - (1)].str))+1);} +#line 274 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BMPSTRING);} break; case 57: /* Line 1806 of yacc.c */ -#line 271 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_IDENTIFIER|CONST_SIZE); - _asn1_set_value((yyval.node),(yyvsp[(1) - (2)].str),strlen((yyvsp[(1) - (2)].str))+1); - _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} +#line 275 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BMPSTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 58: /* Line 1806 of yacc.c */ -#line 274 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 279 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_UTF8STRING);} break; case 59: /* Line 1806 of yacc.c */ -#line 275 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 280 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_UTF8STRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 60: /* Line 1806 of yacc.c */ -#line 276 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 284 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_VISIBLESTRING);} + break; + + case 61: + +/* Line 1806 of yacc.c */ +#line 285 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_VISIBLESTRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; case 62: /* Line 1806 of yacc.c */ -#line 278 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 289 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING);} break; case 63: /* Line 1806 of yacc.c */ -#line 279 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 290 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING|CONST_SIZE); + _asn1_set_down((yyval.node),(yyvsp[(3) - (3)].node));} break; case 64: /* Line 1806 of yacc.c */ -#line 280 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 294 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); + _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str)); + _asn1_set_value((yyval.node),(yyvsp[(3) - (4)].str),strlen((yyvsp[(3) - (4)].str))+1);} break; case 65: /* Line 1806 of yacc.c */ -#line 281 "ASN1.y" +#line 299 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; case 66: /* Line 1806 of yacc.c */ -#line 282 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 300 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (3)].node); + _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (3)].node)),(yyvsp[(3) - (3)].node));} break; case 67: /* Line 1806 of yacc.c */ -#line 283 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 304 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING);} break; case 68: /* Line 1806 of yacc.c */ -#line 284 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 305 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_SIZE);} break; case 69: /* Line 1806 of yacc.c */ -#line 285 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 307 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_LIST); + _asn1_set_down((yyval.node),(yyvsp[(4) - (5)].node));} break; case 70: /* Line 1806 of yacc.c */ -#line 286 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_NULL);} +#line 312 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_ENUMERATED|CONST_LIST); + _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} break; case 71: /* Line 1806 of yacc.c */ -#line 289 "ASN1.y" - {(yyval.node)=(yyvsp[(1) - (1)].node);} +#line 317 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID);} break; case 72: /* Line 1806 of yacc.c */ -#line 290 "ASN1.y" +#line 320 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER); + _asn1_set_value((yyval.node),(yyvsp[(1) - (1)].str),strlen((yyvsp[(1) - (1)].str))+1);} + break; + + case 73: + +/* Line 1806 of yacc.c */ +#line 322 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER|CONST_SIZE); + _asn1_set_value((yyval.node),(yyvsp[(1) - (2)].str),strlen((yyvsp[(1) - (2)].str))+1); + _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} + break; + + case 74: + +/* Line 1806 of yacc.c */ +#line 325 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 75: + +/* Line 1806 of yacc.c */ +#line 326 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 76: + +/* Line 1806 of yacc.c */ +#line 327 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 78: + +/* Line 1806 of yacc.c */ +#line 329 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 79: + +/* Line 1806 of yacc.c */ +#line 330 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 80: + +/* Line 1806 of yacc.c */ +#line 331 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 81: + +/* Line 1806 of yacc.c */ +#line 332 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 82: + +/* Line 1806 of yacc.c */ +#line 333 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 83: + +/* Line 1806 of yacc.c */ +#line 334 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 84: + +/* Line 1806 of yacc.c */ +#line 335 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 85: + +/* Line 1806 of yacc.c */ +#line 336 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 86: + +/* Line 1806 of yacc.c */ +#line 337 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 87: + +/* Line 1806 of yacc.c */ +#line 338 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 88: + +/* Line 1806 of yacc.c */ +#line 339 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 89: + +/* Line 1806 of yacc.c */ +#line 340 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 90: + +/* Line 1806 of yacc.c */ +#line 341 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 91: + +/* Line 1806 of yacc.c */ +#line 342 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 92: + +/* Line 1806 of yacc.c */ +#line 343 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 93: + +/* Line 1806 of yacc.c */ +#line 344 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 94: + +/* Line 1806 of yacc.c */ +#line 345 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_NULL);} + break; + + case 95: + +/* Line 1806 of yacc.c */ +#line 348 "ASN1.y" + {(yyval.node)=(yyvsp[(1) - (1)].node);} + break; + + case 96: + +/* Line 1806 of yacc.c */ +#line 349 "ASN1.y" {(yyval.node)=_asn1_mod_type((yyvsp[(2) - (2)].node),CONST_TAG); _asn1_set_right((yyvsp[(1) - (2)].node),_asn1_get_down((yyval.node))); _asn1_set_down((yyval.node),(yyvsp[(1) - (2)].node));} break; - case 73: + case 97: /* Line 1806 of yacc.c */ -#line 295 "ASN1.y" +#line 354 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; - case 74: + case 98: /* Line 1806 of yacc.c */ -#line 296 "ASN1.y" +#line 355 "ASN1.y" {(yyval.node)=_asn1_mod_type((yyvsp[(1) - (2)].node),CONST_DEFAULT); _asn1_set_right((yyvsp[(2) - (2)].node),_asn1_get_down((yyval.node))); _asn1_set_down((yyval.node),(yyvsp[(2) - (2)].node));} break; - case 75: + case 99: /* Line 1806 of yacc.c */ -#line 299 "ASN1.y" +#line 358 "ASN1.y" {(yyval.node)=_asn1_mod_type((yyvsp[(1) - (2)].node),CONST_OPTION);} break; - case 76: + case 100: /* Line 1806 of yacc.c */ -#line 302 "ASN1.y" +#line 361 "ASN1.y" {(yyval.node)=_asn1_set_name((yyvsp[(2) - (2)].node),(yyvsp[(1) - (2)].str));} break; - case 77: + case 101: /* Line 1806 of yacc.c */ -#line 305 "ASN1.y" +#line 364 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; - case 78: + case 102: /* Line 1806 of yacc.c */ -#line 306 "ASN1.y" +#line 365 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (3)].node); _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (3)].node)),(yyvsp[(3) - (3)].node));} break; - case 79: + case 103: /* Line 1806 of yacc.c */ -#line 310 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SEQUENCE); +#line 369 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE); _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} break; - case 80: + case 104: /* Line 1806 of yacc.c */ -#line 312 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SEQUENCE_OF); +#line 371 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF); _asn1_set_down((yyval.node),(yyvsp[(3) - (3)].node));} break; - case 81: + case 105: /* Line 1806 of yacc.c */ -#line 314 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SEQUENCE_OF|CONST_SIZE); +#line 373 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF|CONST_SIZE); _asn1_set_right((yyvsp[(2) - (4)].node),(yyvsp[(4) - (4)].node)); _asn1_set_down((yyval.node),(yyvsp[(2) - (4)].node));} break; - case 82: + case 106: /* Line 1806 of yacc.c */ -#line 319 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SET); +#line 378 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SET); _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} break; - case 83: + case 107: /* Line 1806 of yacc.c */ -#line 321 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SET_OF); +#line 380 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SET_OF); _asn1_set_down((yyval.node),(yyvsp[(3) - (3)].node));} break; - case 84: + case 108: /* Line 1806 of yacc.c */ -#line 323 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_SET_OF|CONST_SIZE); +#line 382 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_SET_OF|CONST_SIZE); _asn1_set_right((yyvsp[(2) - (4)].node),(yyvsp[(4) - (4)].node)); _asn1_set_down((yyval.node),(yyvsp[(2) - (4)].node));} break; - case 85: + case 109: /* Line 1806 of yacc.c */ -#line 328 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_CHOICE); +#line 387 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_CHOICE); _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node));} break; - case 86: + case 110: /* Line 1806 of yacc.c */ -#line 332 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_ANY);} +#line 391 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_ANY);} break; - case 87: + case 111: /* Line 1806 of yacc.c */ -#line 333 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_ANY|CONST_DEFINED_BY); - _asn1_set_down((yyval.node),_asn1_add_static_node(TYPE_CONSTANT)); +#line 392 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_ANY|CONST_DEFINED_BY); + _asn1_set_down((yyval.node),_asn1_add_static_node(ASN1_ETYPE_CONSTANT)); _asn1_set_name(_asn1_get_down((yyval.node)),(yyvsp[(4) - (4)].str));} break; - case 88: + case 112: /* Line 1806 of yacc.c */ -#line 338 "ASN1.y" +#line 397 "ASN1.y" {(yyval.node)=_asn1_set_name((yyvsp[(3) - (3)].node),(yyvsp[(1) - (3)].str));} break; - case 89: + case 113: /* Line 1806 of yacc.c */ -#line 342 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID|CONST_ASSIGN); +#line 398 "ASN1.y" + {(yyval.node)=_asn1_set_name((yyvsp[(2) - (2)].node),"");} + break; + + case 114: + +/* Line 1806 of yacc.c */ +#line 402 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN); _asn1_set_name((yyval.node),(yyvsp[(1) - (7)].str)); _asn1_set_down((yyval.node),(yyvsp[(6) - (7)].node));} break; - case 90: + case 115: /* Line 1806 of yacc.c */ -#line 346 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); +#line 406 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); _asn1_set_name((yyval.node),(yyvsp[(1) - (6)].str)); _asn1_set_value((yyval.node),(yyvsp[(2) - (6)].str),strlen((yyvsp[(2) - (6)].str))+1); _asn1_set_down((yyval.node),(yyvsp[(5) - (6)].node));} break; - case 91: + case 116: /* Line 1806 of yacc.c */ -#line 351 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_INTEGER|CONST_ASSIGN); +#line 411 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_ASSIGN); _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str)); _asn1_set_value((yyval.node),(yyvsp[(4) - (4)].str),strlen((yyvsp[(4) - (4)].str))+1);} break; - case 92: + case 117: /* Line 1806 of yacc.c */ -#line 356 "ASN1.y" +#line 416 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; - case 93: + case 118: /* Line 1806 of yacc.c */ -#line 357 "ASN1.y" +#line 417 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; - case 94: + case 119: /* Line 1806 of yacc.c */ -#line 360 "ASN1.y" +#line 420 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (1)].node);} break; - case 95: + case 120: /* Line 1806 of yacc.c */ -#line 361 "ASN1.y" +#line 421 "ASN1.y" {(yyval.node)=(yyvsp[(1) - (2)].node); _asn1_set_right(_asn1_get_last_right((yyvsp[(1) - (2)].node)),(yyvsp[(2) - (2)].node));} break; - case 96: + case 121: /* Line 1806 of yacc.c */ -#line 365 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID); +#line 425 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_down((yyval.node),(yyvsp[(3) - (4)].node)); _asn1_set_name((yyval.node),(yyvsp[(1) - (4)].str));} break; - case 97: + case 122: /* Line 1806 of yacc.c */ -#line 368 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID); +#line 428 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_name((yyval.node),(yyvsp[(1) - (3)].str));} break; - case 98: + case 123: /* Line 1806 of yacc.c */ -#line 370 "ASN1.y" - {(yyval.node)=_asn1_add_static_node(TYPE_OBJECT_ID); +#line 430 "ASN1.y" + {(yyval.node)=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_name((yyval.node),(yyvsp[(1) - (1)].str));} break; - case 99: + case 124: /* Line 1806 of yacc.c */ -#line 394 "ASN1.y" +#line 454 "ASN1.y" {(yyval.constant)=CONST_EXPLICIT;} break; - case 100: + case 125: /* Line 1806 of yacc.c */ -#line 395 "ASN1.y" +#line 455 "ASN1.y" {(yyval.constant)=CONST_IMPLICIT;} break; /* Line 1806 of yacc.c */ -#line 2412 "ASN1.c" +#line 2645 "ASN1.c" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2639,7 +2872,7 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 399 "ASN1.y" +#line 459 "ASN1.y" @@ -2651,7 +2884,9 @@ static const char *key_word[] = { ,"BOOLEAN","TRUE","FALSE","APPLICATION","ANY","DEFINED" ,"SET","BY","EXPLICIT","IMPLICIT","DEFINITIONS","TAGS" ,"BEGIN","END","UTCTime","GeneralizedTime" - ,"GeneralString","FROM","IMPORTS","NULL","ENUMERATED"}; + ,"GeneralString","FROM","IMPORTS","NULL","ENUMERATED" + ,"NumericString", "IA5String", "TeletexString", "PrintableString" + ,"UniversalString", "BMPString", "UTF8String", "VisibleString"}; static const int key_word_token[] = { ASSIG,OPTIONAL,INTEGER,SIZE,OCTET,STRING ,SEQUENCE,BIT,UNIVERSAL,PRIVATE,OPTIONAL @@ -2659,7 +2894,10 @@ static const int key_word_token[] = { ,BOOLEAN,ASN1_TRUE,ASN1_FALSE,APPLICATION,ANY,DEFINED ,SET,BY,EXPLICIT,IMPLICIT,DEFINITIONS,TAGS ,BEGIN,END,UTCTime,GeneralizedTime - ,GeneralString,FROM,IMPORTS,TOKEN_NULL,ENUMERATED}; + ,GeneralString,FROM,IMPORTS,TOKEN_NULL,ENUMERATED + ,NumericString,IA5String,TeletexString,PrintableString + ,UniversalString,BMPString,UTF8String,VisibleString + }; /*************************************************************/ /* Function: _asn1_yylex */ @@ -2679,8 +2917,8 @@ _asn1_yylex() while((c=fgetc(file_asn1))==' ' || c=='\t' || c=='\n') if(c=='\n') lineNumber++; - if(c==EOF){ - strcpy(lastToken,"End Of File"); + if(c==EOF) { + strcpy(lastToken, "End Of File"); return 0; } @@ -2703,8 +2941,8 @@ _asn1_yylex() while((c=fgetc(file_asn1))!=EOF && c!='\n' && (lastc!='-' || (lastc=='-' && c!='-'))) lastc=c; - if(c==EOF){ - strcpy(lastToken,"End Of File"); + if(c==EOF) { + strcpy(lastToken, "End Of File"); return 0; } else{ @@ -2719,7 +2957,7 @@ _asn1_yylex() c=='(' || c==')' || c=='[' || c==']' || c=='{' || c=='}' || c==',' || c=='.')) { - if(counter>=ASN1_MAX_NAME_SIZE){ + if(counter>=ASN1_MAX_NAME_SIZE) { result_parse=ASN1_NAME_TOO_LONG; return 0; } @@ -2760,41 +2998,24 @@ _asn1_yylex() static void _asn1_create_errorDescription(int error,char *errorDescription) { + if (errorDescription == NULL) + return; + + errorDescription[0]=0; + switch(error){ - case ASN1_SUCCESS: case ASN1_FILE_NOT_FOUND: - if (errorDescription!=NULL) errorDescription[0]=0; - break; case ASN1_SYNTAX_ERROR: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - _asn1_ltostr(lineNumber,errorDescription+strlen(fileName)+1); - strcat(errorDescription,": parse error near '"); - strcat(errorDescription,lastToken); - strcat(errorDescription,"'"); - } + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:%u: parse error near '%s'", fileName, lineNumber, lastToken); break; case ASN1_NAME_TOO_LONG: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - _asn1_ltostr(lineNumber,errorDescription+strlen(fileName)+1); - strcat(errorDescription,": name too long (more than "); - _asn1_ltostr(ASN1_MAX_NAME_SIZE,errorDescription+strlen(errorDescription)); - strcat(errorDescription," characters)"); - } + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:%u: name too long (more than %u characters)", fileName, lineNumber, + ASN1_MAX_NAME_SIZE); break; case ASN1_IDENTIFIER_NOT_FOUND: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - strcat(errorDescription,": identifier '"); - strcat(errorDescription,_asn1_identifierMissing); - strcat(errorDescription,"' not found"); - } - break; - default: - if (errorDescription!=NULL) errorDescription[0]=0; + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:: identifier '%s' not found", fileName, _asn1_identifierMissing); break; } @@ -2840,8 +3061,7 @@ asn1_parser2tree(const char *file_name, asn1_node *definitions, if(file_asn1==NULL){ result_parse=ASN1_FILE_NOT_FOUND; - } - else{ + } else{ result_parse=ASN1_SUCCESS; lineNumber=1; @@ -2855,7 +3075,7 @@ asn1_parser2tree(const char *file_name, asn1_node *definitions, /* set CONST_SET and CONST_NOT_USED */ _asn1_type_set_config(p_tree); /* check the identifier definitions */ - result_parse=_asn1_check_identifier(p_tree); + result_parse = _asn1_check_identifier(p_tree); if(result_parse==ASN1_SUCCESS){ /* all identifier defined */ /* Delete the list and keep the ASN1 structure */ _asn1_delete_list(); @@ -3014,13 +3234,28 @@ static int _asn1_yyerror (const char *s) { /* Sends the error description to the std_out */ -#if 0 - printf("_asn1_yyerror:%s:%ld: %s (Last Token:'%s')\n",fileName, - lineNumber,s,lastToken); -#endif + if (strcmp(lastToken, "VisibleString") == 0 || + strcmp(lastToken, "PrintableString") == 0 || + strcmp(lastToken, "UniversalString") == 0 || + strcmp(lastToken, "IA5String") == 0 || + strcmp(lastToken, "UTF8String") == 0 || + strcmp(lastToken, "NumericString") == 0 || + strcmp(lastToken, "TeletexString") == 0 || + strcmp(lastToken, "BMPString") == 0) + { + fprintf(stderr, "%s:%ld: Warning: %s is already defined in libtasn1\n", + fileName, lineNumber, lastToken); + return 0; /* recover */ + } + if(result_parse!=ASN1_NAME_TOO_LONG) - result_parse=ASN1_SYNTAX_ERROR; + { + fprintf(stderr, "%s:%ld: Error: %s near '%s'\n", fileName, + lineNumber,s,lastToken); + result_parse = ASN1_SYNTAX_ERROR; + return 1; + } return 0; } @@ -32,7 +32,7 @@ #include <structure.h> static FILE *file_asn1; /* Pointer to file to parse */ -static int result_parse; /* result of the parser +static int result_parse = 0; /* result of the parser algorithm */ static asn1_node p_tree; /* pointer to the root of the structure created by the @@ -96,6 +96,15 @@ static int _asn1_yylex(void); %token UTCTime %token GeneralizedTime %token GeneralString +%token NumericString +%token IA5String +%token TeletexString +%token PrintableString +%token UniversalString +%token BMPString +%token UTF8String +%token VisibleString + %token FROM %token IMPORTS %token ENUMERATED @@ -107,6 +116,8 @@ static int _asn1_yylex(void); %type <node> constant_def type_constant type_constant_list definitions %type <node> definitions_id Time bit_element bit_element_list set_def %type <node> tag_type tag type_assig_right_tag generalstring_def +%type <node> numericstring_def ia5string_def printablestring_def universalstring_def +%type <node> bmpstring_def utf8string_def visiblestring_def teletexstring_def %type <node> type_assig_right_tag_default enumerated_def %type <str> pos_num neg_num pos_neg_num pos_neg_identifier pos_neg_list %type <str> num_identifier @@ -118,7 +129,7 @@ static int _asn1_yylex(void); definitions: definitions_id DEFINITIONS explicit_implicit TAGS "::=" BEGIN /* imports_def */ type_constant_list END - {$$=_asn1_add_static_node(TYPE_DEFINITIONS|$3); + {$$=_asn1_add_static_node(ASN1_ETYPE_DEFINITIONS|$3); _asn1_set_name($$,_asn1_get_name($1)); _asn1_set_name($1,""); _asn1_set_right($1,$7); @@ -148,9 +159,9 @@ pos_neg_identifier : pos_neg_num {strcpy($$,$1);} | IDENTIFIER {strcpy($$,$1);} ; -constant: '(' pos_neg_num ')' {$$=_asn1_add_static_node(TYPE_CONSTANT); +constant: '(' pos_neg_num ')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_value($$,$2,strlen($2)+1);} - | IDENTIFIER'('pos_neg_num')' {$$=_asn1_add_static_node(TYPE_CONSTANT); + | IDENTIFIER'('pos_neg_num')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -160,9 +171,9 @@ constant_list: constant {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -obj_constant: num_identifier {$$=_asn1_add_static_node(TYPE_CONSTANT); +obj_constant: num_identifier {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_value($$,$1,strlen($1)+1);} - | IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(TYPE_CONSTANT); + | IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -177,9 +188,9 @@ class : UNIVERSAL {$$=CONST_UNIVERSAL;} | APPLICATION {$$=CONST_APPLICATION;} ; -tag_type : '[' NUM ']' {$$=_asn1_add_static_node(TYPE_TAG); +tag_type : '[' NUM ']' {$$=_asn1_add_static_node(ASN1_ETYPE_TAG); _asn1_set_value($$,$2,strlen($2)+1);} - | '[' class NUM ']' {$$=_asn1_add_static_node(TYPE_TAG | $2); + | '[' class NUM ']' {$$=_asn1_add_static_node(ASN1_ETYPE_TAG | $2); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -188,10 +199,10 @@ tag : tag_type {$$=$1;} | tag_type IMPLICIT {$$=_asn1_mod_type($1,CONST_IMPLICIT);} ; -default : DEFAULT pos_neg_identifier {$$=_asn1_add_static_node(TYPE_DEFAULT); +default : DEFAULT pos_neg_identifier {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT); _asn1_set_value($$,$2,strlen($2)+1);} - | DEFAULT ASN1_TRUE {$$=_asn1_add_static_node(TYPE_DEFAULT|CONST_TRUE);} - | DEFAULT ASN1_FALSE {$$=_asn1_add_static_node(TYPE_DEFAULT|CONST_FALSE);} + | DEFAULT ASN1_TRUE {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_TRUE);} + | DEFAULT ASN1_FALSE {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_FALSE);} ; @@ -200,28 +211,28 @@ pos_neg_list: pos_neg_num ; -integer_def: INTEGER {$$=_asn1_add_static_node(TYPE_INTEGER);} - | INTEGER'{'constant_list'}' {$$=_asn1_add_static_node(TYPE_INTEGER|CONST_LIST); +integer_def: INTEGER {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} + | INTEGER'{'constant_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_LIST); _asn1_set_down($$,$3);} - | integer_def'(' pos_neg_list ')' {$$=_asn1_add_static_node(TYPE_INTEGER);} + | integer_def'(' pos_neg_list ')' {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} | integer_def'('num_identifier'.''.'num_identifier')' - {$$=_asn1_add_static_node(TYPE_INTEGER|CONST_MIN_MAX); - _asn1_set_down($$,_asn1_add_static_node(TYPE_SIZE)); + {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_MIN_MAX); + _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_SIZE)); _asn1_set_value(_asn1_get_down($$),$6,strlen($6)+1); _asn1_set_name(_asn1_get_down($$),$3);} ; -boolean_def: BOOLEAN {$$=_asn1_add_static_node(TYPE_BOOLEAN);} +boolean_def: BOOLEAN {$$=_asn1_add_static_node(ASN1_ETYPE_BOOLEAN);} ; -Time: UTCTime {$$=_asn1_add_static_node(TYPE_TIME|CONST_UTC);} - | GeneralizedTime {$$=_asn1_add_static_node(TYPE_TIME|CONST_GENERALIZED);} +Time: UTCTime {$$=_asn1_add_static_node(ASN1_ETYPE_TIME|CONST_UTC);} + | GeneralizedTime {$$=_asn1_add_static_node(ASN1_ETYPE_TIME|CONST_GENERALIZED);} ; -size_def2: SIZE'('num_identifier')' {$$=_asn1_add_static_node(TYPE_SIZE|CONST_1_PARAM); +size_def2: SIZE'('num_identifier')' {$$=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_1_PARAM); _asn1_set_value($$,$3,strlen($3)+1);} | SIZE'('num_identifier'.''.'num_identifier')' - {$$=_asn1_add_static_node(TYPE_SIZE|CONST_MIN_MAX); + {$$=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_MIN_MAX); _asn1_set_value($$,$3,strlen($3)+1); _asn1_set_name($$,$6);} ; @@ -230,17 +241,57 @@ size_def: size_def2 {$$=$1;} | '(' size_def2 ')' {$$=$2;} ; -generalstring_def: GeneralString {$$=_asn1_add_static_node(TYPE_GENERALSTRING);} - | GeneralString size_def {$$=_asn1_add_static_node(TYPE_GENERALSTRING|CONST_SIZE); +generalstring_def: GeneralString {$$=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING);} + | GeneralString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +numericstring_def: NumericString {$$=_asn1_add_static_node(ASN1_ETYPE_NUMERICSTRING|CONST_UNIVERSAL);} + | NumericString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_NUMERICSTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +ia5string_def: IA5String {$$=_asn1_add_static_node(ASN1_ETYPE_IA5STRING);} + | IA5String size_def {$$=_asn1_add_static_node(ASN1_ETYPE_IA5STRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +teletexstring_def: TeletexString {$$=_asn1_add_static_node(ASN1_ETYPE_TELETEXSTRING);} + | TeletexString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_TELETEXSTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +printablestring_def: PrintableString {$$=_asn1_add_static_node(ASN1_ETYPE_PRINTABLESTRING);} + | PrintableString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_PRINTABLESTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +universalstring_def: UniversalString {$$=_asn1_add_static_node(ASN1_ETYPE_UNIVERSALSTRING);} + | UniversalString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_UNIVERSALSTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +bmpstring_def: BMPString {$$=_asn1_add_static_node(ASN1_ETYPE_BMPSTRING);} + | BMPString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_BMPSTRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +utf8string_def: UTF8String {$$=_asn1_add_static_node(ASN1_ETYPE_UTF8STRING);} + | UTF8String size_def {$$=_asn1_add_static_node(ASN1_ETYPE_UTF8STRING|CONST_SIZE); + _asn1_set_down($$,$2);} +; + +visiblestring_def: VisibleString {$$=_asn1_add_static_node(ASN1_ETYPE_VISIBLESTRING);} + | VisibleString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_VISIBLESTRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -octet_string_def : OCTET STRING {$$=_asn1_add_static_node(TYPE_OCTET_STRING);} - | OCTET STRING size_def {$$=_asn1_add_static_node(TYPE_OCTET_STRING|CONST_SIZE); +octet_string_def : OCTET STRING {$$=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING);} + | OCTET STRING size_def {$$=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING|CONST_SIZE); _asn1_set_down($$,$3);} ; -bit_element : IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(TYPE_CONSTANT); +bit_element : IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -250,25 +301,25 @@ bit_element_list : bit_element {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -bit_string_def : BIT STRING {$$=_asn1_add_static_node(TYPE_BIT_STRING);} - | BIT STRING size_def {$$=_asn1_add_static_node(TYPE_BIT_STRING|CONST_SIZE);} +bit_string_def : BIT STRING {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING);} + | BIT STRING size_def {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_SIZE);} | BIT STRING'{'bit_element_list'}' - {$$=_asn1_add_static_node(TYPE_BIT_STRING|CONST_LIST); + {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_LIST); _asn1_set_down($$,$4);} ; enumerated_def : ENUMERATED'{'bit_element_list'}' - {$$=_asn1_add_static_node(TYPE_ENUMERATED|CONST_LIST); + {$$=_asn1_add_static_node(ASN1_ETYPE_ENUMERATED|CONST_LIST); _asn1_set_down($$,$3);} ; -object_def : OBJECT STR_IDENTIFIER {$$=_asn1_add_static_node(TYPE_OBJECT_ID);} +object_def : OBJECT STR_IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID);} ; -type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(TYPE_IDENTIFIER); +type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER); _asn1_set_value($$,$1,strlen($1)+1);} - | IDENTIFIER size_def {$$=_asn1_add_static_node(TYPE_IDENTIFIER|CONST_SIZE); + | IDENTIFIER size_def {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER|CONST_SIZE); _asn1_set_value($$,$1,strlen($1)+1); _asn1_set_down($$,$2);} | integer_def {$$=$1;} @@ -278,12 +329,20 @@ type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(TYPE_IDENTIFIER) | octet_string_def {$$=$1;} | bit_string_def {$$=$1;} | generalstring_def {$$=$1;} + | numericstring_def {$$=$1;} + | ia5string_def {$$=$1;} + | teletexstring_def {$$=$1;} + | printablestring_def {$$=$1;} + | universalstring_def {$$=$1;} + | bmpstring_def {$$=$1;} + | utf8string_def {$$=$1;} + | visiblestring_def {$$=$1;} | sequence_def {$$=$1;} | object_def {$$=$1;} | choise_def {$$=$1;} | any_def {$$=$1;} | set_def {$$=$1;} - | TOKEN_NULL {$$=_asn1_add_static_node(TYPE_NULL);} + | TOKEN_NULL {$$=_asn1_add_static_node(ASN1_ETYPE_NULL);} ; type_assig_right_tag : type_assig_right {$$=$1;} @@ -307,48 +366,49 @@ type_assig_list : type_assig {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -sequence_def : SEQUENCE'{'type_assig_list'}' {$$=_asn1_add_static_node(TYPE_SEQUENCE); +sequence_def : SEQUENCE'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE); _asn1_set_down($$,$3);} - | SEQUENCE OF type_assig_right {$$=_asn1_add_static_node(TYPE_SEQUENCE_OF); + | SEQUENCE OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF); _asn1_set_down($$,$3);} - | SEQUENCE size_def OF type_assig_right {$$=_asn1_add_static_node(TYPE_SEQUENCE_OF|CONST_SIZE); + | SEQUENCE size_def OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF|CONST_SIZE); _asn1_set_right($2,$4); _asn1_set_down($$,$2);} ; -set_def : SET'{'type_assig_list'}' {$$=_asn1_add_static_node(TYPE_SET); +set_def : SET'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_SET); _asn1_set_down($$,$3);} - | SET OF type_assig_right {$$=_asn1_add_static_node(TYPE_SET_OF); + | SET OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SET_OF); _asn1_set_down($$,$3);} - | SET size_def OF type_assig_right {$$=_asn1_add_static_node(TYPE_SET_OF|CONST_SIZE); + | SET size_def OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SET_OF|CONST_SIZE); _asn1_set_right($2,$4); _asn1_set_down($$,$2);} ; -choise_def : CHOICE'{'type_assig_list'}' {$$=_asn1_add_static_node(TYPE_CHOICE); +choise_def : CHOICE'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_CHOICE); _asn1_set_down($$,$3);} ; -any_def : ANY {$$=_asn1_add_static_node(TYPE_ANY);} - | ANY DEFINED BY IDENTIFIER {$$=_asn1_add_static_node(TYPE_ANY|CONST_DEFINED_BY); - _asn1_set_down($$,_asn1_add_static_node(TYPE_CONSTANT)); +any_def : ANY {$$=_asn1_add_static_node(ASN1_ETYPE_ANY);} + | ANY DEFINED BY IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_ANY|CONST_DEFINED_BY); + _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_CONSTANT)); _asn1_set_name(_asn1_get_down($$),$4);} ; type_def : IDENTIFIER "::=" type_assig_right_tag {$$=_asn1_set_name($3,$1);} + | error type_assig_right_tag {$$=_asn1_set_name($2,"");} ; constant_def : IDENTIFIER OBJECT STR_IDENTIFIER "::=" '{'obj_constant_list'}' - {$$=_asn1_add_static_node(TYPE_OBJECT_ID|CONST_ASSIGN); + {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN); _asn1_set_name($$,$1); _asn1_set_down($$,$6);} | IDENTIFIER IDENTIFIER "::=" '{' obj_constant_list '}' - {$$=_asn1_add_static_node(TYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); + {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); _asn1_set_name($$,$1); _asn1_set_value($$,$2,strlen($2)+1); _asn1_set_down($$,$5);} | IDENTIFIER INTEGER "::=" pos_neg_num - {$$=_asn1_add_static_node(TYPE_INTEGER|CONST_ASSIGN); + {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_ASSIGN); _asn1_set_name($$,$1); _asn1_set_value($$,$4,strlen($4)+1);} ; @@ -362,29 +422,29 @@ type_constant_list : type_constant {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$2);} ; -definitions_id : IDENTIFIER '{' obj_constant_list '}' {$$=_asn1_add_static_node(TYPE_OBJECT_ID); +definitions_id : IDENTIFIER '{' obj_constant_list '}' {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_down($$,$3); _asn1_set_name($$,$1);} - | IDENTIFIER '{' '}' {$$=_asn1_add_static_node(TYPE_OBJECT_ID); + | IDENTIFIER '{' '}' {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_name($$,$1);} - | IDENTIFIER {$$=_asn1_add_static_node(TYPE_OBJECT_ID); + | IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); _asn1_set_name($$,$1);} ; /* -identifier_list : IDENTIFIER {$$=_asn1_add_static_node(TYPE_IDENTIFIER); +identifier_list : IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER); _asn1_set_name($$,$1);} | identifier_list IDENTIFIER {$$=$1; - _asn1_set_right(_asn1_get_last_right($$),_asn1_add_static_node(TYPE_IDENTIFIER)); + _asn1_set_right(_asn1_get_last_right($$),_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER)); _asn1_set_name(_asn1_get_last_right($$),$2);} ; imports_def : empty {$$=NULL;} | IMPORTS identifier_list FROM IDENTIFIER obj_constant_list - {$$=_asn1_add_static_node(TYPE_IMPORTS); - _asn1_set_down($$,_asn1_add_static_node(TYPE_OBJECT_ID)); + {$$=_asn1_add_static_node(ASN1_ETYPE_IMPORTS); + _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID)); _asn1_set_name(_asn1_get_down($$),$4); _asn1_set_down(_asn1_get_down($$),$5); _asn1_set_right($$,$2);} @@ -407,7 +467,9 @@ static const char *key_word[] = { ,"BOOLEAN","TRUE","FALSE","APPLICATION","ANY","DEFINED" ,"SET","BY","EXPLICIT","IMPLICIT","DEFINITIONS","TAGS" ,"BEGIN","END","UTCTime","GeneralizedTime" - ,"GeneralString","FROM","IMPORTS","NULL","ENUMERATED"}; + ,"GeneralString","FROM","IMPORTS","NULL","ENUMERATED" + ,"NumericString", "IA5String", "TeletexString", "PrintableString" + ,"UniversalString", "BMPString", "UTF8String", "VisibleString"}; static const int key_word_token[] = { ASSIG,OPTIONAL,INTEGER,SIZE,OCTET,STRING ,SEQUENCE,BIT,UNIVERSAL,PRIVATE,OPTIONAL @@ -415,7 +477,10 @@ static const int key_word_token[] = { ,BOOLEAN,ASN1_TRUE,ASN1_FALSE,APPLICATION,ANY,DEFINED ,SET,BY,EXPLICIT,IMPLICIT,DEFINITIONS,TAGS ,BEGIN,END,UTCTime,GeneralizedTime - ,GeneralString,FROM,IMPORTS,TOKEN_NULL,ENUMERATED}; + ,GeneralString,FROM,IMPORTS,TOKEN_NULL,ENUMERATED + ,NumericString,IA5String,TeletexString,PrintableString + ,UniversalString,BMPString,UTF8String,VisibleString + }; /*************************************************************/ /* Function: _asn1_yylex */ @@ -435,8 +500,8 @@ _asn1_yylex() while((c=fgetc(file_asn1))==' ' || c=='\t' || c=='\n') if(c=='\n') lineNumber++; - if(c==EOF){ - strcpy(lastToken,"End Of File"); + if(c==EOF) { + strcpy(lastToken, "End Of File"); return 0; } @@ -459,8 +524,8 @@ _asn1_yylex() while((c=fgetc(file_asn1))!=EOF && c!='\n' && (lastc!='-' || (lastc=='-' && c!='-'))) lastc=c; - if(c==EOF){ - strcpy(lastToken,"End Of File"); + if(c==EOF) { + strcpy(lastToken, "End Of File"); return 0; } else{ @@ -475,7 +540,7 @@ _asn1_yylex() c=='(' || c==')' || c=='[' || c==']' || c=='{' || c=='}' || c==',' || c=='.')) { - if(counter>=ASN1_MAX_NAME_SIZE){ + if(counter>=ASN1_MAX_NAME_SIZE) { result_parse=ASN1_NAME_TOO_LONG; return 0; } @@ -516,41 +581,24 @@ _asn1_yylex() static void _asn1_create_errorDescription(int error,char *errorDescription) { + if (errorDescription == NULL) + return; + + errorDescription[0]=0; + switch(error){ - case ASN1_SUCCESS: case ASN1_FILE_NOT_FOUND: - if (errorDescription!=NULL) errorDescription[0]=0; - break; case ASN1_SYNTAX_ERROR: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - _asn1_ltostr(lineNumber,errorDescription+strlen(fileName)+1); - strcat(errorDescription,": parse error near '"); - strcat(errorDescription,lastToken); - strcat(errorDescription,"'"); - } + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:%u: parse error near '%s'", fileName, lineNumber, lastToken); break; case ASN1_NAME_TOO_LONG: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - _asn1_ltostr(lineNumber,errorDescription+strlen(fileName)+1); - strcat(errorDescription,": name too long (more than "); - _asn1_ltostr(ASN1_MAX_NAME_SIZE,errorDescription+strlen(errorDescription)); - strcat(errorDescription," characters)"); - } + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:%u: name too long (more than %u characters)", fileName, lineNumber, + ASN1_MAX_NAME_SIZE); break; case ASN1_IDENTIFIER_NOT_FOUND: - if (errorDescription!=NULL) { - strcpy(errorDescription,fileName); - strcat(errorDescription,":"); - strcat(errorDescription,": identifier '"); - strcat(errorDescription,_asn1_identifierMissing); - strcat(errorDescription,"' not found"); - } - break; - default: - if (errorDescription!=NULL) errorDescription[0]=0; + snprintf(errorDescription, ASN1_MAX_ERROR_DESCRIPTION_SIZE, + "%s:: identifier '%s' not found", fileName, _asn1_identifierMissing); break; } @@ -596,8 +644,7 @@ asn1_parser2tree(const char *file_name, asn1_node *definitions, if(file_asn1==NULL){ result_parse=ASN1_FILE_NOT_FOUND; - } - else{ + } else{ result_parse=ASN1_SUCCESS; lineNumber=1; @@ -611,7 +658,7 @@ asn1_parser2tree(const char *file_name, asn1_node *definitions, /* set CONST_SET and CONST_NOT_USED */ _asn1_type_set_config(p_tree); /* check the identifier definitions */ - result_parse=_asn1_check_identifier(p_tree); + result_parse = _asn1_check_identifier(p_tree); if(result_parse==ASN1_SUCCESS){ /* all identifier defined */ /* Delete the list and keep the ASN1 structure */ _asn1_delete_list(); @@ -770,13 +817,28 @@ static int _asn1_yyerror (const char *s) { /* Sends the error description to the std_out */ -#if 0 - printf("_asn1_yyerror:%s:%ld: %s (Last Token:'%s')\n",fileName, - lineNumber,s,lastToken); -#endif + if (strcmp(lastToken, "VisibleString") == 0 || + strcmp(lastToken, "PrintableString") == 0 || + strcmp(lastToken, "UniversalString") == 0 || + strcmp(lastToken, "IA5String") == 0 || + strcmp(lastToken, "UTF8String") == 0 || + strcmp(lastToken, "NumericString") == 0 || + strcmp(lastToken, "TeletexString") == 0 || + strcmp(lastToken, "BMPString") == 0) + { + fprintf(stderr, "%s:%ld: Warning: %s is already defined in libtasn1\n", + fileName, lineNumber, lastToken); + return 0; /* recover */ + } + if(result_parse!=ASN1_NAME_TOO_LONG) - result_parse=ASN1_SYNTAX_ERROR; + { + fprintf(stderr, "%s:%ld: Error: %s near '%s'\n", fileName, + lineNumber,s,lastToken); + result_parse = ASN1_SYNTAX_ERROR; + return 1; + } return 0; } diff --git a/lib/coding.c b/lib/coding.c index 581ef96..af5c1b7 100644 --- a/lib/coding.c +++ b/lib/coding.c @@ -394,7 +394,7 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der, p = p->right; while (p && p != node->down->left) { - if (type_field (p->type) == TYPE_TAG) + if (type_field (p->type) == ASN1_ETYPE_TAG) { if (p->type & CONST_EXPLICIT) { @@ -429,6 +429,29 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der, return ASN1_SUCCESS; } +tag_and_class_st _asn1_tags[] = +{ + [ASN1_ETYPE_GENERALSTRING] = {ASN1_TAG_GENERALSTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_NUMERICSTRING] = {ASN1_TAG_NUMERICSTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_IA5STRING] = {ASN1_TAG_IA5STRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_TELETEXSTRING] = {ASN1_TAG_TELETEXSTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_PRINTABLESTRING] = {ASN1_TAG_PRINTABLESTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_UNIVERSALSTRING] = {ASN1_TAG_UNIVERSALSTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_BMPSTRING] = {ASN1_TAG_BMPSTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_UTF8STRING] = {ASN1_TAG_UTF8STRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_VISIBLESTRING] = {ASN1_TAG_VISIBLESTRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_OCTET_STRING] = {ASN1_TAG_OCTET_STRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_BIT_STRING] = {ASN1_TAG_BIT_STRING, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_OBJECT_ID] = {ASN1_TAG_OBJECT_ID, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_NULL] = {ASN1_TAG_NULL, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_BOOLEAN] = {ASN1_TAG_BOOLEAN, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_INTEGER] = {ASN1_TAG_INTEGER, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_ENUMERATED] = {ASN1_TAG_ENUMERATED, ASN1_CLASS_UNIVERSAL}, + [ASN1_ETYPE_SEQUENCE] = {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED}, + [ASN1_ETYPE_SEQUENCE_OF] ={ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED}, + [ASN1_ETYPE_SET] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED}, + [ASN1_ETYPE_SET_OF] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED}, +}; /******************************************************/ /* Function : _asn1_insert_tag_der */ @@ -462,7 +485,7 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, p = node->down; while (p) { - if (type_field (p->type) == TYPE_TAG) + if (type_field (p->type) == ASN1_ETYPE_TAG) { if (p->type & CONST_APPLICATION) class = ASN1_CLASS_APPLICATION; @@ -497,10 +520,10 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, { /* CONST_IMPLICIT */ if (!is_tag_implicit) { - if ((type_field (node->type) == TYPE_SEQUENCE) || - (type_field (node->type) == TYPE_SEQUENCE_OF) || - (type_field (node->type) == TYPE_SET) || - (type_field (node->type) == TYPE_SET_OF)) + if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) || + (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) || + (type_field (node->type) == ASN1_ETYPE_SET) || + (type_field (node->type) == ASN1_ETYPE_SET_OF)) class |= ASN1_CLASS_STRUCTURED; class_implicit = class; tag_implicit = _asn1_strtoul (p->value, NULL, 10); @@ -518,29 +541,10 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, } else { - switch (type_field (node->type)) + unsigned type = type_field (node->type); + switch (type) { - case TYPE_NULL: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_NULL, tag_der, - &tag_len); - break; - case TYPE_BOOLEAN: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_BOOLEAN, tag_der, - &tag_len); - break; - case TYPE_INTEGER: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_INTEGER, tag_der, - &tag_len); - break; - case TYPE_ENUMERATED: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_ENUMERATED, tag_der, - &tag_len); - break; - case TYPE_OBJECT_ID: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_OBJECT_ID, tag_der, - &tag_len); - break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (node->type & CONST_UTC) { _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_UTCTime, tag_der, @@ -550,35 +554,32 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_GENERALIZEDTime, tag_der, &tag_len); break; - case TYPE_OCTET_STRING: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_OCTET_STRING, tag_der, - &tag_len); - break; - case TYPE_GENERALSTRING: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_GENERALSTRING, + case ASN1_ETYPE_OBJECT_ID: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: + case ASN1_ETYPE_NULL: + case ASN1_ETYPE_BOOLEAN: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET: + case ASN1_ETYPE_SET_OF: + _asn1_tag_der (_asn1_tags[type].class, _asn1_tags[type].tag, tag_der, &tag_len); break; - case TYPE_BIT_STRING: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_BIT_STRING, tag_der, - &tag_len); - break; - case TYPE_SEQUENCE: - case TYPE_SEQUENCE_OF: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, - ASN1_TAG_SEQUENCE, tag_der, &tag_len); - break; - case TYPE_SET: - case TYPE_SET_OF: - _asn1_tag_der (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, - ASN1_TAG_SET, tag_der, &tag_len); - break; - case TYPE_TAG: - tag_len = 0; - break; - case TYPE_CHOICE: - tag_len = 0; - break; - case TYPE_ANY: + case ASN1_ETYPE_TAG: + case ASN1_ETYPE_CHOICE: + case ASN1_ETYPE_ANY: tag_len = 0; break; default: @@ -624,12 +625,12 @@ _asn1_ordering_set (unsigned char *der, int der_len, asn1_node node) counter = 0; - if (type_field (node->type) != TYPE_SET) + if (type_field (node->type) != ASN1_ETYPE_SET) return; p = node->down; - while ((type_field (p->type) == TYPE_TAG) - || (type_field (p->type) == TYPE_SIZE)) + while ((type_field (p->type) == ASN1_ETYPE_TAG) + || (type_field (p->type) == ASN1_ETYPE_SIZE)) p = p->right; if ((p == NULL) || (p->right == NULL)) @@ -737,12 +738,12 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node) counter = 0; - if (type_field (node->type) != TYPE_SET_OF) + if (type_field (node->type) != ASN1_ETYPE_SET_OF) return; p = node->down; - while ((type_field (p->type) == TYPE_TAG) - || (type_field (p->type) == TYPE_SIZE)) + while ((type_field (p->type) == ASN1_ETYPE_TAG) + || (type_field (p->type) == ASN1_ETYPE_SIZE)) p = p->right; p = p->right; @@ -906,14 +907,14 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, } switch (type_field (p->type)) { - case TYPE_NULL: + case ASN1_ETYPE_NULL: max_len--; if (max_len >= 0) der[counter] = 0; counter++; move = RIGHT; break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if ((p->type & CONST_DEFAULT) && (p->value == NULL)) { counter = counter_old; @@ -942,8 +943,8 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, } move = RIGHT; break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: if ((p->type & CONST_DEFAULT) && (p->value == NULL)) { counter = counter_old; @@ -971,7 +972,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, } move = RIGHT; break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: if ((p->type & CONST_DEFAULT) && (p->value == NULL)) { counter = counter_old; @@ -996,7 +997,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, } move = RIGHT; break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (p->value == NULL) { _asn1_error_description_value_not_found (p, ErrorDescription); @@ -1012,45 +1013,17 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, counter += len2; move = RIGHT; break; - case TYPE_OCTET_STRING: - if (p->value == NULL) - { - _asn1_error_description_value_not_found (p, ErrorDescription); - err = ASN1_VALUE_NOT_FOUND; - goto error; - } - len2 = asn1_get_length_der (p->value, p->value_len, &len3); - if (len2 < 0) - { - err = ASN1_DER_ERROR; - goto error; - } - max_len -= len2 + len3; - if (max_len >= 0) - memcpy (der + counter, p->value, len3 + len2); - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_GENERALSTRING: - if (p->value == NULL) - { - _asn1_error_description_value_not_found (p, ErrorDescription); - err = ASN1_VALUE_NOT_FOUND; - goto error; - } - len2 = asn1_get_length_der (p->value, p->value_len, &len3); - if (len2 < 0) - { - err = ASN1_DER_ERROR; - goto error; - } - max_len -= len2 + len3; - if (max_len >= 0) - memcpy (der + counter, p->value, len3 + len2); - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: if (p->value == NULL) { _asn1_error_description_value_not_found (p, ErrorDescription); @@ -1069,8 +1042,8 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, counter += len3 + len2; move = RIGHT; break; - case TYPE_SEQUENCE: - case TYPE_SET: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SET: if (move != UP) { _asn1_ltostr (counter, (char *) temp); @@ -1085,7 +1058,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, else { p2 = p->down; - while (p2 && (type_field (p2->type) == TYPE_TAG)) + while (p2 && (type_field (p2->type) == ASN1_ETYPE_TAG)) p2 = p2->right; if (p2) { @@ -1101,7 +1074,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, { /* move==UP */ len2 = _asn1_strtol (p->value, NULL, 10); _asn1_set_value (p, NULL, 0); - if ((type_field (p->type) == TYPE_SET) && (max_len >= 0)) + if ((type_field (p->type) == ASN1_ETYPE_SET) && (max_len >= 0)) _asn1_ordering_set (der + len2, max_len - len2, p); asn1_length_der (counter - len2, temp, &len3); max_len -= len3; @@ -1114,8 +1087,8 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, move = RIGHT; } break; - case TYPE_SEQUENCE_OF: - case TYPE_SET_OF: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET_OF: if (move != UP) { _asn1_ltostr (counter, (char *) temp); @@ -1124,8 +1097,8 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, 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)) + while ((type_field (p->type) == ASN1_ETYPE_TAG) + || (type_field (p->type) == ASN1_ETYPE_SIZE)) p = p->right; if (p->right) { @@ -1141,7 +1114,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, { len2 = _asn1_strtol (p->value, NULL, 10); _asn1_set_value (p, NULL, 0); - if ((type_field (p->type) == TYPE_SET_OF) + if ((type_field (p->type) == ASN1_ETYPE_SET_OF) && (max_len - len2 > 0)) { _asn1_ordering_set_of (der + len2, max_len - len2, p); @@ -1157,7 +1130,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, move = RIGHT; } break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: if (p->value == NULL) { _asn1_error_description_value_not_found (p, ErrorDescription); diff --git a/lib/decoding.c b/lib/decoding.c index 79766a1..5a844b8 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -387,7 +387,7 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, p = node->down; while (p) { - if (type_field (p->type) == TYPE_TAG) + if (type_field (p->type) == ASN1_ETYPE_TAG) { if (p->type & CONST_APPLICATION) class2 = ASN1_CLASS_APPLICATION; @@ -436,10 +436,10 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, { /* ASN1_TAG_IMPLICIT */ if (!is_tag_implicit) { - if ((type_field (node->type) == TYPE_SEQUENCE) || - (type_field (node->type) == TYPE_SEQUENCE_OF) || - (type_field (node->type) == TYPE_SET) || - (type_field (node->type) == TYPE_SET_OF)) + if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE) || + (type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) || + (type_field (node->type) == ASN1_ETYPE_SET) || + (type_field (node->type) == ASN1_ETYPE_SET_OF)) class2 |= ASN1_CLASS_STRUCTURED; class_implicit = class2; tag_implicit = strtoul ((char *) p->value, NULL, 10); @@ -462,7 +462,7 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, if ((class != class_implicit) || (tag != tag_implicit)) { - if (type_field (node->type) == TYPE_OCTET_STRING) + if (type_field (node->type) == ASN1_ETYPE_OCTET_STRING) { class_implicit |= ASN1_CLASS_STRUCTURED; if ((class != class_implicit) || (tag != tag_implicit)) @@ -474,7 +474,8 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, } else { - if (type_field (node->type) == TYPE_TAG) + unsigned type = type_field (node->type); + if (type == ASN1_ETYPE_TAG) { counter = 0; *ret_len = counter; @@ -489,29 +490,32 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, if (counter + len2 > der_len) return ASN1_DER_ERROR; - switch (type_field (node->type)) + switch (type) { - case TYPE_NULL: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_NULL)) + case ASN1_ETYPE_NULL: + case ASN1_ETYPE_BOOLEAN: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: + case ASN1_ETYPE_OBJECT_ID: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET: + case ASN1_ETYPE_SET_OF: + if ((class != _asn1_tags[type].class) || (tag != _asn1_tags[type].tag)) return ASN1_DER_ERROR; break; - case TYPE_BOOLEAN: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_BOOLEAN)) - return ASN1_DER_ERROR; - break; - case TYPE_INTEGER: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_INTEGER)) - return ASN1_DER_ERROR; - break; - case TYPE_ENUMERATED: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_ENUMERATED)) - return ASN1_DER_ERROR; - break; - case TYPE_OBJECT_ID: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_OBJECT_ID)) - return ASN1_DER_ERROR; - break; - case TYPE_TIME: + + case ASN1_ETYPE_TIME: if (node->type & CONST_UTC) { if ((class != ASN1_CLASS_UNIVERSAL) @@ -525,34 +529,15 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, return ASN1_DER_ERROR; } break; - case TYPE_OCTET_STRING: + + case ASN1_ETYPE_OCTET_STRING: + /* does it need to be structured??? --nmav */ if (((class != ASN1_CLASS_UNIVERSAL) && (class != (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED))) || (tag != ASN1_TAG_OCTET_STRING)) return ASN1_DER_ERROR; break; - case TYPE_GENERALSTRING: - if ((class != ASN1_CLASS_UNIVERSAL) - || (tag != ASN1_TAG_GENERALSTRING)) - return ASN1_DER_ERROR; - break; - case TYPE_BIT_STRING: - if ((class != ASN1_CLASS_UNIVERSAL) || (tag != ASN1_TAG_BIT_STRING)) - return ASN1_DER_ERROR; - break; - case TYPE_SEQUENCE: - case TYPE_SEQUENCE_OF: - if ((class != (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED)) - || (tag != ASN1_TAG_SEQUENCE)) - return ASN1_DER_ERROR; - break; - case TYPE_SET: - case TYPE_SET_OF: - if ((class != (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED)) - || (tag != ASN1_TAG_SET)) - return ASN1_DER_ERROR; - break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: counter -= len2; break; default: @@ -883,7 +868,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, { if ((p2->type & CONST_SET) && (p2->type & CONST_NOT_USED)) { - if (type_field (p2->type) != TYPE_CHOICE) + if (type_field (p2->type) != ASN1_ETYPE_CHOICE) ris = _asn1_extract_tag_der (p2, der + counter, len - counter, &len2); @@ -938,7 +923,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, } } - if (type_field (p->type) == TYPE_CHOICE) + if (type_field (p->type) == ASN1_ETYPE_CHOICE) { while (p->down) { @@ -1021,7 +1006,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, { switch (type_field (p->type)) { - case TYPE_NULL: + case ASN1_ETYPE_NULL: if (der[counter]) { result = ASN1_DER_ERROR; @@ -1030,7 +1015,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter++; move = RIGHT; break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if (der[counter++] != 1) { result = ASN1_DER_ERROR; @@ -1042,8 +1027,8 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, _asn1_set_value (p, "T", 1); move = RIGHT; break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: len2 = asn1_get_length_der (der + counter, len - counter, &len3); if (len2 < 0) @@ -1056,7 +1041,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter += len3 + len2; move = RIGHT; break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: result = _asn1_get_objectid_der (der + counter, len - counter, &len2, temp, sizeof (temp)); @@ -1069,7 +1054,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter += len2; move = RIGHT; break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: result = _asn1_get_time_der (der + counter, len - counter, &len2, temp, sizeof (temp) - 1); @@ -1082,7 +1067,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter += len2; move = RIGHT; break; - case TYPE_OCTET_STRING: + case ASN1_ETYPE_OCTET_STRING: len3 = len - counter; result = _asn1_get_octet_string (der + counter, p, &len3); if (result != ASN1_SUCCESS) @@ -1091,7 +1076,16 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter += len3; move = RIGHT; break; - case TYPE_GENERALSTRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: len2 = asn1_get_length_der (der + counter, len - counter, &len3); if (len2 < 0) @@ -1104,21 +1098,8 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, counter += len3 + len2; move = RIGHT; break; - case TYPE_BIT_STRING: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - { - result = ASN1_DER_ERROR; - goto cleanup; - } - - _asn1_set_value (p, der + counter, len3 + len2); - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_SEQUENCE: - case TYPE_SET: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SET: if (move == UP) { len2 = _asn1_strtol (p->value, NULL, 10); @@ -1173,7 +1154,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, p2 = p->down; while (p2) { - if (type_field (p2->type) != TYPE_TAG) + if (type_field (p2->type) != ASN1_ETYPE_TAG) { p3 = p2->right; asn1_delete_structure (&p2); @@ -1191,8 +1172,8 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, } } break; - case TYPE_SEQUENCE_OF: - case TYPE_SET_OF: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET_OF: if (move == UP) { len2 = _asn1_strtol (p->value, NULL, 10); @@ -1260,8 +1241,8 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, _asn1_set_value (p, "-1", 3); } p2 = p->down; - while ((type_field (p2->type) == TYPE_TAG) - || (type_field (p2->type) == TYPE_SIZE)) + while ((type_field (p2->type) == ASN1_ETYPE_TAG) + || (type_field (p2->type) == ASN1_ETYPE_SIZE)) p2 = p2->right; if (p2->right == NULL) _asn1_append_sequence_set (p); @@ -1270,7 +1251,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int len, } move = RIGHT; break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: if (asn1_get_tag_der (der + counter, len - counter, &class, &len2, &tag) != ASN1_SUCCESS) @@ -1494,7 +1475,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, { if ((p2->type & CONST_SET) && (p2->type & CONST_NOT_USED)) { - if (type_field (p2->type) != TYPE_CHOICE) + if (type_field (p2->type) != ASN1_ETYPE_CHOICE) ris = _asn1_extract_tag_der (p2, der + counter, len - counter, &len2); @@ -1549,7 +1530,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, } } - if (type_field (p->type) == TYPE_CHOICE) + if (type_field (p->type) == ASN1_ETYPE_CHOICE) { while (p->down) { @@ -1632,7 +1613,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, { switch (type_field (p->type)) { - case TYPE_NULL: + case ASN1_ETYPE_NULL: if (der[counter]) { result = ASN1_DER_ERROR; @@ -1645,7 +1626,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter++; move = RIGHT; break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if (der[counter++] != 1) { result = ASN1_DER_ERROR; @@ -1668,8 +1649,8 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, move = RIGHT; break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: len2 = asn1_get_length_der (der + counter, len - counter, &len3); if (len2 < 0) @@ -1693,7 +1674,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len3 + len2; move = RIGHT; break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: if (state == FOUND) { result = @@ -1725,7 +1706,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len2; move = RIGHT; break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (state == FOUND) { result = @@ -1756,7 +1737,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len2; move = RIGHT; break; - case TYPE_OCTET_STRING: + case ASN1_ETYPE_OCTET_STRING: len3 = len - counter; if (state == FOUND) { @@ -1773,7 +1754,16 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len3; move = RIGHT; break; - case TYPE_GENERALSTRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: len2 = asn1_get_length_der (der + counter, len - counter, &len3); if (len2 < 0) @@ -1797,31 +1787,8 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len3 + len2; move = RIGHT; break; - case TYPE_BIT_STRING: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - { - result = ASN1_DER_ERROR; - goto cleanup; - } - if (state == FOUND) - { - if (len3 + len2 > len - counter) - { - result = ASN1_DER_ERROR; - goto cleanup; - } - _asn1_set_value (p, der + counter, len3 + len2); - - if (p == nodeFound) - state = EXIT; - } - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_SEQUENCE: - case TYPE_SET: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SET: if (move == UP) { len2 = _asn1_strtol (p->value, NULL, 10); @@ -1887,7 +1854,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, p2 = p->down; while (p2) { - if (type_field (p2->type) != TYPE_TAG) + if (type_field (p2->type) != ASN1_ETYPE_TAG) { p3 = p2->right; asn1_delete_structure (&p2); @@ -1906,8 +1873,8 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, } } break; - case TYPE_SEQUENCE_OF: - case TYPE_SET_OF: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET_OF: if (move == UP) { len2 = _asn1_strtol (p->value, NULL, 10); @@ -1964,8 +1931,8 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, 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)) + while ((type_field (p2->type) == ASN1_ETYPE_TAG) + || (type_field (p2->type) == ASN1_ETYPE_SIZE)) p2 = p2->right; if (p2->right == NULL) _asn1_append_sequence_set (p); @@ -1976,7 +1943,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, } break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: if (asn1_get_tag_der (der + counter, len - counter, &class, &len2, &tag) != ASN1_SUCCESS) @@ -2289,7 +2256,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, { if ((p2->type & CONST_SET) && (p2->type & CONST_NOT_USED)) { /* CONTROLLARE */ - if (type_field (p2->type) != TYPE_CHOICE) + if (type_field (p2->type) != ASN1_ETYPE_CHOICE) ris = _asn1_extract_tag_der (p2, der + counter, len - counter, &len2); @@ -2319,7 +2286,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, if (p == node_to_find) *start = counter; - if (type_field (p->type) == TYPE_CHOICE) + if (type_field (p->type) == ASN1_ETYPE_CHOICE) { p = p->down; if (p == NULL) @@ -2359,44 +2326,19 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, { switch (type_field (p->type)) { - case TYPE_NULL: + case ASN1_ETYPE_NULL: if (der[counter]) return ASN1_DER_ERROR; counter++; move = RIGHT; break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if (der[counter++] != 1) return ASN1_DER_ERROR; counter++; move = RIGHT; break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - return ASN1_DER_ERROR; - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_OBJECT_ID: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - return ASN1_DER_ERROR; - counter += len2 + len3; - move = RIGHT; - break; - case TYPE_TIME: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - return ASN1_DER_ERROR; - counter += len2 + len3; - move = RIGHT; - break; - case TYPE_OCTET_STRING: + case ASN1_ETYPE_OCTET_STRING: len3 = len - counter; ris = _asn1_get_octet_string (der + counter, NULL, &len3); if (ris != ASN1_SUCCESS) @@ -2404,15 +2346,20 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, counter += len3; move = RIGHT; break; - case TYPE_GENERALSTRING: - len2 = - asn1_get_length_der (der + counter, len - counter, &len3); - if (len2 < 0) - return ASN1_DER_ERROR; - counter += len3 + len2; - move = RIGHT; - break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_TIME: + case ASN1_ETYPE_OBJECT_ID: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: len2 = asn1_get_length_der (der + counter, len - counter, &len3); if (len2 < 0) @@ -2420,8 +2367,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, counter += len3 + len2; move = RIGHT; break; - case TYPE_SEQUENCE: - case TYPE_SET: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SET: if (move != UP) { len3 = @@ -2441,8 +2388,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, move = RIGHT; } break; - case TYPE_SEQUENCE_OF: - case TYPE_SET_OF: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET_OF: if (move != UP) { len3 = @@ -2455,8 +2402,8 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, else if (len3) { p2 = p->down; - while ((type_field (p2->type) == TYPE_TAG) || - (type_field (p2->type) == TYPE_SIZE)) + while ((type_field (p2->type) == ASN1_ETYPE_TAG) || + (type_field (p2->type) == ASN1_ETYPE_SIZE)) p2 = p2->right; p = p2; } @@ -2468,7 +2415,7 @@ asn1_der_decoding_startEnd (asn1_node element, const void *ider, int len, } move = RIGHT; break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: if (asn1_get_tag_der (der + counter, len - counter, &class, &len2, &tag) != ASN1_SUCCESS) @@ -2587,12 +2534,12 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element) switch (type_field (p->type)) { - case TYPE_ANY: + case ASN1_ETYPE_ANY: if ((p->type & CONST_DEFINED_BY) && (p->value)) { /* search the "DEF_BY" element */ p2 = p->down; - while ((p2) && (type_field (p2->type) != TYPE_CONSTANT)) + while ((p2) && (type_field (p2->type) != ASN1_ETYPE_CONSTANT)) p2 = p2->right; if (!p2) @@ -2617,7 +2564,7 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element) p3 = p3->right; } - if ((!p3) || (type_field (p3->type) != TYPE_OBJECT_ID) || + if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || (p3->value == NULL)) { @@ -2639,7 +2586,7 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element) p3 = p3->right; } - if ((!p3) || (type_field (p3->type) != TYPE_OBJECT_ID) || + if ((!p3) || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || (p3->value == NULL)) { retCode = ASN1_ERROR_TYPE_ANY; @@ -2651,7 +2598,7 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element) p2 = definitions->down; while (p2) { - if ((type_field (p2->type) == TYPE_OBJECT_ID) && + if ((type_field (p2->type) == ASN1_ETYPE_OBJECT_ID) && (p2->type & CONST_ASSIGN)) { strcpy (name, definitionsName); @@ -2812,7 +2759,7 @@ asn1_expand_octet_string (asn1_node definitions, asn1_node * element, octetNode = asn1_find_node (*element, octetName); if (octetNode == NULL) return ASN1_ELEMENT_NOT_FOUND; - if (type_field (octetNode->type) != TYPE_OCTET_STRING) + if (type_field (octetNode->type) != ASN1_ETYPE_OCTET_STRING) return ASN1_ELEMENT_NOT_FOUND; if (octetNode->value == NULL) return ASN1_VALUE_NOT_FOUND; @@ -2821,7 +2768,7 @@ asn1_expand_octet_string (asn1_node definitions, asn1_node * element, if (objectNode == NULL) return ASN1_ELEMENT_NOT_FOUND; - if (type_field (objectNode->type) != TYPE_OBJECT_ID) + if (type_field (objectNode->type) != ASN1_ETYPE_OBJECT_ID) return ASN1_ELEMENT_NOT_FOUND; if (objectNode->value == NULL) @@ -2832,7 +2779,7 @@ asn1_expand_octet_string (asn1_node definitions, asn1_node * element, p2 = definitions->down; while (p2) { - if ((type_field (p2->type) == TYPE_OBJECT_ID) && + if ((type_field (p2->type) == ASN1_ETYPE_OBJECT_ID) && (p2->type & CONST_ASSIGN)) { strcpy (name, definitions->name); diff --git a/lib/element.c b/lib/element.c index 4c871a1..2c6a2fd 100644 --- a/lib/element.c +++ b/lib/element.c @@ -137,8 +137,8 @@ _asn1_append_sequence_set (asn1_node node) return ASN1_GENERIC_ERROR; p = node->down; - while ((type_field (p->type) == TYPE_TAG) - || (type_field (p->type) == TYPE_SIZE)) + while ((type_field (p->type) == ASN1_ETYPE_TAG) + || (type_field (p->type) == ASN1_ETYPE_SIZE)) p = p->right; p2 = _asn1_copy_structure3 (p); while (p->right) @@ -287,12 +287,12 @@ asn1_write_value (asn1_node node_root, const char *name, return ASN1_SUCCESS; } - if ((type_field (node->type) == TYPE_SEQUENCE_OF) && (value == NULL) + if ((type_field (node->type) == ASN1_ETYPE_SEQUENCE_OF) && (value == NULL) && (len == 0)) { p = node->down; - while ((type_field (p->type) == TYPE_TAG) - || (type_field (p->type) == TYPE_SIZE)) + while ((type_field (p->type) == ASN1_ETYPE_TAG) + || (type_field (p->type) == ASN1_ETYPE_SIZE)) p = p->right; while (p->right) @@ -303,13 +303,13 @@ asn1_write_value (asn1_node node_root, const char *name, switch (type_field (node->type)) { - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if (!_asn1_strcmp (value, "TRUE")) { if (node->type & CONST_DEFAULT) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if (p->type & CONST_TRUE) _asn1_set_value (node, NULL, 0); @@ -324,7 +324,7 @@ asn1_write_value (asn1_node node_root, const char *name, if (node->type & CONST_DEFAULT) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if (p->type & CONST_FALSE) _asn1_set_value (node, NULL, 0); @@ -337,8 +337,8 @@ asn1_write_value (asn1_node node_root, const char *name, else return ASN1_VALUE_NOT_VALID; break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: if (len == 0) { if ((isdigit (value[0])) || (value[0] == '-')) @@ -357,7 +357,7 @@ asn1_write_value (asn1_node node_root, const char *name, p = node->down; while (p) { - if (type_field (p->type) == TYPE_CONSTANT) + if (type_field (p->type) == ASN1_ETYPE_CONSTANT) { if (!_asn1_strcmp (p->name, value)) { @@ -392,7 +392,7 @@ asn1_write_value (asn1_node node_root, const char *name, else negative = 0; - if (negative && (type_field (node->type) == TYPE_ENUMERATED)) + if (negative && (type_field (node->type) == ASN1_ETYPE_ENUMERATED)) { free (value_temp); return ASN1_VALUE_NOT_VALID; @@ -413,7 +413,7 @@ asn1_write_value (asn1_node node_root, const char *name, if (node->type & CONST_DEFAULT) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if ((isdigit (p->value[0])) || (p->value[0] == '-')) { @@ -437,7 +437,7 @@ asn1_write_value (asn1_node node_root, const char *name, p2 = node->down; while (p2) { - if (type_field (p2->type) == TYPE_CONSTANT) + if (type_field (p2->type) == ASN1_ETYPE_CONSTANT) { if (!_asn1_strcmp (p2->name, p->value)) { @@ -479,14 +479,14 @@ asn1_write_value (asn1_node node_root, const char *name, } free (value_temp); break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: for (i = 0; i < _asn1_strlen (value); i++) if ((!isdigit (value[i])) && (value[i] != '.') && (value[i] != '+')) return ASN1_VALUE_NOT_VALID; if (node->type & CONST_DEFAULT) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if (!_asn1_strcmp (value, p->value)) { @@ -496,7 +496,7 @@ asn1_write_value (asn1_node node_root, const char *name, } _asn1_set_value (node, value, _asn1_strlen (value) + 1); break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (node->type & CONST_UTC) { if (_asn1_strlen (value) < 11) @@ -542,17 +542,21 @@ asn1_write_value (asn1_node node_root, const char *name, _asn1_set_value (node, value, _asn1_strlen (value) + 1); } break; - case TYPE_OCTET_STRING: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: if (len == 0) len = _asn1_strlen (value); _asn1_set_value_octet (node, value, len); break; - case TYPE_GENERALSTRING: - if (len == 0) - len = _asn1_strlen (value); - _asn1_set_value_octet (node, value, len); - break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_BIT_STRING: if (len == 0) len = _asn1_strlen (value); asn1_length_der ((len >> 3) + 2, NULL, &len2); @@ -564,7 +568,7 @@ asn1_write_value (asn1_node node_root, const char *name, _asn1_set_value_m (node, temp, len2); temp = NULL; break; - case TYPE_CHOICE: + case ASN1_ETYPE_CHOICE: p = node->down; while (p) { @@ -588,11 +592,11 @@ asn1_write_value (asn1_node node_root, const char *name, if (!p) return ASN1_ELEMENT_NOT_FOUND; break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: _asn1_set_value_octet (node, value, len); break; - case TYPE_SEQUENCE_OF: - case TYPE_SET_OF: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET_OF: if (_asn1_strcmp (value, "NEW")) return ASN1_VALUE_NOT_VALID; _asn1_append_sequence_set (node); @@ -705,22 +709,22 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) if (node == NULL) return ASN1_ELEMENT_NOT_FOUND; - if ((type_field (node->type) != TYPE_NULL) && - (type_field (node->type) != TYPE_CHOICE) && + if ((type_field (node->type) != ASN1_ETYPE_NULL) && + (type_field (node->type) != ASN1_ETYPE_CHOICE) && !(node->type & CONST_DEFAULT) && !(node->type & CONST_ASSIGN) && (node->value == NULL)) return ASN1_VALUE_NOT_FOUND; switch (type_field (node->type)) { - case TYPE_NULL: + case ASN1_ETYPE_NULL: PUT_STR_VALUE (value, value_size, "NULL"); break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if ((node->type & CONST_DEFAULT) && (node->value == NULL)) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if (p->type & CONST_TRUE) { @@ -740,12 +744,12 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) PUT_STR_VALUE (value, value_size, "FALSE"); } break; - case TYPE_INTEGER: - case TYPE_ENUMERATED: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: if ((node->type & CONST_DEFAULT) && (node->value == NULL)) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; if ((isdigit (p->value[0])) || (p->value[0] == '-') || (p->value[0] == '+')) @@ -759,7 +763,7 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) p2 = node->down; while (p2) { - if (type_field (p2->type) == TYPE_CONSTANT) + if (type_field (p2->type) == ASN1_ETYPE_CONSTANT) { if (!_asn1_strcmp (p2->name, p->value)) { @@ -783,14 +787,14 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) return ASN1_MEM_ERROR; } break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: if (node->type & CONST_ASSIGN) { value[0] = 0; p = node->down; while (p) { - if (type_field (p->type) == TYPE_CONSTANT) + if (type_field (p->type) == ASN1_ETYPE_CONSTANT) { ADD_STR_VALUE (value, value_size, p->value); if (p->right) @@ -805,7 +809,7 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) else if ((node->type & CONST_DEFAULT) && (node->value == NULL)) { p = node->down; - while (type_field (p->type) != TYPE_DEFAULT) + while (type_field (p->type) != ASN1_ETYPE_DEFAULT) p = p->right; PUT_STR_VALUE (value, value_size, p->value); } @@ -814,34 +818,36 @@ asn1_read_value (asn1_node root, const char *name, void *ivalue, int *len) PUT_STR_VALUE (value, value_size, node->value); } break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: PUT_STR_VALUE (value, value_size, node->value); break; - case TYPE_OCTET_STRING: - len2 = -1; - if (asn1_get_octet_der - (node->value, node->value_len, &len2, value, value_size, - len) != ASN1_SUCCESS) - return ASN1_MEM_ERROR; - break; - case TYPE_GENERALSTRING: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: len2 = -1; if (asn1_get_octet_der (node->value, node->value_len, &len2, value, value_size, len) != ASN1_SUCCESS) return ASN1_MEM_ERROR; break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_BIT_STRING: len2 = -1; if (asn1_get_bit_der (node->value, node->value_len, &len2, value, value_size, len) != ASN1_SUCCESS) return ASN1_MEM_ERROR; break; - case TYPE_CHOICE: + case ASN1_ETYPE_CHOICE: PUT_STR_VALUE (value, value_size, node->down->name); break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: len3 = -1; len2 = asn1_get_length_der (node->value, node->value_len, &len3); if (len2 < 0) @@ -889,7 +895,7 @@ asn1_read_tag (asn1_node root, const char *name, int *tagValue, { while (p) { - if (type_field (p->type) == TYPE_TAG) + if (type_field (p->type) == ASN1_ETYPE_TAG) { if ((p->type & CONST_IMPLICIT) && (pTag == NULL)) pTag = p; @@ -915,26 +921,34 @@ asn1_read_tag (asn1_node root, const char *name, int *tagValue, } else { + unsigned type = type_field (node->type); *classValue = ASN1_CLASS_UNIVERSAL; - switch (type_field (node->type)) + switch (type) { - case TYPE_NULL: - *tagValue = ASN1_TAG_NULL; + case ASN1_ETYPE_NULL: + case ASN1_ETYPE_BOOLEAN: + case ASN1_ETYPE_INTEGER: + case ASN1_ETYPE_ENUMERATED: + case ASN1_ETYPE_OBJECT_ID: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: + case ASN1_ETYPE_BIT_STRING: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SET: + case ASN1_ETYPE_SET_OF: + *tagValue = _asn1_tags[type].tag; break; - case TYPE_BOOLEAN: - *tagValue = ASN1_TAG_BOOLEAN; - break; - case TYPE_INTEGER: - *tagValue = ASN1_TAG_INTEGER; - break; - case TYPE_ENUMERATED: - *tagValue = ASN1_TAG_ENUMERATED; - break; - case TYPE_OBJECT_ID: - *tagValue = ASN1_TAG_OBJECT_ID; - break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (node->type & CONST_UTC) { *tagValue = ASN1_TAG_UTCTime; @@ -942,26 +956,10 @@ asn1_read_tag (asn1_node root, const char *name, int *tagValue, else *tagValue = ASN1_TAG_GENERALIZEDTime; break; - case TYPE_OCTET_STRING: - *tagValue = ASN1_TAG_OCTET_STRING; - break; - case TYPE_GENERALSTRING: - *tagValue = ASN1_TAG_GENERALSTRING; - break; - case TYPE_BIT_STRING: - *tagValue = ASN1_TAG_BIT_STRING; - break; - case TYPE_SEQUENCE: - case TYPE_SEQUENCE_OF: - *tagValue = ASN1_TAG_SEQUENCE; - break; - case TYPE_SET: - case TYPE_SET_OF: - *tagValue = ASN1_TAG_SET; - break; - case TYPE_TAG: - case TYPE_CHOICE: - case TYPE_ANY: + case ASN1_ETYPE_TAG: + case ASN1_ETYPE_CHOICE: + case ASN1_ETYPE_ANY: + *tagValue = -1; break; default: break; @@ -58,6 +58,13 @@ struct asn1_node_st unsigned char small_value[ASN1_SMALL_VALUE_SIZE]; /* For small values */ }; +typedef struct tag_and_class_st { + unsigned tag; + unsigned class; +} tag_and_class_st; + +extern tag_and_class_st _asn1_tags[]; + #define _asn1_strlen(s) strlen((const char *) s) #define _asn1_strtol(n,e,b) strtol((const char *) n, e, b) #define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) @@ -78,31 +85,6 @@ struct asn1_node_st /****************************************/ #define type_field(x) (x&0xFF) -/* List of constants for field type of typedef asn1_node_st */ -#define TYPE_CONSTANT ASN1_ETYPE_CONSTANT -#define TYPE_IDENTIFIER ASN1_ETYPE_IDENTIFIER -#define TYPE_INTEGER ASN1_ETYPE_INTEGER -#define TYPE_BOOLEAN ASN1_ETYPE_BOOLEAN -#define TYPE_SEQUENCE ASN1_ETYPE_SEQUENCE -#define TYPE_BIT_STRING ASN1_ETYPE_BIT_STRING -#define TYPE_OCTET_STRING ASN1_ETYPE_OCTET_STRING -#define TYPE_TAG ASN1_ETYPE_TAG -#define TYPE_DEFAULT ASN1_ETYPE_DEFAULT -#define TYPE_SIZE ASN1_ETYPE_SIZE -#define TYPE_SEQUENCE_OF ASN1_ETYPE_SEQUENCE_OF -#define TYPE_OBJECT_ID ASN1_ETYPE_OBJECT_ID -#define TYPE_ANY ASN1_ETYPE_ANY -#define TYPE_SET ASN1_ETYPE_SET -#define TYPE_SET_OF ASN1_ETYPE_SET_OF -#define TYPE_DEFINITIONS ASN1_ETYPE_DEFINITIONS -#define TYPE_TIME ASN1_ETYPE_TIME -#define TYPE_CHOICE ASN1_ETYPE_CHOICE -#define TYPE_IMPORTS ASN1_ETYPE_IMPORTS -#define TYPE_NULL ASN1_ETYPE_NULL -#define TYPE_ENUMERATED ASN1_ETYPE_ENUMERATED -#define TYPE_GENERALSTRING ASN1_ETYPE_GENERALSTRING - - /***********************************************************************/ /* List of constants to better specify the type of typedef asn1_node_st. */ /***********************************************************************/ diff --git a/lib/libtasn1.h b/lib/libtasn1.h index c80a5ca..ad3b554 100644 --- a/lib/libtasn1.h +++ b/lib/libtasn1.h @@ -100,6 +100,14 @@ extern "C" #define ASN1_TAG_ENUMERATED 0x0A #define ASN1_TAG_NULL 0x05 #define ASN1_TAG_GENERALSTRING 0x1B +#define ASN1_TAG_NUMERICSTRING 0x12 +#define ASN1_TAG_IA5STRING 0x16 +#define ASN1_TAG_TELETEXSTRING 0x14 +#define ASN1_TAG_PRINTABLESTRING 0x13 +#define ASN1_TAG_UNIVERSALSTRING 0x1C +#define ASN1_TAG_BMPSTRING 0x1E +#define ASN1_TAG_UTF8STRING 0x0C +#define ASN1_TAG_VISIBLESTRING 0x1A /******************************************************/ /* Structure definition used for the node of the tree */ @@ -126,7 +134,7 @@ extern "C" }; typedef struct asn1_static_node_st asn1_static_node; -/* List of constants for field type of typedef node_asn */ +/* List of constants for field type of node_asn */ #define ASN1_ETYPE_CONSTANT 1 #define ASN1_ETYPE_IDENTIFIER 2 #define ASN1_ETYPE_INTEGER 3 @@ -149,6 +157,14 @@ extern "C" #define ASN1_ETYPE_NULL 20 #define ASN1_ETYPE_ENUMERATED 21 #define ASN1_ETYPE_GENERALSTRING 27 +#define ASN1_ETYPE_NUMERICSTRING 28 +#define ASN1_ETYPE_IA5STRING 29 +#define ASN1_ETYPE_TELETEXSTRING 30 +#define ASN1_ETYPE_PRINTABLESTRING 31 +#define ASN1_ETYPE_UNIVERSALSTRING 32 +#define ASN1_ETYPE_BMPSTRING 33 +#define ASN1_ETYPE_UTF8STRING 34 +#define ASN1_ETYPE_VISIBLESTRING 35 struct asn1_data_node_st { diff --git a/lib/parser_aux.c b/lib/parser_aux.c index 96ecac6..cced582 100644 --- a/lib/parser_aux.c +++ b/lib/parser_aux.c @@ -48,7 +48,7 @@ list_type *firstElement = NULL; /* Description: creates a new NODE_ASN element and */ /* puts it in the list pointed by firstElement. */ /* Parameters: */ -/* type: type of the new element (see TYPE_ */ +/* type: type of the new element (see ASN1_ETYPE_ */ /* and CONST_ constants). */ /* Return: pointer to the new element. */ /******************************************************/ @@ -581,7 +581,7 @@ _asn1_change_integer_value (asn1_node node) p = node; while (p) { - if ((type_field (p->type) == TYPE_INTEGER) && (p->type & CONST_ASSIGN)) + if ((type_field (p->type) == ASN1_ETYPE_INTEGER) && (p->type & CONST_ASSIGN)) { if (p->value) { @@ -653,11 +653,11 @@ _asn1_expand_object_id (asn1_node node) { if (move != UP) { - if ((type_field (p->type) == TYPE_OBJECT_ID) + if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_ASSIGN)) { p2 = p->down; - if (p2 && (type_field (p2->type) == TYPE_CONSTANT)) + if (p2 && (type_field (p2->type) == ASN1_ETYPE_CONSTANT)) { if (p2->value && !isdigit (p2->value[0])) { @@ -666,7 +666,7 @@ _asn1_expand_object_id (asn1_node node) _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); p3 = asn1_find_node (node, name2); - if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || + if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || !(p3->type & CONST_ASSIGN)) return ASN1_ELEMENT_NOT_FOUND; _asn1_set_down (p, p2->right); @@ -675,9 +675,9 @@ _asn1_expand_object_id (asn1_node node) p4 = p3->down; while (p4) { - if (type_field (p4->type) == TYPE_CONSTANT) + if (type_field (p4->type) == ASN1_ETYPE_CONSTANT) { - p5 = _asn1_add_single_node (TYPE_CONSTANT); + p5 = _asn1_add_single_node (ASN1_ETYPE_CONSTANT); _asn1_set_name (p5, p4->name); tlen = _asn1_strlen (p4->value); if (tlen > 0) @@ -742,24 +742,24 @@ _asn1_expand_object_id (asn1_node node) { if (move != UP) { - if ((type_field (p->type) == TYPE_OBJECT_ID) && + if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_DEFAULT)) { p2 = p->down; - if (p2 && (type_field (p2->type) == TYPE_DEFAULT)) + if (p2 && (type_field (p2->type) == ASN1_ETYPE_DEFAULT)) { _asn1_str_cpy (name2, sizeof (name2), name_root); _asn1_str_cat (name2, sizeof (name2), "."); _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); p3 = asn1_find_node (node, name2); - if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || + if (!p3 || (type_field (p3->type) != ASN1_ETYPE_OBJECT_ID) || !(p3->type & CONST_ASSIGN)) return ASN1_ELEMENT_NOT_FOUND; p4 = p3->down; name2[0] = 0; while (p4) { - if (type_field (p4->type) == TYPE_CONSTANT) + if (type_field (p4->type) == ASN1_ETYPE_CONSTANT) { if (name2[0]) _asn1_str_cat (name2, sizeof (name2), "."); @@ -833,12 +833,12 @@ _asn1_type_set_config (asn1_node node) { if (move != UP) { - if (type_field (p->type) == TYPE_SET) + if (type_field (p->type) == ASN1_ETYPE_SET) { p2 = p->down; while (p2) { - if (type_field (p2->type) != TYPE_TAG) + if (type_field (p2->type) != ASN1_ETYPE_TAG) p2->type |= CONST_SET | CONST_NOT_USED; p2 = p2->right; } @@ -902,7 +902,7 @@ _asn1_check_identifier (asn1_node node) p = node; while (p) { - if (type_field (p->type) == TYPE_IDENTIFIER) + if (type_field (p->type) == ASN1_ETYPE_IDENTIFIER) { _asn1_str_cpy (name2, sizeof (name2), node->name); _asn1_str_cat (name2, sizeof (name2), "."); @@ -917,29 +917,29 @@ _asn1_check_identifier (asn1_node node) return ASN1_IDENTIFIER_NOT_FOUND; } } - else if ((type_field (p->type) == TYPE_OBJECT_ID) && + else if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_DEFAULT)) { p2 = p->down; - if (p2 && (type_field (p2->type) == TYPE_DEFAULT)) + if (p2 && (type_field (p2->type) == ASN1_ETYPE_DEFAULT)) { _asn1_str_cpy (name2, sizeof (name2), node->name); _asn1_str_cat (name2, sizeof (name2), "."); _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); _asn1_strcpy (_asn1_identifierMissing, p2->value); p2 = asn1_find_node (node, name2); - if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || + if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID) || !(p2->type & CONST_ASSIGN)) return ASN1_IDENTIFIER_NOT_FOUND; else _asn1_identifierMissing[0] = 0; } } - else if ((type_field (p->type) == TYPE_OBJECT_ID) && + else if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_ASSIGN)) { p2 = p->down; - if (p2 && (type_field (p2->type) == TYPE_CONSTANT)) + if (p2 && (type_field (p2->type) == ASN1_ETYPE_CONSTANT)) { if (p2->value && !isdigit (p2->value[0])) { @@ -948,7 +948,7 @@ _asn1_check_identifier (asn1_node node) _asn1_str_cat (name2, sizeof (name2), (char *) p2->value); _asn1_strcpy (_asn1_identifierMissing, p2->value); p2 = asn1_find_node (node, name2); - if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || + if (!p2 || (type_field (p2->type) != ASN1_ETYPE_OBJECT_ID) || !(p2->type & CONST_ASSIGN)) return ASN1_IDENTIFIER_NOT_FOUND; else @@ -1002,13 +1002,13 @@ _asn1_set_default_tag (asn1_node node) { asn1_node p; - if ((node == NULL) || (type_field (node->type) != TYPE_DEFINITIONS)) + if ((node == NULL) || (type_field (node->type) != ASN1_ETYPE_DEFINITIONS)) return ASN1_ELEMENT_NOT_FOUND; p = node; while (p) { - if ((type_field (p->type) == TYPE_TAG) && + if ((type_field (p->type) == ASN1_ETYPE_TAG) && !(p->type & CONST_EXPLICIT) && !(p->type & CONST_IMPLICIT)) { if (node->type & CONST_EXPLICIT) diff --git a/lib/structure.c b/lib/structure.c index 32be50b..34fd6f0 100644 --- a/lib/structure.c +++ b/lib/structure.c @@ -40,7 +40,7 @@ extern char _asn1_identifierMissing[]; /* Function : _asn1_add_single_node */ /* Description: creates a new NODE_ASN element. */ /* Parameters: */ -/* type: type of the new element (see TYPE_ */ +/* type: type of the new element (see ASN1_ETYPE_ */ /* and CONST_ constants). */ /* Return: pointer to the new element. */ /******************************************************/ @@ -457,18 +457,18 @@ _asn1_type_choice_config (asn1_node node) { if (move != UP) { - if ((type_field (p->type) == TYPE_CHOICE) && (p->type & CONST_TAG)) + if ((type_field (p->type) == ASN1_ETYPE_CHOICE) && (p->type & CONST_TAG)) { p2 = p->down; while (p2) { - if (type_field (p2->type) != TYPE_TAG) + if (type_field (p2->type) != ASN1_ETYPE_TAG) { p2->type |= CONST_TAG; p3 = _asn1_find_left (p2); while (p3) { - if (type_field (p3->type) == TYPE_TAG) + if (type_field (p3->type) == ASN1_ETYPE_TAG) { p4 = _asn1_add_single_node (p3->type); tlen = _asn1_strlen (p3->value); @@ -487,7 +487,7 @@ _asn1_type_choice_config (asn1_node node) while (p2) { p3 = p2->right; - if (type_field (p2->type) == TYPE_TAG) + if (type_field (p2->type) == ASN1_ETYPE_TAG) asn1_delete_structure (&p2); p2 = p3; } @@ -543,7 +543,7 @@ _asn1_expand_identifier (asn1_node * node, asn1_node root) { if (move != UP) { - if (type_field (p->type) == TYPE_IDENTIFIER) + if (type_field (p->type) == ASN1_ETYPE_IDENTIFIER) { snprintf(name2, sizeof (name2), "%s.%s", root->name, p->value); p2 = _asn1_copy_structure2 (root, name2); @@ -715,9 +715,9 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, { switch (type_field (p->type)) { - case TYPE_CONSTANT: - case TYPE_TAG: - case TYPE_SIZE: + case ASN1_ETYPE_CONSTANT: + case ASN1_ETYPE_TAG: + case ASN1_ETYPE_SIZE: break; default: for (k = 0; k < indent; k++) @@ -734,70 +734,94 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, { switch (type_field (p->type)) { - case TYPE_CONSTANT: + case ASN1_ETYPE_CONSTANT: if (mode == ASN1_PRINT_ALL) fprintf (out, "type:CONST"); break; - case TYPE_TAG: + case ASN1_ETYPE_TAG: if (mode == ASN1_PRINT_ALL) fprintf (out, "type:TAG"); break; - case TYPE_SIZE: + case ASN1_ETYPE_SIZE: if (mode == ASN1_PRINT_ALL) fprintf (out, "type:SIZE"); break; - case TYPE_DEFAULT: + case ASN1_ETYPE_DEFAULT: fprintf (out, "type:DEFAULT"); break; - case TYPE_NULL: + case ASN1_ETYPE_NULL: fprintf (out, "type:NULL"); break; - case TYPE_IDENTIFIER: + case ASN1_ETYPE_IDENTIFIER: fprintf (out, "type:IDENTIFIER"); break; - case TYPE_INTEGER: + case ASN1_ETYPE_INTEGER: fprintf (out, "type:INTEGER"); break; - case TYPE_ENUMERATED: + case ASN1_ETYPE_ENUMERATED: fprintf (out, "type:ENUMERATED"); break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: fprintf (out, "type:TIME"); break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: fprintf (out, "type:BOOLEAN"); break; - case TYPE_SEQUENCE: + case ASN1_ETYPE_SEQUENCE: fprintf (out, "type:SEQUENCE"); break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_BIT_STRING: fprintf (out, "type:BIT_STR"); break; - case TYPE_OCTET_STRING: + case ASN1_ETYPE_OCTET_STRING: fprintf (out, "type:OCT_STR"); break; - case TYPE_GENERALSTRING: + case ASN1_ETYPE_GENERALSTRING: fprintf (out, "type:GENERALSTRING"); break; - case TYPE_SEQUENCE_OF: + case ASN1_ETYPE_NUMERICSTRING: + fprintf (out, "type:NUMERICSTRING"); + break; + case ASN1_ETYPE_IA5STRING: + fprintf (out, "type:IA5STRING"); + break; + case ASN1_ETYPE_TELETEXSTRING: + fprintf (out, "type:TELETEXSTRING"); + break; + case ASN1_ETYPE_PRINTABLESTRING: + fprintf (out, "type:PRINTABLESTRING"); + break; + case ASN1_ETYPE_UNIVERSALSTRING: + fprintf (out, "type:UNIVERSALSTRING"); + break; + case ASN1_ETYPE_BMPSTRING: + fprintf (out, "type:BMPSTRING"); + break; + case ASN1_ETYPE_UTF8STRING: + fprintf (out, "type:UTF8STRING"); + break; + case ASN1_ETYPE_VISIBLESTRING: + fprintf (out, "type:VISIBLESTRING"); + break; + case ASN1_ETYPE_SEQUENCE_OF: fprintf (out, "type:SEQ_OF"); break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: fprintf (out, "type:OBJ_ID"); break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: fprintf (out, "type:ANY"); break; - case TYPE_SET: + case ASN1_ETYPE_SET: fprintf (out, "type:SET"); break; - case TYPE_SET_OF: + case ASN1_ETYPE_SET_OF: fprintf (out, "type:SET_OF"); break; - case TYPE_CHOICE: + case ASN1_ETYPE_CHOICE: fprintf (out, "type:CHOICE"); break; - case TYPE_DEFINITIONS: + case ASN1_ETYPE_DEFINITIONS: fprintf (out, "type:DEFINITIONS"); break; default: @@ -809,22 +833,22 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, { switch (type_field (p->type)) { - case TYPE_CONSTANT: + case ASN1_ETYPE_CONSTANT: if (mode == ASN1_PRINT_ALL) if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_TAG: + case ASN1_ETYPE_TAG: if (mode == ASN1_PRINT_ALL) if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_SIZE: + case ASN1_ETYPE_SIZE: if (mode == ASN1_PRINT_ALL) if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_DEFAULT: + case ASN1_ETYPE_DEFAULT: if (p->value) fprintf (out, " value:%s", p->value); else if (p->type & CONST_TRUE) @@ -832,11 +856,11 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, else if (p->type & CONST_FALSE) fprintf (out, " value:FALSE"); break; - case TYPE_IDENTIFIER: + case ASN1_ETYPE_IDENTIFIER: if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_INTEGER: + case ASN1_ETYPE_INTEGER: if (p->value) { len2 = -1; @@ -847,7 +871,7 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, fprintf (out, "%02x", (p->value)[k + len2]); } break; - case TYPE_ENUMERATED: + case ASN1_ETYPE_ENUMERATED: if (p->value) { len2 = -1; @@ -858,11 +882,11 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, fprintf (out, "%02x", (p->value)[k + len2]); } break; - case TYPE_TIME: + case ASN1_ETYPE_TIME: if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_BOOLEAN: + case ASN1_ETYPE_BOOLEAN: if (p->value) { if (p->value[0] == 'T') @@ -871,7 +895,7 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, fprintf (out, " value:FALSE"); } break; - case TYPE_BIT_STRING: + case ASN1_ETYPE_BIT_STRING: if (p->value) { len2 = -1; @@ -885,18 +909,16 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, } } break; - case TYPE_OCTET_STRING: - if (p->value) - { - len2 = -1; - len = asn1_get_length_der (p->value, p->value_len, &len2); - fprintf (out, " value:"); - if (len > 0) - for (k = 0; k < len; k++) - fprintf (out, "%02x", (p->value)[k + len2]); - } - break; - case TYPE_GENERALSTRING: + case ASN1_ETYPE_OCTET_STRING: + case ASN1_ETYPE_GENERALSTRING: + case ASN1_ETYPE_NUMERICSTRING: + case ASN1_ETYPE_IA5STRING: + case ASN1_ETYPE_TELETEXSTRING: + case ASN1_ETYPE_PRINTABLESTRING: + case ASN1_ETYPE_UNIVERSALSTRING: + case ASN1_ETYPE_BMPSTRING: + case ASN1_ETYPE_UTF8STRING: + case ASN1_ETYPE_VISIBLESTRING: if (p->value) { len2 = -1; @@ -907,11 +929,11 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, fprintf (out, "%02x", (p->value)[k + len2]); } break; - case TYPE_OBJECT_ID: + case ASN1_ETYPE_OBJECT_ID: if (p->value) fprintf (out, " value:%s", p->value); break; - case TYPE_ANY: + case ASN1_ETYPE_ANY: if (p->value) { len3 = -1; @@ -922,13 +944,13 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, fprintf (out, "%02x", (p->value)[k + len3]); } break; - case TYPE_SET: - case TYPE_SET_OF: - case TYPE_CHOICE: - case TYPE_DEFINITIONS: - case TYPE_SEQUENCE_OF: - case TYPE_SEQUENCE: - case TYPE_NULL: + case ASN1_ETYPE_SET: + case ASN1_ETYPE_SET_OF: + case ASN1_ETYPE_CHOICE: + case ASN1_ETYPE_DEFINITIONS: + case ASN1_ETYPE_SEQUENCE_OF: + case ASN1_ETYPE_SEQUENCE: + case ASN1_ETYPE_NULL: break; default: break; @@ -991,9 +1013,9 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, { switch (type_field (p->type)) { - case TYPE_CONSTANT: - case TYPE_TAG: - case TYPE_SIZE: + case ASN1_ETYPE_CONSTANT: + case ASN1_ETYPE_TAG: + case ASN1_ETYPE_SIZE: break; default: fprintf (out, "\n"); @@ -1105,7 +1127,7 @@ asn1_find_structure_from_oid (asn1_node definitions, const char *oidValue) p = definitions->down; while (p) { - if ((type_field (p->type) == TYPE_OBJECT_ID) && + if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_ASSIGN)) { strcpy (name, definitionsName); |