--- trunk/reactos/lib/crypt32/encode.c 2005-11-20 15:27:07 UTC (rev 19372)
+++ trunk/reactos/lib/crypt32/encode.c 2005-11-20 15:43:38 UTC (rev 19373)
@@ -31,15 +31,21 @@
* MSDN, especially:
* http://msdn.microsoft.com/library/en-us/seccrypto/security/constants_for_cryptencodeobject_and_cryptdecodeobject.asp
*/
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
-#include "precomp.h"
+#define NONAMELESSUNION
-static _SEH_FILTER(page_fault)
-{
- if (_SEH_GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
- return _SEH_EXECUTE_HANDLER;
- return _SEH_CONTINUE_SEARCH;
-}
+#include "windef.h"
+#include "winbase.h"
+#include "excpt.h"
+#include "wincrypt.h"
+#include "winreg.h"
+#include "snmp.h"
+#include "wine/debug.h"
+#include "wine/exception.h"
/* This is a bit arbitrary, but to set some limit: */
#define MAX_ENCODED_LEN 0x02000000
@@ -47,7 +53,6 @@
/* a few asn.1 tags we need */
#define ASN_BOOL (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x01)
#define ASN_BITSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03)
-//#define ASN_OCTETSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x04)
#define ASN_ENUMERATED (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x0a)
#define ASN_SETOF (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x11)
#define ASN_NUMERICSTRING (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x12)
@@ -168,6 +173,14 @@
DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara,
void *pvStructInfo, DWORD *pcbStructInfo);
+/* filter for page-fault exceptions */
+static WINE_EXCEPTION_FILTER(page_fault)
+{
+ if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
+ return EXCEPTION_EXECUTE_HANDLER;
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID)
{
@@ -716,7 +729,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_PUBLIC_KEY_INFO *info =
(const CERT_PUBLIC_KEY_INFO *)pvStructInfo;
@@ -731,12 +744,12 @@
sizeof(items) / sizeof(items[0]), dwFlags, pEncodePara, pbEncoded,
pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -746,7 +759,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_SIGNED_CONTENT_INFO *info =
(const CERT_SIGNED_CONTENT_INFO *)pvStructInfo;
@@ -762,12 +775,12 @@
sizeof(items) / sizeof(items[0]), dwFlags, pEncodePara, pbEncoded,
pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -781,7 +794,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_INFO *info = (const CERT_INFO *)pvStructInfo;
struct AsnEncodeSequenceItem items[10] = {
@@ -831,12 +844,12 @@
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items, cItem,
dwFlags, pEncodePara, pbEncoded, pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -941,7 +954,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CRL_INFO *info = (const CRL_INFO *)pvStructInfo;
struct AsnEncodeSequenceItem items[7] = {
@@ -975,12 +988,12 @@
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items, cItem,
dwFlags, pEncodePara, pbEncoded, pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1019,7 +1032,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
DWORD bytesNeeded, dataLen, lenBytes, i;
const CERT_EXTENSIONS *exts = (const CERT_EXTENSIONS *)pvStructInfo;
@@ -1059,12 +1072,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1308,7 +1321,7 @@
BOOL ret;
CRYPT_DER_BLOB *blobs = NULL;
- _SEH_TRY
+ __TRY
{
DWORD bytesNeeded = 0, lenBytes, i;
@@ -1376,12 +1389,12 @@
CryptMemFree(blobs[i].pbData);
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
return FALSE;
}
- _SEH_END
+ __ENDTRY
CryptMemFree(blobs);
return ret;
}
@@ -1392,7 +1405,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_NAME_INFO *info = (const CERT_NAME_INFO *)pvStructInfo;
DWORD bytesNeeded = 0, lenBytes, size, i;
@@ -1438,12 +1451,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1490,15 +1503,15 @@
case CERT_ALT_NAME_RFC822_NAME:
case CERT_ALT_NAME_DNS_NAME:
case CERT_ALT_NAME_URL:
- if (entry->pwszURL)
+ if (entry->u.pwszURL)
{
DWORD i;
/* Not + 1: don't encode the NULL-terminator */
- dataLen = lstrlenW(entry->pwszURL);
+ dataLen = lstrlenW(entry->u.pwszURL);
for (i = 0; ret && i < dataLen; i++)
{
- if (entry->pwszURL[i] > 0x7f)
+ if (entry->u.pwszURL[i] > 0x7f)
{
SetLastError(CRYPT_E_INVALID_IA5_STRING);
ret = FALSE;
@@ -1510,7 +1523,7 @@
dataLen = 0;
break;
case CERT_ALT_NAME_IP_ADDRESS:
- dataLen = entry->IPAddress.cbData;
+ dataLen = entry->u.IPAddress.cbData;
break;
case CERT_ALT_NAME_REGISTERED_ID:
/* FIXME: encode OID */
@@ -1550,11 +1563,11 @@
DWORD i;
for (i = 0; i < dataLen; i++)
- *pbEncoded++ = (BYTE)entry->pwszURL[i];
+ *pbEncoded++ = (BYTE)entry->u.pwszURL[i];
break;
}
case CERT_ALT_NAME_IP_ADDRESS:
- memcpy(pbEncoded, entry->IPAddress.pbData, dataLen);
+ memcpy(pbEncoded, entry->u.IPAddress.pbData, dataLen);
break;
}
if (ret)
@@ -1571,7 +1584,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_ALT_NAME_INFO *info =
(const CERT_ALT_NAME_INFO *)pvStructInfo;
@@ -1635,12 +1648,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1650,7 +1663,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CERT_BASIC_CONSTRAINTS2_INFO *info =
(const CERT_BASIC_CONSTRAINTS2_INFO *)pvStructInfo;
@@ -1672,12 +1685,12 @@
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items, cItem,
dwFlags, pEncodePara, pbEncoded, pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1687,7 +1700,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const BLOBHEADER *hdr =
(const BLOBHEADER *)pvStructInfo;
@@ -1713,12 +1726,12 @@
pcbEncoded);
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1728,7 +1741,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CRYPT_DATA_BLOB *blob = (const CRYPT_DATA_BLOB *)pvStructInfo;
DWORD bytesNeeded, lenBytes;
@@ -1758,12 +1771,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
TRACE("returning %d (%08lx)\n", ret, GetLastError());
return ret;
}
@@ -1774,7 +1787,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CRYPT_BIT_BLOB *blob = (const CRYPT_BIT_BLOB *)pvStructInfo;
DWORD bytesNeeded, lenBytes, dataBytes;
@@ -1829,12 +1842,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1844,7 +1857,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
const CRYPT_BIT_BLOB *blob = (const CRYPT_BIT_BLOB *)pvStructInfo;
CRYPT_BIT_BLOB newBlob = { blob->cbData, NULL, blob->cUnusedBits };
@@ -1868,12 +1881,12 @@
&newBlob, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
CryptMemFree(newBlob.pbData);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1893,7 +1906,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
DWORD significantBytes, lenBytes;
BYTE padByte = 0, bytesNeeded;
@@ -1967,12 +1980,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -1982,7 +1995,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
DWORD significantBytes, lenBytes;
BYTE bytesNeeded;
@@ -2038,12 +2051,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2074,7 +2087,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
SYSTEMTIME sysTime;
/* sorry, magic number: enough for tag, len, YYMMDDHHMMSSZ\0. I use a
@@ -2117,12 +2130,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2132,7 +2145,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
SYSTEMTIME sysTime;
/* sorry, magic number: enough for tag, len, YYYYMMDDHHMMSSZ\0. I use a
@@ -2166,12 +2179,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2181,7 +2194,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
SYSTEMTIME sysTime;
@@ -2196,12 +2209,12 @@
lpszStructType, pvStructInfo, dwFlags, pEncodePara, pbEncoded,
pcbEncoded);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2211,7 +2224,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
DWORD bytesNeeded, dataLen, lenBytes, i;
const CRYPT_SEQUENCE_OF_ANY *seq =
@@ -2245,12 +2258,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2823,7 +2836,7 @@
TRACE("%p, %ld, %08lx, %p, %p, %ld\n", pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, *pcbStructInfo);
- _SEH_TRY
+ __TRY
{
struct AsnDecodeSequenceItem items[] = {
{ offsetof(CERT_SIGNED_CONTENT_INFO, ToBeSigned),
@@ -2844,12 +2857,12 @@
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, pcbStructInfo, NULL);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -2935,7 +2948,7 @@
TRACE("%p, %ld, %08lx, %p, %p, %ld\n", pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, *pcbStructInfo);
- _SEH_TRY
+ __TRY
{
struct AsnDecodeSequenceItem items[] = {
{ offsetof(CERT_INFO, dwVersion), CRYPT_AsnDecodeCertVersion,
@@ -2972,12 +2985,12 @@
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, pcbStructInfo, NULL);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -3124,7 +3137,7 @@
TRACE("%p, %ld, %08lx, %p, %p, %ld\n", pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, *pcbStructInfo);
- _SEH_TRY
+ __TRY
{
struct AsnDecodeSequenceItem items[] = {
{ offsetof(CRL_INFO, dwVersion), CRYPT_AsnDecodeCertVersion,
@@ -3152,12 +3165,12 @@
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, pcbStructInfo, NULL);
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
TRACE("Returning %d (%08lx)\n", ret, GetLastError());
return ret;
@@ -3323,7 +3336,7 @@
{
BOOL ret = TRUE;
- _SEH_TRY
+ __TRY
{
ret = CRYPT_AsnDecodeExtensionsInternal(dwCertEncodingType,
lpszStructType, pbEncoded, cbEncoded,
@@ -3348,12 +3361,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -3366,7 +3379,7 @@
TRACE("%p, %ld, %08lx, %p, %ld\n", pbEncoded, cbEncoded, dwFlags, pszObjId,
*pcbObjId);
- _SEH_TRY
+ __TRY
{
if (pbEncoded[0] == ASN_OBJECTIDENTIFIER)
{
@@ -3463,12 +3476,12 @@
ret = FALSE;
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -3481,7 +3494,7 @@
{
BOOL ret = TRUE;
- _SEH_TRY
+ __TRY
{
DWORD dataLen;
@@ -3565,12 +3578,12 @@
}
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
- _SEH_END
+ __ENDTRY
return ret;
}
@@ -3582,7 +3595,7 @@
{
BOOL ret;
- _SEH_TRY
+ __TRY
{
if (pbEncoded[0] == (ASN_CONSTRUCTOR | ASN_SEQUENCE))
{
@@ -3694,12 +3707,12 @@
ret = FALSE;
}
}
- _SEH_EXCEPT(page_fault)
+ __EXCEPT(page_fault)
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
[truncated at 1000 lines; 626 more skipped]