Juan Lang : crypt32: Add tests for getting hash message params.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 13 08:30:23 CDT 2007


Module: wine
Branch: master
Commit: 1745d8a7285a9555ef3617c96fadc8b4c8dadb25
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1745d8a7285a9555ef3617c96fadc8b4c8dadb25

Author: Juan Lang <juan.lang at gmail.com>
Date:   Thu Jul 12 14:42:46 2007 -0700

crypt32: Add tests for getting hash message params.

---

 dlls/crypt32/tests/msg.c |  143 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 354852b..7f03516 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -747,10 +747,153 @@ static void test_hash_msg_update(void)
     CryptMsgClose(msg);
 }
 
+static const BYTE emptyHashParam[] = {
+0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,
+0x7e };
+
+static void test_hash_msg_get_param(void)
+{
+    HCRYPTMSG msg;
+    BOOL ret;
+    static char oid_rsa_md5[] = szOID_RSA_MD5;
+    CMSG_HASHED_ENCODE_INFO hashInfo = { sizeof(hashInfo), 0,
+     { oid_rsa_md5, { 0, NULL } }, NULL };
+    DWORD size, value;
+    CMSG_STREAM_INFO streamInfo = { 0, nop_stream_output, NULL };
+    BYTE buf[16];
+
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, &hashInfo,
+     NULL, NULL);
+    /* Content and bare content are always gettable for non-streamed messages */
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_BARE_CONTENT_PARAM, 0, NULL, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    /* The hash is also available. */
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+
+    CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    /* Oddly, the hash doesn't seem to change even after an update */
+    ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    /* So is the version. */
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_VERSION_PARAM, 0, NULL, &size);
+    todo_wine
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    size = sizeof(value);
+    ret = CryptMsgGetParam(msg, CMSG_VERSION_PARAM, 0, (LPBYTE)&value, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(value == 0, "Expected version 0, got %d\n", value);
+    }
+    /* As usual, the type isn't available. */
+    ret = CryptMsgGetParam(msg, CMSG_TYPE_PARAM, 0, NULL, &size);
+    todo_wine
+    ok(!ret && GetLastError() == CRYPT_E_INVALID_MSG_TYPE,
+     "Expected CRYPT_E_INVALID_MSG_TYPE, got %x\n", GetLastError());
+    CryptMsgClose(msg);
+
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, &hashInfo,
+     NULL, &streamInfo);
+    /* Streamed messages don't allow you to get the content or bare content. */
+    SetLastError(0xdeadbeef);
+    ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(!ret && GetLastError() == E_INVALIDARG,
+     "Expected E_INVALIDARG, got %x\n", GetLastError());
+    SetLastError(0xdeadbeef);
+    ret = CryptMsgGetParam(msg, CMSG_BARE_CONTENT_PARAM, 0, NULL, &size);
+    ok(!ret && GetLastError() == E_INVALIDARG,
+     "Expected E_INVALIDARG, got %x\n", GetLastError());
+    }
+    /* The hash is still available. */
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    /* An empty update has no effect on the hash */
+    CryptMsgUpdate(msg, NULL, 0, FALSE);
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    /* A non-empty update doesn't appear to either? */
+    CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    CryptMsgClose(msg);
+    /* A detached message similarly has a non-updating hash */
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG,
+     CMSG_HASHED, &hashInfo, NULL, NULL);
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    size = 0;
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, NULL, &size);
+    todo_wine {
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    ok(size == sizeof(buf), "Unexpected size %d\n", size);
+    ret = CryptMsgGetParam(msg, CMSG_COMPUTED_HASH_PARAM, 0, buf, &size);
+    ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
+    }
+    if (size == sizeof(buf))
+        ok(!memcmp(buf, emptyHashParam, size), "Unexpected value\n");
+    CryptMsgClose(msg);
+}
+
 static void test_hash_msg(void)
 {
     test_hash_msg_open();
     test_hash_msg_update();
+    test_hash_msg_get_param();
 }
 
 static CRYPT_DATA_BLOB b4 = { 0, NULL };




More information about the wine-cvs mailing list