Commit 1c837f16 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Add basic parameter checking to CryptMsgOpenTo*.

parent 3de0e4ac
......@@ -24,13 +24,52 @@
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
static inline const char *MSG_TYPE_STR(DWORD type)
{
switch (type)
{
#define _x(x) case (x): return #x
_x(CMSG_DATA);
_x(CMSG_SIGNED);
_x(CMSG_ENVELOPED);
_x(CMSG_SIGNED_AND_ENVELOPED);
_x(CMSG_HASHED);
_x(CMSG_ENCRYPTED);
#undef _x
default:
return wine_dbg_sprintf("unknown (%d)", type);
}
}
HCRYPTMSG WINAPI CryptMsgOpenToEncode(DWORD dwMsgEncodingType, DWORD dwFlags,
DWORD dwMsgType, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID,
PCMSG_STREAM_INFO pStreamInfo)
{
FIXME("(%08x, %08x, %08x, %p, %s, %p): stub\n", dwMsgEncodingType, dwFlags,
HCRYPTMSG msg = NULL;
TRACE("(%08x, %08x, %08x, %p, %s, %p)\n", dwMsgEncodingType, dwFlags,
dwMsgType, pvMsgEncodeInfo, debugstr_a(pszInnerContentObjID), pStreamInfo);
return NULL;
if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING)
{
SetLastError(E_INVALIDARG);
return NULL;
}
switch (dwMsgType)
{
case CMSG_DATA:
case CMSG_SIGNED:
case CMSG_ENVELOPED:
case CMSG_HASHED:
FIXME("unimplemented for type %s\n", MSG_TYPE_STR(dwMsgType));
break;
case CMSG_SIGNED_AND_ENVELOPED:
case CMSG_ENCRYPTED:
/* defined but invalid, fall through */
default:
SetLastError(CRYPT_E_INVALID_MSG_TYPE);
}
return msg;
}
HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags,
......@@ -39,6 +78,12 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags,
{
FIXME("(%08x, %08x, %08x, %08lx, %p, %p): stub\n", dwMsgEncodingType,
dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo);
if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING)
{
SetLastError(E_INVALIDARG);
return NULL;
}
return NULL;
}
......
......@@ -43,19 +43,16 @@ static void test_msg_open_to_encode(void)
/* Bad encodings */
SetLastError(0xdeadbeef);
msg = CryptMsgOpenToEncode(0, 0, 0, NULL, NULL, NULL);
todo_wine {
ok(!msg && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %x\n", GetLastError());
SetLastError(0xdeadbeef);
msg = CryptMsgOpenToEncode(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL);
ok(!msg && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %x\n", GetLastError());
}
/* Bad message types */
SetLastError(0xdeadbeef);
msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, 0, NULL, NULL, NULL);
todo_wine {
ok(!msg && GetLastError() == CRYPT_E_INVALID_MSG_TYPE,
"Expected CRYPT_E_INVALID_MSG_TYPE, got %x\n", GetLastError());
SetLastError(0xdeadbeef);
......@@ -73,7 +70,6 @@ static void test_msg_open_to_encode(void)
NULL, NULL);
ok(!msg && GetLastError() == CRYPT_E_INVALID_MSG_TYPE,
"Expected CRYPT_E_INVALID_MSG_TYPE, got %x\n", GetLastError());
}
}
static void test_msg_open_to_decode(void)
......@@ -83,13 +79,11 @@ static void test_msg_open_to_decode(void)
SetLastError(0xdeadbeef);
msg = CryptMsgOpenToDecode(0, 0, 0, 0, NULL, NULL);
todo_wine
ok(!msg && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %x\n", GetLastError());
/* Bad encodings */
SetLastError(0xdeadbeef);
todo_wine {
msg = CryptMsgOpenToDecode(X509_ASN_ENCODING, 0, 0, 0, NULL, NULL);
ok(!msg && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %x\n", GetLastError());
......@@ -97,7 +91,6 @@ static void test_msg_open_to_decode(void)
msg = CryptMsgOpenToDecode(X509_ASN_ENCODING, 0, CMSG_DATA, 0, NULL, NULL);
ok(!msg && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %x\n", GetLastError());
}
/* The message type can be explicit... */
msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_DATA, 0, NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment