Commit 7833f307 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Correct Unicode quoting of BMP strings.

parent bf70d355
......@@ -73,12 +73,12 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
needsQuotes = TRUE;
for (i = 0; i < pValue->cbData; i++)
{
{
if (is_quotable_char(pValue->pbData[i]))
needsQuotes = TRUE;
if (pValue->pbData[i] == '"')
len += 1;
}
}
if (needsQuotes)
len += 2;
if (!psz || !csz)
......@@ -158,7 +158,7 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
LPWSTR psz, DWORD csz)
{
DWORD ret = 0, len, i;
DWORD ret = 0, len, i, strLen;
BOOL needsQuotes = FALSE;
TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
......@@ -175,19 +175,18 @@ 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;
if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
needsQuotes = TRUE;
for (i = 0; i < pValue->cbData; i++)
{
{
if (is_quotable_char(pValue->pbData[i]))
needsQuotes = TRUE;
if (pValue->pbData[i] == '"')
len += 1;
}
}
if (needsQuotes)
len += 2;
if (!psz || !csz)
......@@ -209,6 +208,40 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
ret = ptr - psz;
}
break;
case CERT_RDN_BMP_STRING:
strLen = len = pValue->cbData / sizeof(WCHAR);
if (pValue->cbData && isspace(pValue->pbData[0]))
needsQuotes = TRUE;
if (pValue->cbData && isspace(pValue->pbData[strLen - 1]))
needsQuotes = TRUE;
for (i = 0; i < strLen; 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
{
WCHAR *ptr = psz;
if (needsQuotes)
*ptr++ = '"';
for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++)
{
*ptr = ((LPCWSTR)pValue->pbData)[i];
if (((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1)
*(++ptr) = '"';
}
if (needsQuotes && ptr - psz < csz)
*ptr++ = '"';
ret = ptr - psz;
}
break;
default:
FIXME("string type %d unimplemented\n", dwValueType);
}
......
......@@ -570,7 +570,7 @@ static void test_CertNameToStrW(void)
blob.pbData = encodedQuotedCN;
blob.cbData = sizeof(encodedQuotedCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, quotedCN_W,
TRUE);
FALSE);
blob.pbData = encodedMultipleAttrCN;
blob.cbData = sizeof(encodedMultipleAttrCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, multipleAttrCN_W,
......@@ -583,17 +583,17 @@ static void test_CertNameToStrW(void)
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, equalCN_W, FALSE);
blob.pbData = encodedLessThanCN;
blob.cbData = sizeof(encodedLessThanCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, TRUE);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, FALSE);
blob.pbData = encodedGreaterThanCN;
blob.cbData = sizeof(encodedGreaterThanCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, greaterThanCN_W,
TRUE);
FALSE);
blob.pbData = encodedHashCN;
blob.cbData = sizeof(encodedHashCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, TRUE);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, FALSE);
blob.pbData = encodedSemiCN;
blob.cbData = sizeof(encodedSemiCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, TRUE);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, FALSE);
}
struct StrToNameA
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment