crypt32: Add base implementation of CryptFormatObject.
This commit is contained in:
parent
14cb694ff8
commit
ba7705ea95
|
@ -243,13 +243,3 @@ ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
|
|||
FIXME("(%08x): stub\n", x);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
|
||||
DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
|
||||
const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
|
||||
{
|
||||
FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
|
||||
dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
|
||||
debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "wincrypt.h"
|
||||
#include "mssip.h"
|
||||
#include "crypt32_private.h"
|
||||
#include "wine/unicode.h"
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
||||
|
@ -548,3 +549,82 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void *pvObject,
|
|||
TRACE("returning %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_FormatHexString(DWORD dwCertEncodingType,
|
||||
DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct,
|
||||
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat,
|
||||
DWORD *pcbFormat)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD bytesNeeded;
|
||||
|
||||
if (cbEncoded)
|
||||
bytesNeeded = (cbEncoded * 3) * sizeof(WCHAR);
|
||||
else
|
||||
bytesNeeded = sizeof(WCHAR);
|
||||
if (!pbFormat)
|
||||
{
|
||||
*pcbFormat = bytesNeeded;
|
||||
ret = TRUE;
|
||||
}
|
||||
else if (*pcbFormat < bytesNeeded)
|
||||
{
|
||||
*pcbFormat = bytesNeeded;
|
||||
SetLastError(ERROR_MORE_DATA);
|
||||
ret = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
static const WCHAR fmt[] = { '%','0','2','x',' ',0 };
|
||||
static const WCHAR endFmt[] = { '%','0','2','x',0 };
|
||||
DWORD i;
|
||||
LPWSTR ptr = pbFormat;
|
||||
|
||||
*pcbFormat = bytesNeeded;
|
||||
if (cbEncoded)
|
||||
{
|
||||
for (i = 0; i < cbEncoded; i++)
|
||||
{
|
||||
if (i < cbEncoded - 1)
|
||||
ptr += sprintfW(ptr, fmt, pbEncoded[i]);
|
||||
else
|
||||
ptr += sprintfW(ptr, endFmt, pbEncoded[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
*ptr = 0;
|
||||
ret = TRUE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef BOOL (WINAPI *CryptFormatObjectFunc)(DWORD, DWORD, DWORD, void *,
|
||||
LPCSTR, const BYTE *, DWORD, void *, DWORD *);
|
||||
|
||||
BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
|
||||
DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
|
||||
const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
|
||||
{
|
||||
static HCRYPTOIDFUNCSET set = NULL;
|
||||
CryptFormatObjectFunc format = NULL;
|
||||
HCRYPTOIDFUNCADDR hFunc = NULL;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
TRACE("(%08x, %d, %08x, %p, %s, %p, %d, %p, %p)\n", dwCertEncodingType,
|
||||
dwFormatType, dwFormatStrType, pFormatStruct, debugstr_a(lpszStructType),
|
||||
pbEncoded, cbEncoded, pbFormat, pcbFormat);
|
||||
|
||||
if (!set)
|
||||
set = CryptInitOIDFunctionSet(CRYPT_OID_FORMAT_OBJECT_FUNC, 0);
|
||||
CryptGetOIDFunctionAddress(set, dwCertEncodingType, lpszStructType, 0,
|
||||
(void **)&format, &hFunc);
|
||||
if (!format && !(dwFormatStrType & CRYPT_FORMAT_STR_NO_HEX))
|
||||
format = CRYPT_FormatHexString;
|
||||
if (format)
|
||||
ret = format(dwCertEncodingType, dwFormatType, dwFormatStrType,
|
||||
pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat,
|
||||
pcbFormat);
|
||||
if (hFunc)
|
||||
CryptFreeOIDFunctionAddress(hFunc, 0);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -414,7 +414,6 @@ static void test_format_object(void)
|
|||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0,
|
||||
NULL, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
|
@ -435,7 +434,6 @@ static void test_format_object(void)
|
|||
}
|
||||
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt,
|
||||
sizeof(encodedInt), NULL, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
|
@ -448,7 +446,6 @@ static void test_format_object(void)
|
|||
}
|
||||
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL,
|
||||
encodedBigInt, sizeof(encodedBigInt), NULL, &size);
|
||||
todo_wine
|
||||
ok(ret, "CryptFormatObject failed: %d\n", GetLastError());
|
||||
if (ret)
|
||||
{
|
||||
|
@ -466,7 +463,6 @@ static void test_format_object(void)
|
|||
SetLastError(0xdeadbeef);
|
||||
ret = pCryptFormatObject(X509_ASN_ENCODING, 0, CRYPT_FORMAT_STR_NO_HEX,
|
||||
NULL, NULL, NULL, 0, NULL, &size);
|
||||
todo_wine
|
||||
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
|
||||
"expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
||||
/* When called to format an AUTHORITY_KEY_ID2_INFO, it fails when no
|
||||
|
|
Loading…
Reference in New Issue