Commit 9afaafc0 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Simplify CRYPT_AsnDecodeExtensions.

parent d1f94671
...@@ -85,12 +85,6 @@ static BOOL CRYPT_AsnDecodePubKeyInfoInternal(const BYTE *pbEncoded, ...@@ -85,12 +85,6 @@ static BOOL CRYPT_AsnDecodePubKeyInfoInternal(const BYTE *pbEncoded,
*/ */
static BOOL CRYPT_AsnDecodeExtension(const BYTE *pbEncoded, DWORD cbEncoded, static BOOL CRYPT_AsnDecodeExtension(const BYTE *pbEncoded, DWORD cbEncoded,
DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded); DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded);
/* Like CRYPT_AsnDecodeExtensions, except assumes rgExtension is set ahead of
* time, doesn't do memory allocation, and doesn't do exception handling.
*/
static BOOL CRYPT_AsnDecodeExtensionsInternal(const BYTE *pbEncoded,
DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
DWORD *pcbDecoded);
/* Assumes algo->Parameters.pbData is set ahead of time. */ /* Assumes algo->Parameters.pbData is set ahead of time. */
static BOOL CRYPT_AsnDecodeAlgorithmId(const BYTE *pbEncoded, DWORD cbEncoded, static BOOL CRYPT_AsnDecodeAlgorithmId(const BYTE *pbEncoded, DWORD cbEncoded,
DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded); DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded);
...@@ -1673,51 +1667,47 @@ static BOOL CRYPT_AsnDecodeExtension(const BYTE *pbEncoded, DWORD cbEncoded, ...@@ -1673,51 +1667,47 @@ static BOOL CRYPT_AsnDecodeExtension(const BYTE *pbEncoded, DWORD cbEncoded,
return ret; return ret;
} }
static BOOL CRYPT_AsnDecodeExtensionsInternal(const BYTE *pbEncoded,
DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
DWORD *pcbDecoded)
{
BOOL ret = TRUE;
struct AsnArrayDescriptor arrayDesc = { ASN_SEQUENCEOF,
CRYPT_AsnDecodeExtension, sizeof(CERT_EXTENSION), TRUE,
offsetof(CERT_EXTENSION, pszObjId) };
PCERT_EXTENSIONS exts = pvStructInfo;
TRACE("%p, %d, %08x, %p, %d, %p\n", pbEncoded, cbEncoded, dwFlags,
pvStructInfo, *pcbStructInfo, pcbDecoded);
ret = CRYPT_AsnDecodeArray(&arrayDesc, pbEncoded, cbEncoded, dwFlags,
NULL, pvStructInfo, pcbStructInfo, pcbDecoded,
exts ? exts->rgExtension : NULL);
return ret;
}
static BOOL WINAPI CRYPT_AsnDecodeExtensions(DWORD dwCertEncodingType, static BOOL WINAPI CRYPT_AsnDecodeExtensions(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, LPCSTR lpszStructType, 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 = TRUE; BOOL ret = TRUE;
TRACE("%p, %d, %08x, %p, %d\n", pbEncoded, cbEncoded, dwFlags,
pvStructInfo, pvStructInfo ? *pcbStructInfo : 0);
__TRY __TRY
{ {
ret = CRYPT_AsnDecodeExtensionsInternal(pbEncoded, cbEncoded, struct AsnArrayDescriptor arrayDesc = { ASN_SEQUENCEOF,
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, pcbStructInfo, NULL); CRYPT_AsnDecodeExtension, sizeof(CERT_EXTENSION), TRUE,
if (ret && pvStructInfo) offsetof(CERT_EXTENSION, pszObjId) };
DWORD itemSize;
ret = CRYPT_AsnDecodeArrayNoAlloc(&arrayDesc, pbEncoded, cbEncoded,
NULL, NULL, &itemSize, NULL);
if (ret)
{ {
ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara, pvStructInfo, DWORD bytesNeeded;
pcbStructInfo, *pcbStructInfo);
if (ret) /* CRYPT_AsnDecodeArrayNoAlloc only returns the size of the decoded
* items, so add the size of CERT_EXTENSIONS.
*/
bytesNeeded = sizeof(CERT_EXTENSIONS) + itemSize;
if (!pvStructInfo)
*pcbStructInfo = bytesNeeded;
else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara,
pvStructInfo, pcbStructInfo, bytesNeeded)))
{ {
CERT_EXTENSIONS *exts; CERT_EXTENSIONS *exts;
if (dwFlags & CRYPT_DECODE_ALLOC_FLAG) if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
pvStructInfo = *(BYTE **)pvStructInfo; pvStructInfo = *(BYTE **)pvStructInfo;
exts = pvStructInfo; exts = (CERT_EXTENSIONS *)pvStructInfo;
exts->rgExtension = (CERT_EXTENSION *)((BYTE *)exts + exts->rgExtension = (CERT_EXTENSION *)((BYTE *)exts +
sizeof(CERT_EXTENSIONS)); sizeof(CERT_EXTENSIONS));
ret = CRYPT_AsnDecodeExtensionsInternal(pbEncoded, cbEncoded, ret = CRYPT_AsnDecodeArrayNoAlloc(&arrayDesc, pbEncoded,
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, pvStructInfo, cbEncoded, &exts->cExtension, exts->rgExtension, &itemSize,
pcbStructInfo, NULL); NULL);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment