crypt32(4/25): Add tests for updating hash messages opened to encode

Juan Lang juan.lang at gmail.com
Thu Jul 12 17:16:39 CDT 2007


--Juan
-------------- next part --------------
From ae07c8a0ee35bcc04ef9ef73dcc71bc111053183 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Thu, 12 Jul 2007 14:26:47 -0700
Subject: [PATCH] Add tests for updating hash messages opened to encode
---
 dlls/crypt32/tests/msg.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 60bfe0b..f5b2fc5 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -680,9 +680,71 @@ static void test_hash_msg_open(void)
     CryptMsgClose(msg);
 }
 
+static void test_hash_msg_update(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 };
+    CMSG_STREAM_INFO streamInfo = { 0, nop_stream_output, NULL };
+
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, CMSG_DETACHED_FLAG,
+     CMSG_HASHED, &hashInfo, NULL, NULL);
+    /* Detached hashed messages opened in non-streaming mode allow non-final
+     * updates..
+     */
+    ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    todo_wine
+    ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+    /* including non-final updates with no data.. */
+    ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
+    todo_wine
+    ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+    /* and final updates with no data. */
+    ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+    todo_wine
+    ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+    /* But no updates are allowed after the final update. */
+    SetLastError(0xdeadbeef);
+    ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
+    todo_wine
+    ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+     "Expected CRYPT_E_MSG_ERROR, got %x\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 %x\n", GetLastError());
+    CryptMsgClose(msg);
+    /* Non-detached messages, in contrast, don't allow non-final updates in
+     * non-streaming mode.
+     */
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, &hashInfo,
+     NULL, NULL);
+    SetLastError(0xdeadbeef);
+    ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    todo_wine
+    ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+     "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
+    /* Final updates (including empty ones) are allowed. */
+    ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+    todo_wine
+    ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+    CryptMsgClose(msg);
+    /* And, of course, streaming mode allows non-final updates */
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_HASHED, &hashInfo,
+     NULL, &streamInfo);
+    ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    todo_wine
+    ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
+    CryptMsgClose(msg);
+}
+
 static void test_hash_msg(void)
 {
     test_hash_msg_open();
+    test_hash_msg_update();
 }
 
 static CRYPT_DATA_BLOB b4 = { 0, NULL };
-- 
1.4.1


More information about the wine-patches mailing list