crypt32: Add and use a helper function for getting cert properties.

This commit is contained in:
Juan Lang 2007-08-02 12:21:10 -07:00 committed by Alexandre Julliard
parent a2475921b1
commit 90824039ac
1 changed files with 30 additions and 44 deletions

View File

@ -167,6 +167,27 @@ static BOOL CertContext_GetHashProp(void *context, DWORD dwPropId,
return ret; return ret;
} }
static BOOL CertContext_CopyParam(void *pvData, DWORD *pcbData, const void *pb,
DWORD cb)
{
BOOL ret = TRUE;
if (!pvData)
*pcbData = cb;
else if (*pcbData < cb)
{
SetLastError(ERROR_MORE_DATA);
*pcbData = cb;
ret = FALSE;
}
else
{
memcpy(pvData, pb, cb);
*pcbData = cb;
}
return ret;
}
static BOOL WINAPI CertContext_GetProperty(void *context, DWORD dwPropId, static BOOL WINAPI CertContext_GetProperty(void *context, DWORD dwPropId,
void *pvData, DWORD *pcbData) void *pvData, DWORD *pcbData)
{ {
@ -183,21 +204,7 @@ static BOOL WINAPI CertContext_GetProperty(void *context, DWORD dwPropId,
else else
ret = FALSE; ret = FALSE;
if (ret) if (ret)
{ ret = CertContext_CopyParam(pvData, pcbData, blob.pbData, blob.cbData);
if (!pvData)
*pcbData = blob.cbData;
else if (*pcbData < blob.cbData)
{
SetLastError(ERROR_MORE_DATA);
*pcbData = blob.cbData;
ret = FALSE;
}
else
{
memcpy(pvData, blob.pbData, blob.cbData);
*pcbData = blob.cbData;
}
}
else else
{ {
/* Implicit properties */ /* Implicit properties */
@ -283,25 +290,14 @@ BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext,
ret = FALSE; ret = FALSE;
break; break;
case CERT_ACCESS_STATE_PROP_ID: case CERT_ACCESS_STATE_PROP_ID:
if (!pvData) if (pCertContext->hCertStore)
{ ret = CertGetStoreProperty(pCertContext->hCertStore, dwPropId,
*pcbData = sizeof(DWORD); pvData, pcbData);
ret = TRUE;
}
else if (*pcbData < sizeof(DWORD))
{
SetLastError(ERROR_MORE_DATA);
*pcbData = sizeof(DWORD);
ret = FALSE;
}
else else
{ {
if (pCertContext->hCertStore) DWORD state = 0;
ret = CertGetStoreProperty(pCertContext->hCertStore, dwPropId,
pvData, pcbData); ret = CertContext_CopyParam(pvData, pcbData, &state, sizeof(state));
else
*(DWORD *)pvData = 0;
ret = TRUE;
} }
break; break;
case CERT_KEY_IDENTIFIER_PROP_ID: case CERT_KEY_IDENTIFIER_PROP_ID:
@ -318,18 +314,8 @@ BOOL WINAPI CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext,
ret = CertContext_GetProperty((void *)pCertContext, ret = CertContext_GetProperty((void *)pCertContext,
CERT_KEY_CONTEXT_PROP_ID, &keyContext, &size); CERT_KEY_CONTEXT_PROP_ID, &keyContext, &size);
if (ret) if (ret)
{ ret = CertContext_CopyParam(pvData, pcbData, &keyContext.hCryptProv,
if (!pvData) sizeof(keyContext.hCryptProv));
*pcbData = sizeof(HCRYPTPROV);
else if (*pcbData < sizeof(HCRYPTPROV))
{
SetLastError(ERROR_MORE_DATA);
*pcbData = sizeof(HCRYPTPROV);
ret = FALSE;
}
else
*(HCRYPTPROV *)pvData = keyContext.hCryptProv;
}
break; break;
} }
case CERT_KEY_PROV_INFO_PROP_ID: case CERT_KEY_PROV_INFO_PROP_ID: