crypt32(20/25): Introduce an algorithm id encoding function that
encodes missing parameters..
Juan Lang
juan.lang at gmail.com
Thu Jul 12 17:24:17 CDT 2007
as NULL, and use it to match native encoding (and simplify PKCS signer tests.)
--Juan
-------------- next part --------------
From f8a58e98fa145d2a30c800172fc8dcfffa0027d1 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Thu, 12 Jul 2007 14:58:08 -0700
Subject: [PATCH] Introduce an algorithm id encoding function that encodes missing parameters as
NULL, and use it to match native encoding (and simplify PKCS signer tests.)
---
dlls/crypt32/encode.c | 37 ++++++++++++++++++++++++---
dlls/crypt32/tests/encode.c | 59 ++++---------------------------------------
2 files changed, 39 insertions(+), 57 deletions(-)
diff --git a/dlls/crypt32/encode.c b/dlls/crypt32/encode.c
index d5427a0..3821d36 100644
--- a/dlls/crypt32/encode.c
+++ b/dlls/crypt32/encode.c
@@ -394,13 +394,41 @@ static BOOL WINAPI CRYPT_AsnEncodeValidi
return ret;
}
-static BOOL WINAPI CRYPT_AsnEncodeAlgorithmId(
+/* Like CRYPT_AsnEncodeAlgorithmId, but encodes parameters as an asn.1 NULL
+ * if they are empty.
+ */
+static BOOL WINAPI CRYPT_AsnEncodeAlgorithmIdWithNullParams(
DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo,
DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded,
DWORD *pcbEncoded)
{
const CRYPT_ALGORITHM_IDENTIFIER *algo =
(const CRYPT_ALGORITHM_IDENTIFIER *)pvStructInfo;
+ static const BYTE asn1Null[] = { ASN_NULL, 0 };
+ static const CRYPT_DATA_BLOB nullBlob = { sizeof(asn1Null),
+ (LPBYTE)asn1Null };
+ BOOL ret;
+ struct AsnEncodeSequenceItem items[2] = {
+ { algo->pszObjId, CRYPT_AsnEncodeOid, 0 },
+ { NULL, CRYPT_CopyEncodedBlob, 0 },
+ };
+
+ if (algo->Parameters.cbData)
+ items[1].pvStructInfo = &algo->Parameters;
+ else
+ items[1].pvStructInfo = &nullBlob;
+ ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items,
+ sizeof(items) / sizeof(items[0]), dwFlags, pEncodePara, pbEncoded,
+ pcbEncoded);
+ return ret;
+}
+
+static BOOL WINAPI CRYPT_AsnEncodeAlgorithmId(DWORD dwCertEncodingType,
+ LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
+ PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
+{
+ const CRYPT_ALGORITHM_IDENTIFIER *algo =
+ (const CRYPT_ALGORITHM_IDENTIFIER *)pvStructInfo;
BOOL ret;
struct AsnEncodeSequenceItem items[] = {
{ algo->pszObjId, CRYPT_AsnEncodeOid, 0 },
@@ -1455,7 +1483,6 @@ static BOOL WINAPI CRYPT_AsnEncodePKCSCo
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items,
cItem, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
}
-
}
__EXCEPT_PAGE_FAULT
{
@@ -3098,8 +3125,10 @@ static BOOL WINAPI CRYPT_AsnEncodePKCSSi
struct AsnEncodeSequenceItem items[7] = {
{ &info->dwVersion, CRYPT_AsnEncodeInt, 0 },
{ &info->Issuer, CRYPT_AsnEncodeIssuerSerialNumber, 0 },
- { &info->HashAlgorithm, CRYPT_AsnEncodeAlgorithmId, 0 },
- { &info->HashEncryptionAlgorithm, CRYPT_AsnEncodeAlgorithmId, 0 },
+ { &info->HashAlgorithm, CRYPT_AsnEncodeAlgorithmIdWithNullParams,
+ 0 },
+ { &info->HashEncryptionAlgorithm,
+ CRYPT_AsnEncodeAlgorithmIdWithNullParams, 0 },
};
DWORD cItem = 4;
diff --git a/dlls/crypt32/tests/encode.c b/dlls/crypt32/tests/encode.c
index c0940d5..52603e5 100644
--- a/dlls/crypt32/tests/encode.c
+++ b/dlls/crypt32/tests/encode.c
@@ -4870,57 +4870,31 @@ static void test_decodePKCSAttributes(DW
static BYTE encodedCommonNameNoNull[] = { 0x30,0x14,0x31,0x12,0x30,0x10,
0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
0x67 };
-/* As with the algorithm ID tests, accept the algorithm ID parameters either as
- * NULL or as nonexistent.
- */
static const BYTE minimalPKCSSigner[] = {
0x30,0x2b,0x02,0x01,0x00,0x30,0x18,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x00 };
-static const BYTE minimalPKCSSignerNoNull[] = {
- 0x30,0x27,0x02,0x01,0x00,0x30,0x18,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
- 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
- 0x00,0x30,0x02,0x06,0x00,0x30,0x02,0x06,0x00,0x04,0x00 };
static const BYTE PKCSSignerWithSerial[] = {
0x30,0x2c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
0x01,0x01,0x30,0x04,0x06,0x00,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
0x00 };
-static const BYTE PKCSSignerWithSerialNoNull[] = {
- 0x30,0x28,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
- 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
- 0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x02,0x06,0x00,0x04,0x00 };
static const BYTE PKCSSignerWithHashAlgo[] = {
0x30,0x2e,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x04,0x06,0x00,0x05,
0x00,0x04,0x00 };
-static const BYTE PKCSSignerWithHashAlgoNoNull[] = {
- 0x30,0x2a,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
- 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
- 0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x02,0x06,0x00,0x04,0x00 };
static const BYTE PKCSSignerWithHashAndEncryptionAlgo[] = {
0x30,0x30,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x06,0x06,0x02,0x2d,
0x06,0x05,0x00,0x04,0x00 };
-static const BYTE PKCSSignerWithHashAndEncryptionAlgoNoNull[] = {
- 0x30,0x2c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
- 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
- 0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x04,0x06,0x02,0x2d,0x06,0x04,
- 0x00 };
static const BYTE PKCSSignerWithHash[] = {
0x30,0x40,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x06,0x06,0x02,0x2d,
0x06,0x05,0x00,0x04,0x10,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
-static const BYTE PKCSSignerWithHashNoNull[] = {
- 0x30,0x3c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
- 0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
- 0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x04,0x06,0x02,0x2d,
- 0x06,0x04,0x10,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
- 0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
static void test_encodePKCSSignerInfo(DWORD dwEncoding)
{
@@ -4952,14 +4926,9 @@ static void test_encodePKCSSignerInfo(DW
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
if (buf)
{
- ok(size == sizeof(minimalPKCSSigner) ||
- size == sizeof(minimalPKCSSignerNoNull), "Unexpected size %d\n",
- size);
+ ok(size == sizeof(minimalPKCSSigner), "Unexpected size %d\n", size);
if (size == sizeof(minimalPKCSSigner))
ok(!memcmp(buf, minimalPKCSSigner, size), "Unexpected value\n");
- else if (size == sizeof(minimalPKCSSignerNoNull))
- ok(!memcmp(buf, minimalPKCSSignerNoNull, size),
- "Unexpected value\n");
else
ok(0, "Unexpected value\n");
LocalFree(buf);
@@ -4978,15 +4947,11 @@ static void test_encodePKCSSignerInfo(DW
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
if (buf)
{
- ok(size == sizeof(PKCSSignerWithSerial) ||
- size == sizeof(PKCSSignerWithSerialNoNull), "Unexpected size %d\n",
+ ok(size == sizeof(PKCSSignerWithSerial), "Unexpected size %d\n",
size);
if (size == sizeof(PKCSSignerWithSerial))
ok(!memcmp(buf, PKCSSignerWithSerial, size),
"Unexpected value\n");
- else if (size == sizeof(PKCSSignerWithSerialNoNull))
- ok(!memcmp(buf, PKCSSignerWithSerialNoNull, size),
- "Unexpected value\n");
else
ok(0, "Unexpected value\n");
LocalFree(buf);
@@ -5004,15 +4969,11 @@ static void test_encodePKCSSignerInfo(DW
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
if (buf)
{
- ok(size == sizeof(PKCSSignerWithHashAlgo) ||
- size == sizeof(PKCSSignerWithHashAlgoNoNull),
- "Unexpected size %d\n", size);
+ ok(size == sizeof(PKCSSignerWithHashAlgo), "Unexpected size %d\n",
+ size);
if (size == sizeof(PKCSSignerWithHashAlgo))
ok(!memcmp(buf, PKCSSignerWithHashAlgo, size),
"Unexpected value\n");
- else if (size == sizeof(PKCSSignerWithHashAlgoNoNull))
- ok(!memcmp(buf, PKCSSignerWithHashAlgoNoNull, size),
- "Unexpected value\n");
else
ok(0, "Unexpected value\n");
LocalFree(buf);
@@ -5030,15 +4991,11 @@ static void test_encodePKCSSignerInfo(DW
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
if (buf)
{
- ok(size == sizeof(PKCSSignerWithHashAndEncryptionAlgo) ||
- size == sizeof(PKCSSignerWithHashAndEncryptionAlgoNoNull),
+ ok(size == sizeof(PKCSSignerWithHashAndEncryptionAlgo),
"Unexpected size %d\n", size);
if (size == sizeof(PKCSSignerWithHashAndEncryptionAlgo))
ok(!memcmp(buf, PKCSSignerWithHashAndEncryptionAlgo, size),
"Unexpected value\n");
- else if (size == sizeof(PKCSSignerWithHashAndEncryptionAlgoNoNull))
- ok(!memcmp(buf, PKCSSignerWithHashAndEncryptionAlgoNoNull,
- size), "Unexpected value\n");
else
ok(0, "Unexpected value\n");
LocalFree(buf);
@@ -5057,15 +5014,11 @@ static void test_encodePKCSSignerInfo(DW
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
if (buf)
{
- ok(size == sizeof(PKCSSignerWithHash) ||
- size == sizeof(PKCSSignerWithHashNoNull), "Unexpected size %d\n",
+ ok(size == sizeof(PKCSSignerWithHash), "Unexpected size %d\n",
size);
if (size == sizeof(PKCSSignerWithHash))
ok(!memcmp(buf, PKCSSignerWithHash, size),
"Unexpected value\n");
- else if (size == sizeof(PKCSSignerWithHashNoNull))
- ok(!memcmp(buf, PKCSSignerWithHashNoNull, size),
- "Unexpected value\n");
else
ok(0, "Unexpected value\n");
LocalFree(buf);
--
1.4.1
More information about the wine-patches
mailing list