From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/crypt32/str.c | 61 ++++++++++++++++++++++------------------ dlls/crypt32/tests/str.c | 2 -- 2 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 63333e5f736..50c05dd88bd 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -139,8 +139,8 @@ static inline BOOL is_quotable_char(WCHAR c) } }
-static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, - PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz) +static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, + DWORD dwStrType, LPWSTR psz, DWORD csz) { DWORD ret = 0, len, i, strLen; BOOL needsQuotes = FALSE; @@ -160,19 +160,22 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, case CERT_RDN_VISIBLE_STRING: case CERT_RDN_GENERAL_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 (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG)) { - if (is_quotable_char(pValue->pbData[i])) + if (pValue->cbData && isspace(pValue->pbData[0])) needsQuotes = TRUE; - if (pValue->pbData[i] == '"') - len += 1; + 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 (needsQuotes) - len += 2; if (!psz || !csz) ret = len; else @@ -184,7 +187,8 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, for (i = 0; i < pValue->cbData && ptr - psz < csz; ptr++, i++) { *ptr = pValue->pbData[i]; - if (pValue->pbData[i] == '"' && ptr - psz < csz - 1) + if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG) && + pValue->pbData[i] == '"' && ptr - psz < csz - 1) *(++ptr) = '"'; } if (needsQuotes && ptr - psz < csz) @@ -195,19 +199,22 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, case CERT_RDN_BMP_STRING: case CERT_RDN_UTF8_STRING: strLen = len = pValue->cbData / sizeof(WCHAR); - if (pValue->cbData && iswspace(((LPCWSTR)pValue->pbData)[0])) - needsQuotes = TRUE; - if (pValue->cbData && iswspace(((LPCWSTR)pValue->pbData)[strLen - 1])) - needsQuotes = TRUE; - for (i = 0; i < strLen; i++) + if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG)) { - if (is_quotable_char(((LPCWSTR)pValue->pbData)[i])) + if (pValue->cbData && iswspace(((LPCWSTR)pValue->pbData)[0])) needsQuotes = TRUE; - if (((LPCWSTR)pValue->pbData)[i] == '"') - len += 1; + if (pValue->cbData && iswspace(((LPCWSTR)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 (needsQuotes) - len += 2; if (!psz || !csz) ret = len; else @@ -219,7 +226,8 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++) { *ptr = ((LPCWSTR)pValue->pbData)[i]; - if (((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1) + if (!(dwStrType & CERT_NAME_STR_NO_QUOTING_FLAG) && + ((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1) *(++ptr) = '"'; } if (needsQuotes && ptr - psz < csz) @@ -323,8 +331,7 @@ static const WCHAR indent[] = L" "; DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, const CERT_NAME_BLOB *pName, DWORD dwStrType, LPWSTR psz, DWORD csz) { - static const DWORD unsupportedFlags = CERT_NAME_STR_NO_QUOTING_FLAG | - CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG; + static const DWORD unsupportedFlags = CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG; DWORD ret = 0, bytes = 0; BOOL bRet; CERT_NAME_INFO *info; @@ -414,7 +421,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, } if (psz && ret + 1 == csz) break;
- chars = quote_rdn_value_to_str_w(rdn->rgRDNAttr[j].dwValueType, &rdn->rgRDNAttr[j].Value, + chars = quote_rdn_value_to_str_w(rdn->rgRDNAttr[j].dwValueType, &rdn->rgRDNAttr[j].Value, dwStrType, psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0); ret += chars; if (j < rdn->cRDNAttr - 1) diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index 58a4e971f15..8510fed00ec 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -1157,7 +1157,6 @@ static void test_quoted_RDN(void) ret = CertNameToStrA(X509_ASN_ENCODING, &blob, CERT_X500_NAME_STR | CERT_NAME_STR_NO_QUOTING_FLAG, str, sizeof(str)); ok(ret, "CertNameToStr error %08lx\n", GetLastError()); ok(!strncmp(str, "CN=", 3), "got %s\n", str); - todo_wine_if(i != 0) ok(!strcmp(&str[3], test[i].CN), "got %s, expected %s\n", &str[3], test[i].CN);
LocalFree(buf); @@ -1214,7 +1213,6 @@ static void test_quoted_RDN(void) ret = CertNameToStrA(X509_ASN_ENCODING, &blob, CERT_X500_NAME_STR | CERT_NAME_STR_NO_QUOTING_FLAG, str, sizeof(str)); ok(ret, "CertNameToStr error %08lx\n", GetLastError()); ok(!strncmp(str, "CN=", 3), "got %s\n", str); - todo_wine_if(i != 0) ok(!strcmp(&str[3], test[i].CN), "got %s, expected %s\n", &str[3], test[i].CN);
LocalFree(buf);