Rearrange Crypt{De|En}codeObjectEx to make error handling more
natural.
This commit is contained in:
parent
8cf6accf23
commit
5af64e4869
|
@ -313,20 +313,14 @@ BOOL WINAPI CryptEncodeObject(DWORD dwCertEncodingType, LPCSTR lpszStructType,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL CRYPT_EncodeInt(DWORD dwCertEncodingType, const void *pvStructInfo,
|
static BOOL WINAPI CRYPT_AsnEncodeInt(DWORD dwCertEncodingType,
|
||||||
DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded,
|
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||||
DWORD *pcbEncoded)
|
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||||
{
|
{
|
||||||
INT val, i;
|
INT val, i;
|
||||||
BYTE significantBytes, padByte = 0, bytesNeeded;
|
BYTE significantBytes, padByte = 0, bytesNeeded;
|
||||||
BOOL neg = FALSE, pad = FALSE;
|
BOOL neg = FALSE, pad = FALSE;
|
||||||
|
|
||||||
if ((dwCertEncodingType & CERT_ENCODING_TYPE_MASK) != X509_ASN_ENCODING &&
|
|
||||||
(dwCertEncodingType & CMSG_ENCODING_TYPE_MASK) != PKCS_7_ASN_ENCODING)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (!pvStructInfo)
|
if (!pvStructInfo)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
@ -403,7 +397,9 @@ BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType,
|
||||||
const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara,
|
const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara,
|
||||||
BYTE *pbEncoded, DWORD *pcbEncoded)
|
BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||||
{
|
{
|
||||||
BOOL ret = FALSE, encoded = FALSE;
|
BOOL ret = FALSE;
|
||||||
|
HMODULE lib = NULL;
|
||||||
|
CryptEncodeObjectExFunc encodeFunc = NULL;
|
||||||
|
|
||||||
TRACE("(0x%08lx, %s, %p, 0x%08lx, %p, %p, %p): semi-stub\n",
|
TRACE("(0x%08lx, %s, %p, 0x%08lx, %p, %p, %p): semi-stub\n",
|
||||||
dwCertEncodingType, HIWORD(lpszStructType) ? debugstr_a(lpszStructType) :
|
dwCertEncodingType, HIWORD(lpszStructType) ? debugstr_a(lpszStructType) :
|
||||||
|
@ -418,30 +414,30 @@ BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType,
|
||||||
|
|
||||||
if (!HIWORD(lpszStructType))
|
if (!HIWORD(lpszStructType))
|
||||||
{
|
{
|
||||||
switch (LOWORD(lpszStructType))
|
if ((dwCertEncodingType & CERT_ENCODING_TYPE_MASK) == X509_ASN_ENCODING
|
||||||
|
|| (dwCertEncodingType & CMSG_ENCODING_TYPE_MASK) ==
|
||||||
|
PKCS_7_ASN_ENCODING)
|
||||||
{
|
{
|
||||||
case (WORD)X509_INTEGER:
|
switch (LOWORD(lpszStructType))
|
||||||
ret = CRYPT_EncodeInt(dwCertEncodingType, pvStructInfo, dwFlags,
|
{
|
||||||
pEncodePara, pbEncoded, pcbEncoded);
|
case (WORD)X509_INTEGER:
|
||||||
break;
|
encodeFunc = CRYPT_AsnEncodeInt;
|
||||||
default:
|
break;
|
||||||
FIXME("%d: unimplemented\n", LOWORD(lpszStructType));
|
default:
|
||||||
|
FIXME("%d: unimplemented\n", LOWORD(lpszStructType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!encoded)
|
if (!encodeFunc)
|
||||||
{
|
encodeFunc = (CryptEncodeObjectExFunc)CRYPT_GetFunc(dwCertEncodingType,
|
||||||
HMODULE lib;
|
|
||||||
CryptEncodeObjectExFunc pCryptEncodeObjectEx =
|
|
||||||
(CryptEncodeObjectExFunc)CRYPT_GetFunc(dwCertEncodingType,
|
|
||||||
lpszStructType, "CryptEncodeObjectEx", &lib);
|
lpszStructType, "CryptEncodeObjectEx", &lib);
|
||||||
|
if (encodeFunc)
|
||||||
if (pCryptEncodeObjectEx)
|
ret = encodeFunc(dwCertEncodingType, lpszStructType, pvStructInfo,
|
||||||
{
|
dwFlags, pEncodePara, pbEncoded, pcbEncoded);
|
||||||
ret = pCryptEncodeObjectEx(dwCertEncodingType, lpszStructType,
|
else
|
||||||
pvStructInfo, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||||
FreeLibrary(lib);
|
if (lib)
|
||||||
}
|
FreeLibrary(lib);
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +489,9 @@ BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType,
|
||||||
const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
||||||
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
||||||
{
|
{
|
||||||
BOOL ret = FALSE, decoded = FALSE;
|
BOOL ret = FALSE;
|
||||||
|
HMODULE lib = NULL;
|
||||||
|
CryptDecodeObjectExFunc decodeFunc = NULL;
|
||||||
|
|
||||||
FIXME("(0x%08lx, %s, %p, %ld, 0x%08lx, %p, %p, %p): stub\n",
|
FIXME("(0x%08lx, %s, %p, %ld, 0x%08lx, %p, %p, %p): stub\n",
|
||||||
dwCertEncodingType, HIWORD(lpszStructType) ? debugstr_a(lpszStructType) :
|
dwCertEncodingType, HIWORD(lpszStructType) ? debugstr_a(lpszStructType) :
|
||||||
|
@ -508,26 +506,26 @@ BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType,
|
||||||
|
|
||||||
if (!HIWORD(lpszStructType))
|
if (!HIWORD(lpszStructType))
|
||||||
{
|
{
|
||||||
switch (LOWORD(lpszStructType))
|
if ((dwCertEncodingType & CERT_ENCODING_TYPE_MASK) == X509_ASN_ENCODING
|
||||||
|
|| (dwCertEncodingType & CMSG_ENCODING_TYPE_MASK) ==
|
||||||
|
PKCS_7_ASN_ENCODING)
|
||||||
{
|
{
|
||||||
default:
|
switch (LOWORD(lpszStructType))
|
||||||
FIXME("%d: unimplemented\n", LOWORD(lpszStructType));
|
{
|
||||||
|
default:
|
||||||
|
FIXME("%d: unimplemented\n", LOWORD(lpszStructType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!decoded)
|
if (!decodeFunc)
|
||||||
{
|
decodeFunc = (CryptDecodeObjectExFunc)CRYPT_GetFunc(dwCertEncodingType,
|
||||||
HMODULE lib;
|
|
||||||
CryptDecodeObjectExFunc pCryptDecodeObjectEx =
|
|
||||||
(CryptDecodeObjectExFunc)CRYPT_GetFunc(dwCertEncodingType,
|
|
||||||
lpszStructType, "CryptDecodeObjectEx", &lib);
|
lpszStructType, "CryptDecodeObjectEx", &lib);
|
||||||
|
if (decodeFunc)
|
||||||
if (pCryptDecodeObjectEx)
|
ret = decodeFunc(dwCertEncodingType, lpszStructType, pbEncoded,
|
||||||
{
|
cbEncoded, dwFlags, pDecodePara, pvStructInfo, pcbStructInfo);
|
||||||
ret = pCryptDecodeObjectEx(dwCertEncodingType, lpszStructType,
|
else
|
||||||
pbEncoded, cbEncoded, dwFlags, pDecodePara, pvStructInfo,
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||||
pcbStructInfo);
|
if (lib)
|
||||||
FreeLibrary(lib);
|
FreeLibrary(lib);
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue