summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_strex.c
diff options
context:
space:
mode:
authorjsing <>2021-12-14 17:35:21 +0000
committerjsing <>2021-12-14 17:35:21 +0000
commit9ba2385eabb29de87df68ff88f34bbd29ed4952e (patch)
treec1a26d3aa6222d08c3946dc662d663cc793fc23d /src/lib/libcrypto/asn1/a_strex.c
parentbb673fb853e10ee12848841c7d2608a5018a7e5c (diff)
downloadopenbsd-9ba2385eabb29de87df68ff88f34bbd29ed4952e.tar.gz
openbsd-9ba2385eabb29de87df68ff88f34bbd29ed4952e.tar.bz2
openbsd-9ba2385eabb29de87df68ff88f34bbd29ed4952e.zip
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 'src/lib/libcrypto/asn1/a_strex.c')
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c47
1 files changed, 13 insertions, 34 deletions
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index 3b66ea8d36..61672d29a4 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_strex.c,v 1.29 2021/11/01 20:53:08 tb Exp $ */ 1/* $OpenBSD: a_strex.c,v 1.30 2021/12/14 17:35:21 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -322,22 +322,6 @@ do_dump(unsigned long lflags, char_io *io_ch, void *arg, const ASN1_STRING *str)
322 return outlen + 1; 322 return outlen + 1;
323} 323}
324 324
325/* Lookup table to convert tags to character widths,
326 * 0 = UTF8 encoded, -1 is used for non string types
327 * otherwise it is the number of bytes per character
328 */
329
330static const signed char tag2nbyte[] = {
331 -1, -1, -1, -1, -1, /* 0-4 */
332 -1, -1, -1, -1, -1, /* 5-9 */
333 -1, -1, 0, -1, /* 10-13 */
334 -1, -1, -1, -1, /* 15-17 */
335 -1, 1, 1, /* 18-20 */
336 -1, 1, 1, 1, /* 21-24 */
337 -1, 1, -1, /* 25-27 */
338 4, -1, 2 /* 28-30 */
339};
340
341/* This is the main function, print out an 325/* This is the main function, print out an
342 * ASN1_STRING taking note of various escape 326 * ASN1_STRING taking note of various escape
343 * and display options. Returns number of 327 * and display options. Returns number of
@@ -371,19 +355,16 @@ do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
371 355
372 /* Decide what to do with type, either dump content or display it */ 356 /* Decide what to do with type, either dump content or display it */
373 357
374 /* Dump everything */ 358 if (lflags & ASN1_STRFLGS_DUMP_ALL) {
375 if (lflags & ASN1_STRFLGS_DUMP_ALL) 359 /* Dump everything. */
376 type = -1; 360 type = -1;
377 /* Ignore the string type */ 361 } else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) {
378 else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) 362 /* Ignore the string type. */
379 type = 1; 363 type = 1;
380 else { 364 } else {
381 /* Else determine width based on type */ 365 /* Else determine width based on type. */
382 if ((type > 0) && (type < 31)) 366 type = asn1_tag2charwidth(type);
383 type = tag2nbyte[type]; 367 if (type == -1 && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
384 else
385 type = -1;
386 if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
387 type = 1; 368 type = 1;
388 } 369 }
389 370
@@ -627,17 +608,15 @@ int
627ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) 608ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in)
628{ 609{
629 ASN1_STRING stmp, *str = &stmp; 610 ASN1_STRING stmp, *str = &stmp;
630 int mbflag, type, ret; 611 int mbflag, ret;
631 612
632 if (!in) 613 if (!in)
633 return -1; 614 return -1;
634 type = in->type; 615
635 if ((type < 0) || (type > 30)) 616 if ((mbflag = asn1_tag2charwidth(in->type)) == -1)
636 return -1;
637 mbflag = tag2nbyte[type];
638 if (mbflag == -1)
639 return -1; 617 return -1;
640 mbflag |= MBSTRING_FLAG; 618 mbflag |= MBSTRING_FLAG;
619
641 stmp.data = NULL; 620 stmp.data = NULL;
642 stmp.length = 0; 621 stmp.length = 0;
643 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, 622 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag,