crypt32: Implement quoting of BMP strings.

This commit is contained in:
Juan Lang 2010-10-18 17:21:43 -07:00 committed by Alexandre Julliard
parent 993068038e
commit dcafe721bf
2 changed files with 46 additions and 5 deletions

View File

@ -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;

View File

@ -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,