summaryrefslogtreecommitdiffstats
path: root/crypto/asn1/a_mbstr.c
diff options
context:
space:
mode:
authorDmitry Belyavsky <beldmit@gmail.com>2015-08-26 13:34:31 +0100
committerMatt Caswell <matt@openssl.org>2015-09-07 10:34:44 +0100
commit68572c8af3ebb0a0729acad2196763df463927c1 (patch)
treeb8f3725da9dbd9a7f605c950f4c552d04137a588 /crypto/asn1/a_mbstr.c
parent26d57a1a9225db13324d6c699753437da4de910c (diff)
Add NumericString support
GOST requires improved NumericString support. Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'crypto/asn1/a_mbstr.c')
-rw-r--r--crypto/asn1/a_mbstr.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c
index 241eb60bcc..823839ffba 100644
--- a/crypto/asn1/a_mbstr.c
+++ b/crypto/asn1/a_mbstr.c
@@ -72,6 +72,7 @@ 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);
/*
@@ -169,7 +170,9 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
/* Now work out output format and string type */
outform = MBSTRING_ASC;
- if (mask & B_ASN1_PRINTABLESTRING)
+ if (mask & B_ASN1_NUMERICSTRING)
+ str_type = V_ASN1_NUMERICSTRING;
+ else if (mask & B_ASN1_PRINTABLESTRING)
str_type = V_ASN1_PRINTABLESTRING;
else if (mask & B_ASN1_IA5STRING)
str_type = V_ASN1_IA5STRING;
@@ -320,6 +323,8 @@ static int type_str(unsigned long value, void *arg)
{
unsigned long types;
types = *((unsigned long *)arg);
+ if ((types & B_ASN1_NUMERICSTRING) && !is_numeric(value))
+ types &= ~B_ASN1_NUMERICSTRING;
if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
types &= ~B_ASN1_PRINTABLESTRING;
if ((types & B_ASN1_IA5STRING) && (value > 127))
@@ -419,3 +424,12 @@ static int is_printable(unsigned long value)
#endif /* CHARSET_EBCDIC */
return 0;
}
+
+static int is_numeric(unsigned long value)
+{
+ if (value > '9')
+ return 0;
+ if (value < '0' && value != 32)
+ return 0;
+ return 1;
+}