crypt32: Implement updating enveloped messages.

This commit is contained in:
Alexander Morozov 2010-12-01 14:36:02 +03:00 committed by Alexandre Julliard
parent c3a2f7a3d1
commit 03e94320c2
2 changed files with 64 additions and 16 deletions

View File

@ -1793,8 +1793,70 @@ static BOOL CEnvelopedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
static BOOL CEnvelopedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
DWORD cbData, BOOL fFinal)
{
FIXME("(%p, %p, %d, %d): stub\n", hCryptMsg, pbData, cbData, fFinal);
return FALSE;
CEnvelopedEncodeMsg *msg = hCryptMsg;
BOOL ret = FALSE;
if (msg->base.state == MsgStateFinalized)
SetLastError(CRYPT_E_MSG_ERROR);
else if (msg->base.streamed)
{
FIXME("streamed stub\n");
msg->base.state = fFinal ? MsgStateFinalized : MsgStateUpdated;
ret = TRUE;
}
else
{
if (!fFinal)
{
if (msg->base.open_flags & CMSG_DETACHED_FLAG)
SetLastError(E_INVALIDARG);
else
SetLastError(CRYPT_E_MSG_ERROR);
}
else
{
if (cbData)
{
DWORD dataLen = cbData;
msg->data.cbData = cbData;
msg->data.pbData = CryptMemAlloc(cbData);
if (msg->data.pbData)
{
memcpy(msg->data.pbData, pbData, cbData);
ret = CryptEncrypt(msg->key, 0, TRUE, 0, msg->data.pbData,
&dataLen, msg->data.cbData);
msg->data.cbData = dataLen;
if (dataLen > cbData)
{
msg->data.pbData = CryptMemRealloc(msg->data.pbData,
dataLen);
if (msg->data.pbData)
{
dataLen = cbData;
ret = CryptEncrypt(msg->key, 0, TRUE, 0,
msg->data.pbData, &dataLen, msg->data.cbData);
}
else
ret = FALSE;
}
if (!ret)
CryptMemFree(msg->data.pbData);
}
else
ret = FALSE;
if (!ret)
{
msg->data.cbData = 0;
msg->data.pbData = NULL;
}
}
else
ret = TRUE;
msg->base.state = MsgStateFinalized;
}
}
return ret;
}
static HCRYPTMSG CEnvelopedEncodeMsg_Open(DWORD dwFlags,

View File

@ -2118,16 +2118,13 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
"expected CRYPT_E_MSG_ERROR, got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
"expected CRYPT_E_MSG_ERROR, got %08x\n", GetLastError());
CryptMsgClose(msg);
@ -2142,18 +2139,15 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
"expected CRYPT_E_MSG_ERROR, got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(ret ||
broken(!ret && GetLastError() == NTE_PERM), /* some NT4 */
"CryptMsgUpdate failed: %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
todo_wine
ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
"expected CRYPT_E_MSG_ERROR, got %08x\n", GetLastError());
CryptMsgClose(msg);
@ -2168,12 +2162,10 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
CryptMsgClose(msg);
}
@ -2187,12 +2179,10 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(ret ||
broken(!ret && GetLastError() == NTE_PERM), /* some NT4 */
"CryptMsgUpdate failed: %08x\n", GetLastError());
@ -2208,11 +2198,9 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
CryptMsgClose(msg);
}
@ -2226,11 +2214,9 @@ static void test_enveloped_msg_update(void)
{
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
todo_wine
ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
SetLastError(0xdeadbeef);
ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
todo_wine
ok(ret ||
broken(!ret && GetLastError() == NTE_PERM), /* some NT4 */
"CryptMsgUpdate failed: %08x\n", GetLastError());