summaryrefslogtreecommitdiff
path: root/deps/openssl/openssl/crypto/asn1/a_mbstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/openssl/openssl/crypto/asn1/a_mbstr.c')
-rw-r--r--deps/openssl/openssl/crypto/asn1/a_mbstr.c70
1 files changed, 9 insertions, 61 deletions
diff --git a/deps/openssl/openssl/crypto/asn1/a_mbstr.c b/deps/openssl/openssl/crypto/asn1/a_mbstr.c
index 7a035afbae..949fe6c161 100644
--- a/deps/openssl/openssl/crypto/asn1/a_mbstr.c
+++ b/deps/openssl/openssl/crypto/asn1/a_mbstr.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -8,7 +8,7 @@
*/
#include <stdio.h>
-#include <ctype.h>
+#include "internal/ctype.h"
#include "internal/cryptlib.h"
#include <openssl/asn1.h>
@@ -22,8 +22,6 @@ static int cpy_asc(unsigned long value, void *arg);
static int cpy_bmp(unsigned long value, void *arg);
static int cpy_univ(unsigned long value, void *arg);
static int cpy_utf8(unsigned long value, void *arg);
-static int is_numeric(unsigned long value);
-static int is_printable(unsigned long value);
/*
* These functions take a string in UTF8, ASCII or multibyte form and a mask
@@ -271,13 +269,15 @@ static int out_utf8(unsigned long value, void *arg)
static int type_str(unsigned long value, void *arg)
{
- unsigned long types;
- types = *((unsigned long *)arg);
- if ((types & B_ASN1_NUMERICSTRING) && !is_numeric(value))
+ unsigned long types = *((unsigned long *)arg);
+ const int native = value > INT_MAX ? INT_MAX : ossl_fromascii(value);
+
+ if ((types & B_ASN1_NUMERICSTRING) && !(ossl_isdigit(native)
+ || native == ' '))
types &= ~B_ASN1_NUMERICSTRING;
- if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
+ if ((types & B_ASN1_PRINTABLESTRING) && !ossl_isasn1print(native))
types &= ~B_ASN1_PRINTABLESTRING;
- if ((types & B_ASN1_IA5STRING) && (value > 127))
+ if ((types & B_ASN1_IA5STRING) && !ossl_isascii(native))
types &= ~B_ASN1_IA5STRING;
if ((types & B_ASN1_T61STRING) && (value > 0xff))
types &= ~B_ASN1_T61STRING;
@@ -341,55 +341,3 @@ static int cpy_utf8(unsigned long value, void *arg)
*p += ret;
return 1;
}
-
-/* Return 1 if the character is permitted in a PrintableString */
-static int is_printable(unsigned long value)
-{
- int ch;
- if (value > 0x7f)
- return 0;
- ch = (int)value;
- /*
- * Note: we can't use 'isalnum' because certain accented characters may
- * count as alphanumeric in some environments.
- */
-#ifndef CHARSET_EBCDIC
- if ((ch >= 'a') && (ch <= 'z'))
- return 1;
- if ((ch >= 'A') && (ch <= 'Z'))
- return 1;
- if ((ch >= '0') && (ch <= '9'))
- return 1;
- if ((ch == ' ') || strchr("'()+,-./:=?", ch))
- return 1;
-#else /* CHARSET_EBCDIC */
- if ((ch >= os_toascii['a']) && (ch <= os_toascii['z']))
- return 1;
- if ((ch >= os_toascii['A']) && (ch <= os_toascii['Z']))
- return 1;
- if ((ch >= os_toascii['0']) && (ch <= os_toascii['9']))
- return 1;
- if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch]))
- return 1;
-#endif /* CHARSET_EBCDIC */
- return 0;
-}
-
-/* Return 1 if the character is a digit or space */
-static int is_numeric(unsigned long value)
-{
- int ch;
- if (value > 0x7f)
- return 0;
- ch = (int)value;
-#ifndef CHARSET_EBCDIC
- if (!isdigit(ch) && ch != ' ')
- return 0;
-#else
- if (ch > os_toascii['9'])
- return 0;
- if (ch < os_toascii['0'] && ch != os_toascii[' '])
- return 0;
-#endif
- return 1;
-}