crypt32: Return bytes decoded from AsnDecodeArray.

This commit is contained in:
Juan Lang 2007-09-17 15:07:58 -07:00 committed by Alexandre Julliard
parent b2f02f3bf7
commit deb07ccb1c
1 changed files with 8 additions and 3 deletions

View File

@ -524,12 +524,13 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
if ((ret = CRYPT_GetLen(pbEncoded, cbEncoded, &dataLen))) if ((ret = CRYPT_GetLen(pbEncoded, cbEncoded, &dataLen)))
{ {
DWORD bytesNeeded, cItems = 0; DWORD bytesNeeded, cItems = 0, decoded;
BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]); BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]);
/* There can be arbitrarily many items, but there is often only one. /* There can be arbitrarily many items, but there is often only one.
*/ */
struct AsnArrayItemSize itemSize = { 0 }, *itemSizes = &itemSize; struct AsnArrayItemSize itemSize = { 0 }, *itemSizes = &itemSize;
decoded = 1 + lenBytes;
bytesNeeded = sizeof(struct GenericArray); bytesNeeded = sizeof(struct GenericArray);
if (dataLen) if (dataLen)
{ {
@ -538,7 +539,7 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
for (ptr = pbEncoded + 1 + lenBytes; ret && for (ptr = pbEncoded + 1 + lenBytes; ret &&
ptr - pbEncoded - 1 - lenBytes < dataLen; ) ptr - pbEncoded - 1 - lenBytes < dataLen; )
{ {
DWORD itemLenBytes, itemDataLen, size = 0; DWORD itemLenBytes, itemDataLen, itemDecoded, size = 0;
itemLenBytes = GET_LEN_BYTES(ptr[1]); itemLenBytes = GET_LEN_BYTES(ptr[1]);
/* Each item decoded may not tolerate extraneous bytes, so /* Each item decoded may not tolerate extraneous bytes, so
@ -549,7 +550,8 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
if (ret) if (ret)
ret = arrayDesc->decodeFunc(ptr, ret = arrayDesc->decodeFunc(ptr,
1 + itemLenBytes + itemDataLen, 1 + itemLenBytes + itemDataLen,
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, &size, NULL); dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, &size,
&itemDecoded);
if (ret) if (ret)
{ {
DWORD nextLen; DWORD nextLen;
@ -568,6 +570,7 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
} }
if (itemSizes) if (itemSizes)
{ {
decoded += itemDecoded;
itemSizes[cItems - 1].encodedLen = 1 + itemLenBytes itemSizes[cItems - 1].encodedLen = 1 + itemLenBytes
+ itemDataLen; + itemDataLen;
itemSizes[cItems - 1].size = size; itemSizes[cItems - 1].size = size;
@ -594,6 +597,8 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
const BYTE *ptr; const BYTE *ptr;
struct GenericArray *array; struct GenericArray *array;
if (pcbDecoded)
*pcbDecoded = decoded;
if (dwFlags & CRYPT_DECODE_ALLOC_FLAG) if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
pvStructInfo = *(BYTE **)pvStructInfo; pvStructInfo = *(BYTE **)pvStructInfo;
array = (struct GenericArray *)pvStructInfo; array = (struct GenericArray *)pvStructInfo;