crypt32(8/20): Add tests for opening non-detached signed messages, and clarify detached open

Juan Lang juan.lang at gmail.com
Mon Jul 23 20:28:57 CDT 2007


--Juan
-------------- next part --------------
From 2167b671ca026764bf7c3a14dbd668eee88fd4ba Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Mon, 23 Jul 2007 17:34:14 -0700
Subject: [PATCH] Add tests for opening non-detached signed messages, and clarify detached open
---
 dlls/crypt32/tests/msg.c |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 94864c1..44c3098 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -1110,10 +1110,10 @@ static void test_signed_msg_update(void)
     msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING,
      CMSG_DETACHED_FLAG, CMSG_SIGNED, &signInfo, NULL, NULL);
     ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
-    /* CMSG_SIGNED allows non-final updates. */
+    /* Detached CMSG_SIGNED allows non-final updates. */
     ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
     ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
-    /* CMSG_SIGNED also allows non-final updates with no data. */
+    /* Detached CMSG_SIGNED also allows non-final updates with no data. */
     ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
     ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
     /* The final update requires a private key in the hCryptProv, in order to
@@ -1139,10 +1139,10 @@ static void test_signed_msg_update(void)
     msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING,
      CMSG_DETACHED_FLAG, CMSG_SIGNED, &signInfo, NULL, NULL);
     ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
-    /* CMSG_SIGNED allows non-final updates. */
+    /* Detached CMSG_SIGNED allows non-final updates. */
     ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
     ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
-    /* CMSG_SIGNED also allows non-final updates with no data. */
+    /* Detached CMSG_SIGNED also allows non-final updates with no data. */
     ret = CryptMsgUpdate(msg, NULL, 0, FALSE);
     ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError());
     /* Now that the private key exists, the final update can succeed (even
@@ -1161,6 +1161,26 @@ static void test_signed_msg_update(void)
      "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
     CryptMsgClose(msg);
 
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, &signInfo,
+     NULL, NULL);
+    ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
+    /* Non-detached messages don't allow non-final updates.. */
+    SetLastError(0xdeadbeef);
+    ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE);
+    ok(!ret && GetLastError() == CRYPT_E_MSG_ERROR,
+     "Expected CRYPT_E_MSG_ERROR, got %x\n", GetLastError());
+    /* but they do allow final ones. */
+    ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE);
+    ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
+    CryptMsgClose(msg);
+    msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, &signInfo,
+     NULL, NULL);
+    ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError());
+    /* They also allow final updates with no data. */
+    ret = CryptMsgUpdate(msg, NULL, 0, TRUE);
+    ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
+    CryptMsgClose(msg);
+
     CryptDestroyKey(key);
     CryptReleaseContext(signer.hCryptProv, 0);
     CryptAcquireContextW(&signer.hCryptProv, cspNameW, NULL, PROV_RSA_FULL,
-- 
1.4.1


More information about the wine-patches mailing list