crypt32: Correct Unicode quoting of BMP strings.
This commit is contained in:
parent
bf70d35529
commit
7833f30721
|
@ -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,7 +175,6 @@ 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;
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue