From dcafe721bfb38c26e9d67d6649313a9430f62155 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 18 Oct 2010 17:21:43 -0700 Subject: [PATCH] crypt32: Implement quoting of BMP strings. --- dlls/crypt32/str.c | 41 ++++++++++++++++++++++++++++++++++++++++ dlls/crypt32/tests/str.c | 10 +++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index d3a1a367c14..2f90110301b 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -100,6 +100,46 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, ret = ptr - psz; } break; + case CERT_RDN_BMP_STRING: + len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData, + pValue->cbData / sizeof(WCHAR), NULL, 0, NULL, NULL); + if (pValue->cbData && isspaceW(((LPCWSTR)pValue->pbData)[0])) + needsQuotes = TRUE; + if (pValue->cbData && + isspaceW(((LPCWSTR)pValue->pbData)[pValue->cbData / sizeof(WCHAR)-1])) + needsQuotes = TRUE; + for (i = 0; i < pValue->cbData / sizeof(WCHAR); i++) + { + if (is_quotable_char(((LPCWSTR)pValue->pbData)[i])) + needsQuotes = TRUE; + if (((LPCWSTR)pValue->pbData)[i] == '"') + len += 1; + } + if (needsQuotes) + len += 2; + if (!psz || !csz) + ret = len; + else + { + char *dst = psz; + + if (needsQuotes) + *dst++ = '"'; + for (i = 0; i < pValue->cbData / sizeof(WCHAR) && + dst - psz < csz; dst++, i++) + { + LPCWSTR src = (LPCWSTR)pValue->pbData + i; + + WideCharToMultiByte(CP_ACP, 0, src, 1, dst, + csz - (dst - psz) - 1, NULL, NULL); + if (*src == '"' && dst - psz < csz - 1) + *(++dst) = '"'; + } + if (needsQuotes && dst - psz < csz) + *dst++ = '"'; + ret = dst - psz; + } + break; case CERT_RDN_UTF8_STRING: if (!psz || !csz) ret = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)pValue->pbData, @@ -146,6 +186,7 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, case CERT_RDN_GRAPHIC_STRING: case CERT_RDN_VISIBLE_STRING: case CERT_RDN_GENERAL_STRING: + case CERT_RDN_BMP_STRING: len = pValue->cbData; if (pValue->cbData && isspace(pValue->pbData[0])) needsQuotes = TRUE; diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index 3032b9358f9..e59b933bfb4 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -443,7 +443,7 @@ static void test_CertNameToStrA(void) blob.pbData = encodedQuotedCN; blob.cbData = sizeof(encodedQuotedCN); test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"\"\"1\"\"\"", - TRUE); + FALSE); blob.pbData = encodedMultipleAttrCN; blob.cbData = sizeof(encodedMultipleAttrCN); test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"1+2\"", FALSE); @@ -455,16 +455,16 @@ static void test_CertNameToStrA(void) test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a=b\"", FALSE); blob.pbData = encodedLessThanCN; blob.cbData = sizeof(encodedLessThanCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"<\"", TRUE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"<\"", FALSE); blob.pbData = encodedGreaterThanCN; blob.cbData = sizeof(encodedGreaterThanCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\">\"", TRUE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\">\"", FALSE); blob.pbData = encodedHashCN; blob.cbData = sizeof(encodedHashCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"#\"", TRUE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"#\"", FALSE); blob.pbData = encodedSemiCN; blob.cbData = sizeof(encodedSemiCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\";\"", TRUE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\";\"", FALSE); } static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType,