crypt32: Rewrite CDecodeMsg_Update for better detached data handling.

This commit is contained in:
Juan Lang 2008-08-20 12:03:37 -07:00 committed by Alexandre Julliard
parent d3c8b59e02
commit 0a8d14c2e6
2 changed files with 41 additions and 30 deletions

View File

@ -1491,6 +1491,7 @@ typedef struct _CDecodeMsg
CSignedMsgData signed_data; CSignedMsgData signed_data;
} u; } u;
CRYPT_DATA_BLOB msg_data; CRYPT_DATA_BLOB msg_data;
CRYPT_DATA_BLOB detached_data;
PCONTEXT_PROPERTY_LIST properties; PCONTEXT_PROPERTY_LIST properties;
} CDecodeMsg; } CDecodeMsg;
@ -1515,6 +1516,7 @@ static void CDecodeMsg_Close(HCRYPTMSG hCryptMsg)
break; break;
} }
CryptMemFree(msg->msg_data.pbData); CryptMemFree(msg->msg_data.pbData);
CryptMemFree(msg->detached_data.pbData);
ContextPropertyList_Free(msg->properties); ContextPropertyList_Free(msg->properties);
} }
@ -1763,30 +1765,38 @@ static BOOL CDecodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
{ {
FIXME("(%p, %p, %d, %d): streamed update stub\n", hCryptMsg, pbData, FIXME("(%p, %p, %d, %d): streamed update stub\n", hCryptMsg, pbData,
cbData, fFinal); cbData, fFinal);
if (fFinal) switch (msg->base.state)
{ {
if (msg->base.open_flags & CMSG_DETACHED_FLAG && case MsgStateInit:
msg->base.state != MsgStateDataFinalized) ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
if (fFinal)
{ {
ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData); if (msg->base.open_flags & CMSG_DETACHED_FLAG)
msg->base.state = MsgStateDataFinalized; msg->base.state = MsgStateDataFinalized;
if (ret) else
ret = CDecodeMsg_DecodeContent(msg, &msg->msg_data, msg->base.state = MsgStateFinalized;
msg->type);
} }
else else
{
FIXME("(%p, %p, %d, %d): detached update stub\n", hCryptMsg,
pbData, cbData, fFinal);
ret = TRUE;
msg->base.state = MsgStateFinalized;
}
}
else
{
ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
if (msg->base.state == MsgStateInit)
msg->base.state = MsgStateUpdated; msg->base.state = MsgStateUpdated;
break;
case MsgStateUpdated:
ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
if (fFinal)
{
if (msg->base.open_flags & CMSG_DETACHED_FLAG)
msg->base.state = MsgStateDataFinalized;
else
msg->base.state = MsgStateFinalized;
}
break;
case MsgStateDataFinalized:
ret = CDecodeMsg_CopyData(&msg->detached_data, pbData, cbData);
if (fFinal)
msg->base.state = MsgStateFinalized;
break;
default:
SetLastError(CRYPT_E_MSG_ERROR);
break;
} }
} }
else else
@ -1795,26 +1805,26 @@ static BOOL CDecodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
SetLastError(CRYPT_E_MSG_ERROR); SetLastError(CRYPT_E_MSG_ERROR);
else else
{ {
if (msg->base.state == MsgStateInit) switch (msg->base.state)
{ {
case MsgStateInit:
ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData); ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
if (ret)
ret = CDecodeMsg_DecodeContent(msg, &msg->msg_data,
msg->type);
if (msg->base.open_flags & CMSG_DETACHED_FLAG) if (msg->base.open_flags & CMSG_DETACHED_FLAG)
msg->base.state = MsgStateDataFinalized; msg->base.state = MsgStateDataFinalized;
else else
msg->base.state = MsgStateFinalized; msg->base.state = MsgStateFinalized;
} break;
else if (msg->base.state == MsgStateDataFinalized) case MsgStateDataFinalized:
{ ret = CDecodeMsg_CopyData(&msg->detached_data, pbData, cbData);
FIXME("(%p, %p, %d, %d): detached update stub\n", hCryptMsg,
pbData, cbData, fFinal);
ret = TRUE;
msg->base.state = MsgStateFinalized; msg->base.state = MsgStateFinalized;
break;
default:
SetLastError(CRYPT_E_MSG_ERROR);
} }
} }
} }
if (ret && msg->base.state == MsgStateFinalized)
ret = CDecodeMsg_DecodeContent(msg, &msg->msg_data, msg->type);
return ret; return ret;
} }
@ -2648,6 +2658,8 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags,
memset(&msg->u, 0, sizeof(msg->u)); memset(&msg->u, 0, sizeof(msg->u));
msg->msg_data.cbData = 0; msg->msg_data.cbData = 0;
msg->msg_data.pbData = NULL; msg->msg_data.pbData = NULL;
msg->detached_data.cbData = 0;
msg->detached_data.pbData = NULL;
msg->properties = ContextPropertyList_Create(); msg->properties = ContextPropertyList_Create();
} }
return msg; return msg;

View File

@ -2080,7 +2080,6 @@ static void test_decode_msg_update(void)
msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, &streamInfo); msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, &streamInfo);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG, ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError()); "Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
CryptMsgClose(msg); CryptMsgClose(msg);