diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-22 19:38:38 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-22 19:39:17 +0100 |
commit | eba04f5f91b62c33a800ed8cf3325a4d82e12dd5 (patch) | |
tree | e484cad65fadb7cd2f4968019f4c15347716e47a | |
parent | 3b545f01f74778112769ef1a1225324d6428423a (diff) | |
download | libtasn1-eba04f5f91b62c33a800ed8cf3325a4d82e12dd5.tar.gz libtasn1-eba04f5f91b62c33a800ed8cf3325a4d82e12dd5.tar.bz2 libtasn1-eba04f5f91b62c33a800ed8cf3325a4d82e12dd5.zip |
small simplifications
-rw-r--r-- | lib/coding.c | 61 | ||||
-rw-r--r-- | lib/decoding.c | 3 | ||||
-rw-r--r-- | lib/element.c | 21 | ||||
-rw-r--r-- | lib/int.h | 24 | ||||
-rw-r--r-- | lib/structure.c | 66 |
5 files changed, 53 insertions, 122 deletions
diff --git a/lib/coding.c b/lib/coding.c index af5c1b7..ba59257 100644 --- a/lib/coding.c +++ b/lib/coding.c @@ -431,26 +431,26 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der, 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}, + [ASN1_ETYPE_GENERALSTRING] = {ASN1_TAG_GENERALSTRING, ASN1_CLASS_UNIVERSAL, "type:GENERALSTRING"}, + [ASN1_ETYPE_NUMERICSTRING] = {ASN1_TAG_NUMERICSTRING, ASN1_CLASS_UNIVERSAL, "type:NUMERIC_STR"}, + [ASN1_ETYPE_IA5STRING] = {ASN1_TAG_IA5STRING, ASN1_CLASS_UNIVERSAL, "type:IA5_STR"}, + [ASN1_ETYPE_TELETEXSTRING] = {ASN1_TAG_TELETEXSTRING, ASN1_CLASS_UNIVERSAL, "type:TELETEX_STR"}, + [ASN1_ETYPE_PRINTABLESTRING] = {ASN1_TAG_PRINTABLESTRING, ASN1_CLASS_UNIVERSAL, "type:PRINTABLE_STR"}, + [ASN1_ETYPE_UNIVERSALSTRING] = {ASN1_TAG_UNIVERSALSTRING, ASN1_CLASS_UNIVERSAL, "type:UNIVERSAL_STR"}, + [ASN1_ETYPE_BMPSTRING] = {ASN1_TAG_BMPSTRING, ASN1_CLASS_UNIVERSAL, "type:BMP_STR"}, + [ASN1_ETYPE_UTF8STRING] = {ASN1_TAG_UTF8STRING, ASN1_CLASS_UNIVERSAL, "type:UTF8_STR"}, + [ASN1_ETYPE_VISIBLESTRING] = {ASN1_TAG_VISIBLESTRING, ASN1_CLASS_UNIVERSAL, "type:VISIBLE_STR"}, + [ASN1_ETYPE_OCTET_STRING] = {ASN1_TAG_OCTET_STRING, ASN1_CLASS_UNIVERSAL, "type:OCT_STR"}, + [ASN1_ETYPE_BIT_STRING] = {ASN1_TAG_BIT_STRING, ASN1_CLASS_UNIVERSAL, "type:BIT_STR"}, + [ASN1_ETYPE_OBJECT_ID] = {ASN1_TAG_OBJECT_ID, ASN1_CLASS_UNIVERSAL, "type:OBJ_STR"}, + [ASN1_ETYPE_NULL] = {ASN1_TAG_NULL, ASN1_CLASS_UNIVERSAL, "type:NULL"}, + [ASN1_ETYPE_BOOLEAN] = {ASN1_TAG_BOOLEAN, ASN1_CLASS_UNIVERSAL, "type:BOOLEAN"}, + [ASN1_ETYPE_INTEGER] = {ASN1_TAG_INTEGER, ASN1_CLASS_UNIVERSAL, "type:INTEGER"}, + [ASN1_ETYPE_ENUMERATED] = {ASN1_TAG_ENUMERATED, ASN1_CLASS_UNIVERSAL, "type:ENUMERATED"}, + [ASN1_ETYPE_SEQUENCE] = {ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SEQUENCE"}, + [ASN1_ETYPE_SEQUENCE_OF] ={ASN1_TAG_SEQUENCE, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SEQ_OF"}, + [ASN1_ETYPE_SET] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET"}, + [ASN1_ETYPE_SET_OF] = {ASN1_TAG_SET, ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED, "type:SET_OF"}, }; /******************************************************/ @@ -554,26 +554,7 @@ _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 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: + CASE_TAGGED_TYPES: _asn1_tag_der (_asn1_tags[type].class, _asn1_tags[type].tag, tag_der, &tag_len); break; diff --git a/lib/decoding.c b/lib/decoding.c index 5a844b8..eb4ca0e 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -531,7 +531,8 @@ _asn1_extract_tag_der (asn1_node node, const unsigned char *der, int der_len, break; case ASN1_ETYPE_OCTET_STRING: - /* does it need to be structured??? --nmav */ + /* OCTET STRING is handled differently to allow + * BER encodings (structured class). */ if (((class != ASN1_CLASS_UNIVERSAL) && (class != (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED))) || (tag != ASN1_TAG_OCTET_STRING)) diff --git a/lib/element.c b/lib/element.c index 2c6a2fd..f1d002e 100644 --- a/lib/element.c +++ b/lib/element.c @@ -926,26 +926,7 @@ asn1_read_tag (asn1_node root, const char *name, int *tagValue, switch (type) { - 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: + CASE_TAGGED_TYPES: *tagValue = _asn1_tags[type].tag; break; case ASN1_ETYPE_TIME: @@ -61,8 +61,32 @@ struct asn1_node_st typedef struct tag_and_class_st { unsigned tag; unsigned class; + const char* desc; } tag_and_class_st; +/* the types that are handled in _asn1_tags */ +#define CASE_TAGGED_TYPES \ + 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 + extern tag_and_class_st _asn1_tags[]; #define _asn1_strlen(s) strlen((const char *) s) diff --git a/lib/structure.c b/lib/structure.c index 34fd6f0..eee15a3 100644 --- a/lib/structure.c +++ b/lib/structure.c @@ -732,7 +732,8 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, if (mode != ASN1_PRINT_NAME) { - switch (type_field (p->type)) + unsigned type = type_field (p->type); + switch (type) { case ASN1_ETYPE_CONSTANT: if (mode == ASN1_PRINT_ALL) @@ -749,81 +750,24 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name, case ASN1_ETYPE_DEFAULT: fprintf (out, "type:DEFAULT"); break; - case ASN1_ETYPE_NULL: - fprintf (out, "type:NULL"); - break; case ASN1_ETYPE_IDENTIFIER: fprintf (out, "type:IDENTIFIER"); break; - case ASN1_ETYPE_INTEGER: - fprintf (out, "type:INTEGER"); - break; - case ASN1_ETYPE_ENUMERATED: - fprintf (out, "type:ENUMERATED"); - break; case ASN1_ETYPE_TIME: fprintf (out, "type:TIME"); break; - case ASN1_ETYPE_BOOLEAN: - fprintf (out, "type:BOOLEAN"); - break; - case ASN1_ETYPE_SEQUENCE: - fprintf (out, "type:SEQUENCE"); - break; - case ASN1_ETYPE_BIT_STRING: - fprintf (out, "type:BIT_STR"); - break; - case ASN1_ETYPE_OCTET_STRING: - fprintf (out, "type:OCT_STR"); - break; - case ASN1_ETYPE_GENERALSTRING: - fprintf (out, "type:GENERALSTRING"); - break; - 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 ASN1_ETYPE_OBJECT_ID: - fprintf (out, "type:OBJ_ID"); - break; case ASN1_ETYPE_ANY: fprintf (out, "type:ANY"); break; - case ASN1_ETYPE_SET: - fprintf (out, "type:SET"); - break; - case ASN1_ETYPE_SET_OF: - fprintf (out, "type:SET_OF"); - break; case ASN1_ETYPE_CHOICE: fprintf (out, "type:CHOICE"); break; case ASN1_ETYPE_DEFINITIONS: fprintf (out, "type:DEFINITIONS"); break; + CASE_TAGGED_TYPES: + fprintf (out, "%s", _asn1_tags[type].desc); + break; default: break; } |