Alexander Morozov : crypt32: Implement updating enveloped messages.
Alexandre Julliard
julliard at winehq.org
Thu Dec 2 12:23:58 CST 2010
Module: wine
Branch: master
Commit: 03e94320c21cabf503a2eae2175d6a1989aebdcc
URL: http://source.winehq.org/git/wine.git/?a=commit;h=03e94320c21cabf503a2eae2175d6a1989aebdcc
Author: Alexander Morozov <amorozov at etersoft.ru>
Date: Wed Dec 1 14:36:02 2010 +0300
crypt32: Implement updating enveloped messages.
---
dlls/crypt32/msg.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-
dlls/crypt32/tests/msg.c | 14 ----------
2 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index 1ca4d0e..2b93a5b 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -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,
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index fb7a7c2..9ffae52 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -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());
More information about the wine-cvs
mailing list