From: Beat Bolli Date: Sun, 14 Feb 2021 22:47:57 +0000 (+0100) Subject: Add tests for the limited Unicode code point range X-Git-Tag: openssl-3.0.0-alpha14~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d07d8057991712261323c05bb022d000a01404d0;p=thirdparty%2Fopenssl.git Add tests for the limited Unicode code point range Signed-off-by: Beat Bolli Reviewed-by: Shane Lontis Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/14185) --- diff --git a/test/asn1_internal_test.c b/test/asn1_internal_test.c index e77299a7c8e..cf201a5a267 100644 --- a/test/asn1_internal_test.c +++ b/test/asn1_internal_test.c @@ -107,9 +107,50 @@ static int test_standard_methods(void) return 0; } +/********************************************************************** + * + * Tests of the Unicode code point range + * + ***/ + +static int test_unicode(const unsigned char *univ, size_t len, int expected) +{ + const unsigned char *end = univ + len; + int ok = 1; + + for (; univ < end; univ += 4) { + if (!TEST_int_eq(ASN1_mbstring_copy(NULL, univ, 4, MBSTRING_UNIV, + B_ASN1_UTF8STRING), + expected)) + ok = 0; + } + return ok; +} + +static int test_unicode_range(void) +{ + const unsigned char univ_ok[] = "\0\0\0\0" + "\0\0\xd7\xff" + "\0\0\xe0\x00" + "\0\x10\xff\xff"; + const unsigned char univ_bad[] = "\0\0\xd8\x00" + "\0\0\xdf\xff" + "\0\x11\x00\x00" + "\x80\x00\x00\x00" + "\xff\xff\xff\xff"; + int ok = 1; + + if (!test_unicode(univ_ok, sizeof univ_ok - 1, V_ASN1_UTF8STRING)) + ok = 0; + if (!test_unicode(univ_bad, sizeof univ_bad - 1, -1)) + ok = 0; + return ok; +} + int setup_tests(void) { ADD_TEST(test_tbl_standard); ADD_TEST(test_standard_methods); + ADD_TEST(test_unicode_range); return 1; }