crypt32: Add support for encoding PKCS_SMIME_CAPABILITIES.

This commit is contained in:
Juan Lang 2008-08-20 12:11:15 -07:00 committed by Alexandre Julliard
parent 70744f07d1
commit db6c8e23b6
2 changed files with 95 additions and 4 deletions

View File

@ -1404,6 +1404,96 @@ static BOOL WINAPI CRYPT_AsnEncodeUnicodeName(DWORD dwCertEncodingType,
return ret;
}
static BOOL WINAPI CRYPT_AsnEncodeSMIMECapability(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
{
BOOL ret = FALSE;
__TRY
{
const CRYPT_SMIME_CAPABILITY *capability =
(const CRYPT_SMIME_CAPABILITY *)pvStructInfo;
if (!capability->pszObjId)
SetLastError(E_INVALIDARG);
else
{
struct AsnEncodeSequenceItem items[] = {
{ capability->pszObjId, CRYPT_AsnEncodeOid, 0 },
{ &capability->Parameters, CRYPT_CopyEncodedBlob, 0 },
};
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items,
sizeof(items) / sizeof(items[0]), dwFlags, pEncodePara, pbEncoded,
pcbEncoded);
}
}
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
}
__ENDTRY
return ret;
}
static BOOL WINAPI CRYPT_AsnEncodeSMIMECapabilities(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
{
BOOL ret = FALSE;
__TRY
{
DWORD bytesNeeded, dataLen, lenBytes, i;
const CRYPT_SMIME_CAPABILITIES *capabilities =
(const CRYPT_SMIME_CAPABILITIES *)pvStructInfo;
ret = TRUE;
for (i = 0, dataLen = 0; ret && i < capabilities->cCapability; i++)
{
DWORD size;
ret = CRYPT_AsnEncodeSMIMECapability(dwCertEncodingType, NULL,
&capabilities->rgCapability[i], 0, NULL, NULL, &size);
if (ret)
dataLen += size;
}
CRYPT_EncodeLen(dataLen, NULL, &lenBytes);
bytesNeeded = 1 + lenBytes + dataLen;
if (!pbEncoded)
*pcbEncoded = bytesNeeded;
else
{
if ((ret = CRYPT_EncodeEnsureSpace(dwFlags, pEncodePara, pbEncoded,
pcbEncoded, bytesNeeded)))
{
if (dwFlags & CRYPT_ENCODE_ALLOC_FLAG)
pbEncoded = *(BYTE **)pbEncoded;
*pbEncoded++ = ASN_SEQUENCEOF;
CRYPT_EncodeLen(dataLen, pbEncoded, &lenBytes);
pbEncoded += lenBytes;
for (i = 0; i < capabilities->cCapability; i++)
{
DWORD size = dataLen;
ret = CRYPT_AsnEncodeSMIMECapability(dwCertEncodingType,
NULL, &capabilities->rgCapability[i], 0, NULL, pbEncoded,
&size);
pbEncoded += size;
dataLen -= size;
}
}
}
}
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
}
__ENDTRY
return ret;
}
static BOOL WINAPI CRYPT_AsnEncodePKCSAttribute(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
@ -3684,6 +3774,9 @@ static CryptEncodeObjectExFunc CRYPT_GetBuiltinEncoder(DWORD dwCertEncodingType,
case LOWORD(X509_ENHANCED_KEY_USAGE):
encodeFunc = CRYPT_AsnEncodeEnhancedKeyUsage;
break;
case LOWORD(PKCS_SMIME_CAPABILITIES):
encodeFunc = CRYPT_AsnEncodeSMIMECapabilities;
break;
case LOWORD(PKCS_ATTRIBUTES):
encodeFunc = CRYPT_AsnEncodePKCSAttributes;
break;
@ -3705,6 +3798,8 @@ static CryptEncodeObjectExFunc CRYPT_GetBuiltinEncoder(DWORD dwCertEncodingType,
encodeFunc = CRYPT_AsnEncodeExtensions;
else if (!strcmp(lpszStructType, szOID_RSA_signingTime))
encodeFunc = CRYPT_AsnEncodeUtcTime;
else if (!strcmp(lpszStructType, szOID_RSA_SMIMECapabilities))
encodeFunc = CRYPT_AsnEncodeUtcTime;
else if (!strcmp(lpszStructType, szOID_AUTHORITY_KEY_IDENTIFIER))
encodeFunc = CRYPT_AsnEncodeAuthorityKeyId;
else if (!strcmp(lpszStructType, szOID_AUTHORITY_KEY_IDENTIFIER2))

View File

@ -5180,7 +5180,6 @@ static void test_encodePKCSSMimeCapabilities(DWORD dwEncoding)
capabilities.cCapability = 0;
ret = CryptEncodeObjectEx(dwEncoding, PKCS_SMIME_CAPABILITIES,
&capabilities, CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (buf)
{
@ -5198,13 +5197,11 @@ static void test_encodePKCSSMimeCapabilities(DWORD dwEncoding)
SetLastError(0xdeadbeef);
ret = CryptEncodeObjectEx(dwEncoding, PKCS_SMIME_CAPABILITIES,
&capabilities, CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
capability[0].pszObjId = oid1;
ret = CryptEncodeObjectEx(dwEncoding, PKCS_SMIME_CAPABILITIES,
&capabilities, CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (buf)
{
@ -5217,7 +5214,6 @@ static void test_encodePKCSSMimeCapabilities(DWORD dwEncoding)
capabilities.cCapability = 2;
ret = CryptEncodeObjectEx(dwEncoding, PKCS_SMIME_CAPABILITIES,
&capabilities, CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptEncodeObjectEx failed: %08x\n", GetLastError());
if (buf)
{