summaryrefslogtreecommitdiff
path: root/lib/libcrypto/asn1/a_strex.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2021-12-14 17:35:22 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2021-12-14 17:35:22 +0000
commit21fccdcda6a5af59433905ae9f6a20dacb8e371b (patch)
treeed7cc63ad0ceee0bce4c7c4ecf78527a549e5f4d /lib/libcrypto/asn1/a_strex.c
parentc229d3008350fb52ed0141aa12f23feade41e147 (diff)
Consolidate ASN.1 universal tag type data.
There are currently three different tables in three different files that contain information about ASN.1 universal class tag types. Range checking is also implemented in three different places (with different implementations). Consolidate all of this into a single table, provide a lookup function that deals with the range checks and wrappers to deal with specific types. ok inoguchi@ tb@
Diffstat (limited to 'lib/libcrypto/asn1/a_strex.c')
-rw-r--r--lib/libcrypto/asn1/a_strex.c47
1 files changed, 13 insertions, 34 deletions
diff --git a/lib/libcrypto/asn1/a_strex.c b/lib/libcrypto/asn1/a_strex.c
index 3b66ea8d36d..61672d29a44 100644
--- a/lib/libcrypto/asn1/a_strex.c
+++ b/lib/libcrypto/asn1/a_strex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_strex.c,v 1.29 2021/11/01 20:53:08 tb Exp $ */
+/* $OpenBSD: a_strex.c,v 1.30 2021/12/14 17:35:21 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@@ -322,22 +322,6 @@ do_dump(unsigned long lflags, char_io *io_ch, void *arg, const ASN1_STRING *str)
return outlen + 1;
}
-/* Lookup table to convert tags to character widths,
- * 0 = UTF8 encoded, -1 is used for non string types
- * otherwise it is the number of bytes per character
- */
-
-static const signed char tag2nbyte[] = {
- -1, -1, -1, -1, -1, /* 0-4 */
- -1, -1, -1, -1, -1, /* 5-9 */
- -1, -1, 0, -1, /* 10-13 */
- -1, -1, -1, -1, /* 15-17 */
- -1, 1, 1, /* 18-20 */
- -1, 1, 1, 1, /* 21-24 */
- -1, 1, -1, /* 25-27 */
- 4, -1, 2 /* 28-30 */
-};
-
/* This is the main function, print out an
* ASN1_STRING taking note of various escape
* and display options. Returns number of
@@ -371,19 +355,16 @@ do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
/* Decide what to do with type, either dump content or display it */
- /* Dump everything */
- if (lflags & ASN1_STRFLGS_DUMP_ALL)
+ if (lflags & ASN1_STRFLGS_DUMP_ALL) {
+ /* Dump everything. */
type = -1;
- /* Ignore the string type */
- else if (lflags & ASN1_STRFLGS_IGNORE_TYPE)
+ } else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) {
+ /* Ignore the string type. */
type = 1;
- else {
- /* Else determine width based on type */
- if ((type > 0) && (type < 31))
- type = tag2nbyte[type];
- else
- type = -1;
- if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
+ } else {
+ /* Else determine width based on type. */
+ type = asn1_tag2charwidth(type);
+ if (type == -1 && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
type = 1;
}
@@ -627,17 +608,15 @@ int
ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in)
{
ASN1_STRING stmp, *str = &stmp;
- int mbflag, type, ret;
+ int mbflag, ret;
if (!in)
return -1;
- type = in->type;
- if ((type < 0) || (type > 30))
- return -1;
- mbflag = tag2nbyte[type];
- if (mbflag == -1)
+
+ if ((mbflag = asn1_tag2charwidth(in->type)) == -1)
return -1;
mbflag |= MBSTRING_FLAG;
+
stmp.data = NULL;
stmp.length = 0;
ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag,