crypt32: Add a helper function to copy params.
This commit is contained in:
parent
fef57dad46
commit
a468e6f6c3
@ -242,6 +242,27 @@ static BOOL CDataEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL CRYPT_CopyParam(void *pvData, DWORD *pcbData, const BYTE *src,
|
||||||
|
DWORD len)
|
||||||
|
{
|
||||||
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
|
if (!pvData)
|
||||||
|
*pcbData = len;
|
||||||
|
else if (*pcbData < len)
|
||||||
|
{
|
||||||
|
*pcbData = len;
|
||||||
|
SetLastError(ERROR_MORE_DATA);
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pcbData = len;
|
||||||
|
memcpy(pvData, src, len);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL CDataEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
static BOOL CDataEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
||||||
DWORD dwIndex, void *pvData, DWORD *pcbData)
|
DWORD dwIndex, void *pvData, DWORD *pcbData)
|
||||||
{
|
{
|
||||||
@ -268,22 +289,9 @@ static BOOL CDataEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
|||||||
case CMSG_BARE_CONTENT_PARAM:
|
case CMSG_BARE_CONTENT_PARAM:
|
||||||
if (msg->base.streamed)
|
if (msg->base.streamed)
|
||||||
SetLastError(E_INVALIDARG);
|
SetLastError(E_INVALIDARG);
|
||||||
else if (!pvData)
|
|
||||||
{
|
|
||||||
*pcbData = msg->bare_content_len;
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
else if (*pcbData < msg->bare_content_len)
|
|
||||||
{
|
|
||||||
*pcbData = msg->bare_content_len;
|
|
||||||
SetLastError(ERROR_MORE_DATA);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
ret = CRYPT_CopyParam(pvData, pcbData, msg->bare_content,
|
||||||
*pcbData = msg->bare_content_len;
|
msg->bare_content_len);
|
||||||
memcpy(pvData, msg->bare_content, msg->bare_content_len);
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SetLastError(CRYPT_E_INVALID_MSG_TYPE);
|
SetLastError(CRYPT_E_INVALID_MSG_TYPE);
|
||||||
@ -349,22 +357,13 @@ static BOOL CHashEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
|||||||
case CMSG_VERSION_PARAM:
|
case CMSG_VERSION_PARAM:
|
||||||
if (!msg->base.finalized)
|
if (!msg->base.finalized)
|
||||||
SetLastError(CRYPT_E_MSG_ERROR);
|
SetLastError(CRYPT_E_MSG_ERROR);
|
||||||
else if (!pvData)
|
|
||||||
{
|
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
else if (*pcbData < sizeof(DWORD))
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_MORE_DATA);
|
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* FIXME: under what circumstances is this CMSG_HASHED_DATA_V2? */
|
/* FIXME: under what circumstances is this CMSG_HASHED_DATA_V2? */
|
||||||
*(DWORD *)pvData = CMSG_HASHED_DATA_PKCS_1_5_VERSION;
|
DWORD version = CMSG_HASHED_DATA_PKCS_1_5_VERSION;
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
ret = TRUE;
|
ret = CRYPT_CopyParam(pvData, pcbData, (const BYTE *)&version,
|
||||||
|
sizeof(version));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -552,22 +551,8 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
|
|||||||
switch (dwParamType)
|
switch (dwParamType)
|
||||||
{
|
{
|
||||||
case CMSG_TYPE_PARAM:
|
case CMSG_TYPE_PARAM:
|
||||||
if (!pvData)
|
ret = CRYPT_CopyParam(pvData, pcbData, (const BYTE *)&msg->type,
|
||||||
{
|
sizeof(msg->type));
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
else if (*pcbData < sizeof(DWORD))
|
|
||||||
{
|
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
SetLastError(ERROR_MORE_DATA);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*pcbData = sizeof(DWORD);
|
|
||||||
*(DWORD *)pvData = msg->type;
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FIXME("unimplemented for parameter %d\n", dwParamType);
|
FIXME("unimplemented for parameter %d\n", dwParamType);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user