wintrust: Implement WVTAsn1SpcSpOpusInfoEncode.

This commit is contained in:
Juan Lang 2008-12-09 16:30:47 -08:00 committed by Alexandre Julliard
parent 796bb0734a
commit 9e7c5626b3
2 changed files with 100 additions and 14 deletions

View File

@ -740,15 +740,6 @@ BOOL WINAPI WVTAsn1SpcIndirectDataContentEncode(DWORD dwCertEncodingType,
return ret;
}
BOOL WINAPI WVTAsn1SpcSpOpusInfoEncode(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded,
DWORD *pcbEncoded)
{
FIXME("(0x%08x, %s, %p, %p, %p): stub\n", dwCertEncodingType,
debugstr_a(lpszStructType), pvStructInfo, pbEncoded, pcbEncoded);
return FALSE;
}
static BOOL WINAPI CRYPT_AsnEncodeBMPString(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded,
DWORD *pcbEncoded)
@ -788,6 +779,106 @@ static BOOL WINAPI CRYPT_AsnEncodeBMPString(DWORD dwCertEncodingType,
return ret;
}
struct AsnEncodeTagSwappedItem
{
BYTE tag;
const void *pvStructInfo;
CryptEncodeObjectFunc encodeFunc;
};
/* Sort of a wacky hack, it encodes something using the struct
* AsnEncodeTagSwappedItem's encodeFunc, then replaces the tag byte with the tag
* given in the struct AsnEncodeTagSwappedItem.
*/
static BOOL WINAPI CRYPT_AsnEncodeSwapTag(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded,
DWORD *pcbEncoded)
{
BOOL ret;
const struct AsnEncodeTagSwappedItem *item = pvStructInfo;
ret = item->encodeFunc(dwCertEncodingType, lpszStructType,
item->pvStructInfo, pbEncoded, pcbEncoded);
if (ret && pbEncoded)
*pbEncoded = item->tag;
return ret;
}
BOOL WINAPI WVTAsn1SpcSpOpusInfoEncode(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded,
DWORD *pcbEncoded)
{
BOOL ret = FALSE;
TRACE("(0x%08x, %s, %p, %p, %p)\n", dwCertEncodingType,
debugstr_a(lpszStructType), pvStructInfo, pbEncoded, pcbEncoded);
__TRY
{
const SPC_SP_OPUS_INFO *info = pvStructInfo;
if (info->pMoreInfo &&
info->pMoreInfo->dwLinkChoice != SPC_URL_LINK_CHOICE &&
info->pMoreInfo->dwLinkChoice != SPC_MONIKER_LINK_CHOICE &&
info->pMoreInfo->dwLinkChoice != SPC_FILE_LINK_CHOICE)
SetLastError(E_INVALIDARG);
else if (info->pPublisherInfo &&
info->pPublisherInfo->dwLinkChoice != SPC_URL_LINK_CHOICE &&
info->pPublisherInfo->dwLinkChoice != SPC_MONIKER_LINK_CHOICE &&
info->pPublisherInfo->dwLinkChoice != SPC_FILE_LINK_CHOICE)
SetLastError(E_INVALIDARG);
else
{
struct AsnEncodeSequenceItem items[3] = { { 0 } };
struct AsnConstructedItem constructed[3] = { { 0 } };
struct AsnEncodeTagSwappedItem swapped;
DWORD cItem = 0, cConstructed = 0;
if (info->pwszProgramName)
{
swapped.tag = ASN_CONTEXT;
swapped.pvStructInfo = info->pwszProgramName;
swapped.encodeFunc = CRYPT_AsnEncodeBMPString;
constructed[cConstructed].tag = 0;
constructed[cConstructed].pvStructInfo = &swapped;
constructed[cConstructed].encodeFunc = CRYPT_AsnEncodeSwapTag;
items[cItem].pvStructInfo = &constructed[cConstructed];
items[cItem].encodeFunc = CRYPT_AsnEncodeConstructed;
cConstructed++;
cItem++;
}
if (info->pMoreInfo)
{
constructed[cConstructed].tag = 1;
constructed[cConstructed].pvStructInfo = info->pMoreInfo;
constructed[cConstructed].encodeFunc = WVTAsn1SpcLinkEncode;
items[cItem].pvStructInfo = &constructed[cConstructed];
items[cItem].encodeFunc = CRYPT_AsnEncodeConstructed;
cConstructed++;
cItem++;
}
if (info->pPublisherInfo)
{
constructed[cConstructed].tag = 2;
constructed[cConstructed].pvStructInfo = info->pPublisherInfo;
constructed[cConstructed].encodeFunc = WVTAsn1SpcLinkEncode;
items[cItem].pvStructInfo = &constructed[cConstructed];
items[cItem].encodeFunc = CRYPT_AsnEncodeConstructed;
cConstructed++;
cItem++;
}
ret = CRYPT_AsnEncodeSequence(X509_ASN_ENCODING,
items, cItem, pbEncoded, pcbEncoded);
}
}
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
}
__ENDTRY
return ret;
}
static BOOL CRYPT_AsnEncodeInteger(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded,
DWORD *pcbEncoded)

View File

@ -810,7 +810,6 @@ static void test_encodeSpOpusInfo(void)
memset(&info, 0, sizeof(info));
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{
@ -821,7 +820,6 @@ static void test_encodeSpOpusInfo(void)
info.pwszProgramName = progName;
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{
@ -837,14 +835,12 @@ static void test_encodeSpOpusInfo(void)
SetLastError(0xdeadbeef);
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
moreInfo.dwLinkChoice = SPC_URL_LINK_CHOICE;
moreInfo.pwszUrl = winehq;
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{
@ -858,7 +854,6 @@ static void test_encodeSpOpusInfo(void)
info.pPublisherInfo = &moreInfo;
ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
(LPBYTE)&info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{