crypt32: Add CRYPT_STRING_BINARY mode for CryptBinaryToStringW().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
78af6e341f
commit
71f3a22519
|
@ -88,8 +88,7 @@ static BOOL EncodeBinaryToBinaryA(const BYTE *pbBinary,
|
||||||
memcpy(pszString, pbBinary, cbBinary);
|
memcpy(pszString, pbBinary, cbBinary);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
*pcchString = cbBinary;
|
||||||
*pcchString = cbBinary;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -294,6 +293,26 @@ BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary,
|
||||||
return encoder(pbBinary, cbBinary, dwFlags, pszString, pcchString);
|
return encoder(pbBinary, cbBinary, dwFlags, pszString, pcchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL EncodeBinaryToBinaryW(const BYTE *in_buf, DWORD in_len, DWORD flags, WCHAR *out_buf, DWORD *out_len)
|
||||||
|
{
|
||||||
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
|
if (out_buf)
|
||||||
|
{
|
||||||
|
if (*out_len < in_len)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
else if (in_len)
|
||||||
|
memcpy(out_buf, in_buf, in_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*out_len = in_len;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
|
||||||
WCHAR* out_buf, DWORD *out_len)
|
WCHAR* out_buf, DWORD *out_len)
|
||||||
{
|
{
|
||||||
|
@ -472,13 +491,15 @@ BOOL WINAPI CryptBinaryToStringW(const BYTE *pbBinary,
|
||||||
|
|
||||||
switch (dwFlags & 0x0fffffff)
|
switch (dwFlags & 0x0fffffff)
|
||||||
{
|
{
|
||||||
|
case CRYPT_STRING_BINARY:
|
||||||
|
encoder = EncodeBinaryToBinaryW;
|
||||||
|
break;
|
||||||
case CRYPT_STRING_BASE64:
|
case CRYPT_STRING_BASE64:
|
||||||
case CRYPT_STRING_BASE64HEADER:
|
case CRYPT_STRING_BASE64HEADER:
|
||||||
case CRYPT_STRING_BASE64REQUESTHEADER:
|
case CRYPT_STRING_BASE64REQUESTHEADER:
|
||||||
case CRYPT_STRING_BASE64X509CRLHEADER:
|
case CRYPT_STRING_BASE64X509CRLHEADER:
|
||||||
encoder = BinaryToBase64W;
|
encoder = BinaryToBase64W;
|
||||||
break;
|
break;
|
||||||
case CRYPT_STRING_BINARY:
|
|
||||||
case CRYPT_STRING_HEX:
|
case CRYPT_STRING_HEX:
|
||||||
case CRYPT_STRING_HEXASCII:
|
case CRYPT_STRING_HEXASCII:
|
||||||
case CRYPT_STRING_HEXADDR:
|
case CRYPT_STRING_HEXADDR:
|
||||||
|
|
|
@ -284,17 +284,14 @@ static void test_CryptBinaryToString(void)
|
||||||
|
|
||||||
strLen = 0;
|
strLen = 0;
|
||||||
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
|
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
|
||||||
todo_wine {
|
|
||||||
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
|
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
|
||||||
ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
|
ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
|
||||||
}
|
|
||||||
strLen2 = strLen;
|
strLen2 = strLen;
|
||||||
strW = heap_alloc(strLen);
|
strW = heap_alloc(strLen);
|
||||||
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, strW, &strLen2);
|
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, strW, &strLen2);
|
||||||
todo_wine
|
|
||||||
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
|
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
|
||||||
ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
|
ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
|
||||||
todo_wine
|
|
||||||
ok(!memcmp(strW, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
|
ok(!memcmp(strW, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
|
||||||
heap_free(strW);
|
heap_free(strW);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue