ntdll: Use the NLS case mapping table for RtlHashUnicodeString().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-03-26 11:26:13 +01:00
parent f66517b5a2
commit 9bbb66fdf7
3 changed files with 46 additions and 33 deletions

View file

@ -1288,6 +1288,40 @@ BOOLEAN WINAPI RtlPrefixUnicodeString( const UNICODE_STRING *s1, const UNICODE_S
}
/******************************************************************************
* RtlHashUnicodeString (NTDLL.@)
*/
NTSTATUS WINAPI RtlHashUnicodeString( const UNICODE_STRING *string, BOOLEAN case_insensitive,
ULONG alg, ULONG *hash )
{
unsigned int i;
if (!string || !hash) return STATUS_INVALID_PARAMETER;
switch (alg)
{
case HASH_STRING_ALGORITHM_DEFAULT:
case HASH_STRING_ALGORITHM_X65599:
break;
default:
return STATUS_INVALID_PARAMETER;
}
*hash = 0;
if (!case_insensitive)
for (i = 0; i < string->Length / sizeof(WCHAR); i++)
*hash = *hash * 65599 + string->Buffer[i];
else if (nls_info.UpperCaseTable)
for (i = 0; i < string->Length / sizeof(WCHAR); i++)
*hash = *hash * 65599 + casemap( nls_info.UpperCaseTable, string->Buffer[i] );
else /* locale not setup yet */
for (i = 0; i < string->Length / sizeof(WCHAR); i++)
*hash = *hash * 65599 + casemap_ascii( string->Buffer[i] );
return STATUS_SUCCESS;
}
/**************************************************************************
* RtlCustomCPToUnicodeN (NTDLL.@)
*/

View file

@ -1708,28 +1708,3 @@ NTSTATUS WINAPI RtlStringFromGUID(const GUID* guid, UNICODE_STRING *str)
return STATUS_SUCCESS;
}
/******************************************************************************
* RtlHashUnicodeString [NTDLL.@]
*/
NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING string, BOOLEAN case_insensitive, ULONG alg, ULONG *hash)
{
unsigned int i;
if (!string || !hash) return STATUS_INVALID_PARAMETER;
switch (alg)
{
case HASH_STRING_ALGORITHM_DEFAULT:
case HASH_STRING_ALGORITHM_X65599:
break;
default:
return STATUS_INVALID_PARAMETER;
}
*hash = 0;
for (i = 0; i < string->Length/sizeof(WCHAR); i++)
*hash = *hash*65599 + (case_insensitive ? toupperW(string->Buffer[i]) : string->Buffer[i]);
return STATUS_SUCCESS;
}

View file

@ -1942,14 +1942,18 @@ struct hash_unicodestring_test {
};
static const struct hash_unicodestring_test hash_test[] = {
{ {'T',0}, FALSE, 0x00000054 },
{ {'T','e','s','t',0}, FALSE, 0x766bb952 },
{ {'T','e','S','t',0}, FALSE, 0x764bb172 },
{ {'t','e','s','t',0}, FALSE, 0x4745d132 },
{ {'t','e','s','t',0}, TRUE, 0x6689c132 },
{ {'T','E','S','T',0}, TRUE, 0x6689c132 },
{ {'T','E','S','T',0}, FALSE, 0x6689c132 },
{ {'a','b','c','d','e','f',0}, FALSE, 0x971318c3 },
{ L"T", FALSE, 0x00000054 },
{ L"Test", FALSE, 0x766bb952 },
{ L"TeSt", FALSE, 0x764bb172 },
{ L"test", FALSE, 0x4745d132 },
{ L"test", TRUE, 0x6689c132 },
{ L"TEST", TRUE, 0x6689c132 },
{ L"TEST", FALSE, 0x6689c132 },
{ L"t\xe9st", FALSE, 0x8845cfb6 },
{ L"t\xe9st", TRUE, 0xa789bfb6 },
{ L"T\xc9ST", TRUE, 0xa789bfb6 },
{ L"T\xc9ST", FALSE, 0xa789bfb6 },
{ L"abcdef", FALSE, 0x971318c3 },
{ { 0 } }
};