[CRYPT32_WINETEST] Sync with Wine Staging 3.17. CORE-15127

This commit is contained in:
Amine Khaldi 2018-10-01 12:48:33 +01:00
parent 997d44c915
commit 06fdb3e6ab
10 changed files with 557 additions and 669 deletions

View file

@ -20,11 +20,10 @@
*/
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winerror.h>
#include <windows.h>
#include <wincrypt.h>
#include "wine/heap.h"
#include "wine/test.h"
#define CERT_HEADER "-----BEGIN CERTIFICATE-----\r\n"
@ -56,6 +55,8 @@ static const BYTE toEncode4[] =
"abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
"abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
"abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
static const BYTE toEncode5[] =
"abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHI";
static const struct BinTests tests[] = {
{ toEncode1, sizeof(toEncode1), "AA==\r\n", },
@ -67,6 +68,8 @@ static const struct BinTests tests[] = {
"d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\r\n"
"Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\r\n"
"SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\r\n" },
{ toEncode5, sizeof(toEncode5),
"YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISQA=\r\n" },
};
static const struct BinTests testsNoCR[] = {
@ -79,131 +82,284 @@ static const struct BinTests testsNoCR[] = {
"d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\n"
"Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\n"
"SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\n" },
{ toEncode5, sizeof(toEncode5),
"YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISQA=\n" },
};
static WCHAR *strdupAtoW(const char *str)
{
WCHAR *ret = NULL;
DWORD len;
if (!str) return ret;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
ret = heap_alloc(len * sizeof(WCHAR));
if (ret)
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
return ret;
}
static void encodeAndCompareBase64_A(const BYTE *toEncode, DWORD toEncodeLen,
DWORD format, const char *expected, const char *header, const char *trailer)
{
DWORD strLen = 0;
DWORD strLen, strLen2, required;
const char *ptr;
LPSTR str = NULL;
BOOL ret;
required = strlen(expected) + 1;
if (header)
required += strlen(header);
if (trailer)
required += strlen(trailer);
strLen = 0;
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
str = HeapAlloc(GetProcessHeap(), 0, strLen);
if (str)
{
DWORD strLen2 = strLen;
LPCSTR ptr = str;
ok(strLen == required, "Unexpected required length %u, expected %u.\n", required, strLen);
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, str,
&strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen2 == strLen - 1, "Expected length %d, got %d\n",
strLen - 1, strLen);
if (header)
{
ok(!strncmp(header, ptr, strlen(header)),
"Expected header %s, got %s\n", header, ptr);
ptr += strlen(header);
}
ok(!strncmp(expected, ptr, strlen(expected)),
"Expected %s, got %s\n", expected, ptr);
ptr += strlen(expected);
if (trailer)
ok(!strncmp(trailer, ptr, strlen(trailer)),
"Expected trailer %s, got %s\n", trailer, ptr);
HeapFree(GetProcessHeap(), 0, str);
strLen2 = strLen;
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Unexpected required length.\n");
strLen2 = strLen - 1;
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Unexpected required length.\n");
str = heap_alloc(strLen);
/* Partially filled output buffer. */
strLen2 = strLen - 1;
str[0] = 0x12;
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, str, &strLen2);
todo_wine
ok((!ret && GetLastError() == ERROR_MORE_DATA) || broken(ret) /* XP */, "CryptBinaryToStringA failed %d, error %d.\n",
ret, GetLastError());
ok(strLen2 == strLen || broken(strLen2 == strLen - 1), "Expected length %d, got %d\n", strLen - 1, strLen);
todo_wine {
if (header)
ok(str[0] == header[0], "Unexpected buffer contents %#x.\n", str[0]);
else
ok(str[0] == expected[0], "Unexpected buffer contents %#x.\n", str[0]);
}
strLen2 = strLen;
ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, str, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen2 == strLen - 1, "Expected length %d, got %d\n", strLen - 1, strLen);
ptr = str;
if (header)
{
ok(!strncmp(header, ptr, strlen(header)), "Expected header %s, got %s\n", header, ptr);
ptr += strlen(header);
}
ok(!strncmp(expected, ptr, strlen(expected)), "Expected %s, got %s\n", expected, ptr);
ptr += strlen(expected);
if (trailer)
ok(!strncmp(trailer, ptr, strlen(trailer)), "Expected trailer %s, got %s\n", trailer, ptr);
heap_free(str);
}
static void testBinaryToStringA(void)
static void encode_compare_base64_W(const BYTE *toEncode, DWORD toEncodeLen, DWORD format,
const WCHAR *expected, const char *header, const char *trailer)
{
WCHAR *headerW, *trailerW, required;
DWORD strLen, strLen2;
WCHAR *strW = NULL;
const WCHAR *ptr;
BOOL ret;
required = lstrlenW(expected) + 1;
if (header)
required += strlen(header);
if (trailer)
required += strlen(trailer);
strLen = 0;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == required, "Unexpected required length %u, expected %u.\n", strLen, required);
/* Same call with non-zero length value. */
strLen2 = strLen;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == strLen2, "Unexpected required length.\n");
strLen2 = strLen - 1;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == strLen2, "Unexpected required length.\n");
strLen2 = strLen - 1;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == strLen2, "Unexpected required length.\n");
strW = heap_alloc(strLen * sizeof(WCHAR));
headerW = strdupAtoW(header);
trailerW = strdupAtoW(trailer);
strLen2 = strLen - 1;
strW[0] = 0x1234;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, strW, &strLen2);
todo_wine
ok((!ret && GetLastError() == ERROR_MORE_DATA) || broken(ret) /* XP */, "CryptBinaryToStringW failed, %d, error %d\n",
ret, GetLastError());
if (headerW)
ok(strW[0] == 0x1234, "Unexpected buffer contents %#x.\n", strW[0]);
else
ok(strW[0] == 0x1234 || broken(strW[0] != 0x1234) /* XP */, "Unexpected buffer contents %#x.\n", strW[0]);
strLen2 = strLen;
ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, strW, &strLen2);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen2 == strLen - 1, "Expected length %d, got %d\n", strLen - 1, strLen);
ptr = strW;
if (headerW)
{
ok(!memcmp(headerW, ptr, lstrlenW(headerW)), "Expected header %s, got %s.\n", wine_dbgstr_w(headerW),
wine_dbgstr_w(ptr));
ptr += lstrlenW(headerW);
}
ok(!memcmp(expected, ptr, lstrlenW(expected)), "Expected %s, got %s.\n", wine_dbgstr_w(expected),
wine_dbgstr_w(ptr));
ptr += lstrlenW(expected);
if (trailerW)
ok(!memcmp(trailerW, ptr, lstrlenW(trailerW)), "Expected trailer %s, got %s.\n", wine_dbgstr_w(trailerW),
wine_dbgstr_w(ptr));
heap_free(strW);
heap_free(headerW);
heap_free(trailerW);
}
static void test_CryptBinaryToString(void)
{
DWORD strLen, strLen2, i;
BOOL ret;
DWORD strLen = 0, i;
ret = CryptBinaryToStringA(NULL, 0, 0, NULL, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
strLen = 123;
ret = CryptBinaryToStringA(NULL, 0, 0, NULL, &strLen);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
ok(strLen == 123, "Unexpected length.\n");
if (0)
ret = CryptBinaryToStringW(NULL, 0, 0, NULL, NULL);
strLen = 123;
ret = CryptBinaryToStringW(NULL, 0, 0, NULL, &strLen);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Unexpected error %d\n", GetLastError());
ok(strLen == 123, "Unexpected length.\n");
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
DWORD strLen = 0;
WCHAR *strW, *encodedW;
LPSTR str = NULL;
BOOL ret;
ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BINARY, NULL, &strLen);
strLen = 0;
ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
str = HeapAlloc(GetProcessHeap(), 0, strLen);
if (str)
{
DWORD strLen2 = strLen;
ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BINARY, str, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Expected length %d, got %d\n", strLen,
strLen2);
ok(!memcmp(str, tests[i].toEncode, tests[i].toEncodeLen),
"Unexpected value\n");
HeapFree(GetProcessHeap(), 0, str);
}
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BASE64, tests[i].base64, NULL, NULL);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BASE64HEADER, tests[i].base64, CERT_HEADER,
CERT_TRAILER);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BASE64REQUESTHEADER, tests[i].base64,
CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
CRYPT_STRING_BASE64X509CRLHEADER, tests[i].base64, X509_HEADER,
X509_TRAILER);
strLen2 = strLen;
str = heap_alloc(strLen);
ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, str, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
ok(!memcmp(str, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
heap_free(str);
strLen = 0;
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
strLen2 = strLen;
strW = heap_alloc(strLen);
ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, strW, &strLen2);
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
ok(!memcmp(strW, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
heap_free(strW);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64,
tests[i].base64, NULL, NULL);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64HEADER,
tests[i].base64, CERT_HEADER, CERT_TRAILER);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64REQUESTHEADER,
tests[i].base64, CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64X509CRLHEADER,
tests[i].base64, X509_HEADER, X509_TRAILER);
encodedW = strdupAtoW(tests[i].base64);
encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64, encodedW, NULL, NULL);
encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64HEADER, encodedW,
CERT_HEADER, CERT_TRAILER);
encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64REQUESTHEADER,
encodedW, CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64X509CRLHEADER, encodedW,
X509_HEADER, X509_TRAILER);
heap_free(encodedW);
}
for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
{
DWORD strLen = 0;
LPSTR str = NULL;
WCHAR *encodedW;
BOOL ret;
ret = CryptBinaryToStringA(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen, CRYPT_STRING_BINARY | CRYPT_STRING_NOCR,
NULL, &strLen);
ret = CryptBinaryToStringA(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BINARY | CRYPT_STRING_NOCR, NULL, &strLen);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
str = HeapAlloc(GetProcessHeap(), 0, strLen);
if (str)
{
DWORD strLen2 = strLen;
ret = CryptBinaryToStringA(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen, CRYPT_STRING_BINARY | CRYPT_STRING_NOCR,
str, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Expected length %d, got %d\n", strLen,
strLen2);
ok(!memcmp(str, testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen),
"Unexpected value\n");
HeapFree(GetProcessHeap(), 0, str);
}
encodeAndCompareBase64_A(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR,
testsNoCR[i].base64, NULL, NULL);
encodeAndCompareBase64_A(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64,
CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
encodeAndCompareBase64_A(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR,
testsNoCR[i].base64, CERT_REQUEST_HEADER_NOCR,
CERT_REQUEST_TRAILER_NOCR);
encodeAndCompareBase64_A(testsNoCR[i].toEncode,
testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR,
testsNoCR[i].base64, X509_HEADER_NOCR, X509_TRAILER_NOCR);
strLen2 = strLen;
str = heap_alloc(strLen);
ret = CryptBinaryToStringA(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BINARY | CRYPT_STRING_NOCR, str, &strLen2);
ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
ok(strLen == strLen2, "Expected length %d, got %d\n", strLen, strLen2);
ok(!memcmp(str, testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen), "Unexpected value\n");
heap_free(str);
encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR,
testsNoCR[i].base64, NULL, NULL);
encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, CERT_REQUEST_HEADER_NOCR,
CERT_REQUEST_TRAILER_NOCR);
encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, X509_HEADER_NOCR, X509_TRAILER_NOCR);
encodedW = strdupAtoW(testsNoCR[i].base64);
encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR, encodedW, NULL, NULL);
encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, encodedW, CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR, encodedW, CERT_REQUEST_HEADER_NOCR,
CERT_REQUEST_TRAILER_NOCR);
encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR, encodedW,
X509_HEADER_NOCR, X509_TRAILER_NOCR);
heap_free(encodedW);
}
}
@ -380,7 +536,7 @@ static void testStringToBinaryA(void)
ok(!ret && GetLastError() == ERROR_INVALID_DATA,
"Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
/* Bad strings */
for (i = 0; i < sizeof(badStrings) / sizeof(badStrings[0]); i++)
for (i = 0; i < ARRAY_SIZE(badStrings); i++)
{
bufLen = 0;
ret = CryptStringToBinaryA(badStrings[i].str, 0, badStrings[i].format,
@ -447,7 +603,7 @@ static void testStringToBinaryA(void)
ret, bufLen, buf[0]);
/* Good strings */
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
bufLen = 0;
/* Bogus length--oddly enough, that succeeds, even though it's not
@ -504,7 +660,7 @@ static void testStringToBinaryA(void)
*/
}
/* And again, with no CR--decoding handles this automatically */
for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
{
bufLen = 0;
/* Bogus length--oddly enough, that succeeds, even though it's not
@ -545,6 +701,6 @@ static void testStringToBinaryA(void)
START_TEST(base64)
{
testBinaryToStringA();
test_CryptBinaryToString();
testStringToBinaryA();
}

View file

@ -3177,7 +3177,7 @@ static void testCompareIntegerBlob(void)
DWORD i;
BOOL ret;
for (i = 0; i < sizeof(intBlobs) / sizeof(intBlobs[0]); i++)
for (i = 0; i < ARRAY_SIZE(intBlobs); i++)
{
ret = CertCompareIntegerBlob(&intBlobs[i].blob1, &intBlobs[i].blob2);
ok(ret == intBlobs[i].areEqual,

File diff suppressed because it is too large Load diff

View file

@ -113,7 +113,7 @@ static void test_encodeInt(DWORD dwEncoding)
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
/* encode as normal integer */
ret = pCryptEncodeObjectEx(dwEncoding, X509_INTEGER, &ints[i].val, 0,
@ -155,7 +155,7 @@ static void test_encodeInt(DWORD dwEncoding)
/* encode a couple bigger ints, just to show it's little-endian and leading
* sign bytes are dropped
*/
for (i = 0; i < sizeof(bigInts) / sizeof(bigInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigInts); i++)
{
blob.cbData = strlen((const char*)bigInts[i].val);
blob.pbData = (BYTE *)bigInts[i].val;
@ -178,7 +178,7 @@ static void test_encodeInt(DWORD dwEncoding)
}
}
/* and, encode some uints */
for (i = 0; i < sizeof(bigUInts) / sizeof(bigUInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigUInts); i++)
{
blob.cbData = strlen((const char*)bigUInts[i].val);
blob.pbData = (BYTE*)bigUInts[i].val;
@ -242,7 +242,7 @@ static void test_decodeInt(DWORD dwEncoding)
GetLastError() == OSS_PDU_MISMATCH /* Win9x */ ),
"Expected CRYPT_E_ASN1_BADTAG or OSS_PDU_MISMATCH, got %08x\n",
GetLastError());
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
/* When the output buffer is NULL, this always succeeds */
SetLastError(0xdeadbeef);
@ -264,7 +264,7 @@ static void test_decodeInt(DWORD dwEncoding)
LocalFree(buf);
}
}
for (i = 0; i < sizeof(bigInts) / sizeof(bigInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigInts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_MULTI_BYTE_INTEGER,
bigInts[i].encoded, bigInts[i].encoded[1] + 2, 0, NULL, NULL,
@ -289,7 +289,7 @@ static void test_decodeInt(DWORD dwEncoding)
LocalFree(buf);
}
}
for (i = 0; i < sizeof(bigUInts) / sizeof(bigUInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigUInts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_MULTI_BYTE_UINT,
bigUInts[i].encoded, bigUInts[i].encoded[1] + 2, 0, NULL, NULL,
@ -377,9 +377,9 @@ static void test_encodeEnumerated(DWORD dwEncoding)
{
DWORD i, j;
for (i = 0; i < sizeof(enumeratedTypes) / sizeof(enumeratedTypes[0]); i++)
for (i = 0; i < ARRAY_SIZE(enumeratedTypes); i++)
{
for (j = 0; j < sizeof(enums) / sizeof(enums[0]); j++)
for (j = 0; j < ARRAY_SIZE(enums); j++)
{
BOOL ret;
BYTE *buf = NULL;
@ -410,9 +410,9 @@ static void test_decodeEnumerated(DWORD dwEncoding)
{
DWORD i, j;
for (i = 0; i < sizeof(enumeratedTypes) / sizeof(enumeratedTypes[0]); i++)
for (i = 0; i < ARRAY_SIZE(enumeratedTypes); i++)
{
for (j = 0; j < sizeof(enums) / sizeof(enums[0]); j++)
for (j = 0; j < ARRAY_SIZE(enums); j++)
{
BOOL ret;
DWORD bufSize = sizeof(int);
@ -563,7 +563,7 @@ static void test_encodeFiletime(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(times) / sizeof(times[0]); i++)
for (i = 0; i < ARRAY_SIZE(times); i++)
{
testTimeEncoding(dwEncoding, X509_CHOICE_OF_TIME, &times[i]);
testTimeEncoding(dwEncoding, PKCS_UTC_TIME, &times[i]);
@ -645,19 +645,19 @@ static void test_decodeFiletime(DWORD dwEncoding)
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"Expected ERROR_MORE_DATA, got %d\n", GetLastError());
/* Normal tests */
for (i = 0; i < sizeof(times) / sizeof(times[0]); i++)
for (i = 0; i < ARRAY_SIZE(times); i++)
{
testTimeDecoding(dwEncoding, X509_CHOICE_OF_TIME, &times[i]);
testTimeDecoding(dwEncoding, PKCS_UTC_TIME, &times[i]);
testTimeDecoding(dwEncoding, szOID_RSA_signingTime, &times[i]);
}
for (i = 0; i < sizeof(otherTimes) / sizeof(otherTimes[0]); i++)
for (i = 0; i < ARRAY_SIZE(otherTimes); i++)
{
testTimeDecoding(dwEncoding, X509_CHOICE_OF_TIME, &otherTimes[i]);
testTimeDecoding(dwEncoding, PKCS_UTC_TIME, &otherTimes[i]);
testTimeDecoding(dwEncoding, szOID_RSA_signingTime, &otherTimes[i]);
}
for (i = 0; i < sizeof(bogusTimes) / sizeof(bogusTimes[0]); i++)
for (i = 0; i < ARRAY_SIZE(bogusTimes); i++)
{
size = sizeof(ft1);
ret = pCryptDecodeObjectEx(dwEncoding, X509_CHOICE_OF_TIME,
@ -861,7 +861,7 @@ static void test_encodeName(DWORD dwEncoding)
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Test a more complex name */
rdn.cRDNAttr = sizeof(rdnAttrs) / sizeof(rdnAttrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(rdnAttrs);
rdn.rgRDNAttr = rdnAttrs;
info.cRDN = 1;
info.rgRDN = &rdn;
@ -1139,7 +1139,7 @@ static void test_decodeName(DWORD dwEncoding)
(BYTE *)commonName } },
};
rdn.cRDNAttr = sizeof(attrs) / sizeof(attrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(attrs);
rdn.rgRDNAttr = attrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1157,7 +1157,7 @@ static void test_decodeName(DWORD dwEncoding)
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{
rdn.cRDNAttr = sizeof(decodedRdnAttrs) / sizeof(decodedRdnAttrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(decodedRdnAttrs);
rdn.rgRDNAttr = decodedRdnAttrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1223,7 +1223,7 @@ static void test_decodeUnicodeName(DWORD dwEncoding)
{ lstrlenW(commonNameW) * sizeof(WCHAR), (BYTE *)commonNameW } },
};
rdn.cRDNAttr = sizeof(attrs) / sizeof(attrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(attrs);
rdn.rgRDNAttr = attrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1332,7 +1332,7 @@ static void test_encodeNameValue(DWORD dwEncoding)
"Unexpected encoding\n");
LocalFree(buf);
}
for (i = 0; i < sizeof(nameValues) / sizeof(nameValues[0]); i++)
for (i = 0; i < ARRAY_SIZE(nameValues); i++)
{
ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME_VALUE,
&nameValues[i].value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
@ -1370,7 +1370,7 @@ static void test_decodeNameValue(DWORD dwEncoding)
DWORD bufSize = 0;
BOOL ret;
for (i = 0; i < sizeof(nameValues) / sizeof(nameValues[0]); i++)
for (i = 0; i < ARRAY_SIZE(nameValues); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_NAME_VALUE,
nameValues[i].encoded, nameValues[i].encoded[1] + 2,
@ -1866,7 +1866,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
"Expected CRYPT_E_NOT_CHAR_STRING, got %08x\n", GetLastError());
/* More failure checking */
value.Value.cbData = 0;
for (i = 0; i < sizeof(unicodeErrors) / sizeof(unicodeErrors[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeErrors); i++)
{
value.Value.pbData = (LPBYTE)unicodeErrors[i].str;
value.dwValueType = unicodeErrors[i].valueType;
@ -1881,7 +1881,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
}
/* cbData can be zero if the string is NULL-terminated */
value.Value.cbData = 0;
for (i = 0; i < sizeof(unicodeResults) / sizeof(unicodeResults[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeResults); i++)
{
value.Value.pbData = (LPBYTE)unicodeResults[i].str;
value.dwValueType = unicodeResults[i].valueType;
@ -1903,7 +1903,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
* rather than properly encoding it. Kept separate from the proper results,
* because the encoded forms won't decode to their original strings.
*/
for (i = 0; i < sizeof(unicodeWeirdness) / sizeof(unicodeWeirdness[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeWeirdness); i++)
{
value.Value.pbData = (LPBYTE)unicodeWeirdness[i].str;
value.dwValueType = unicodeWeirdness[i].valueType;
@ -1933,7 +1933,7 @@ static void test_decodeUnicodeNameValue(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(unicodeResults) / sizeof(unicodeResults[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeResults); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -1991,7 +1991,7 @@ static void test_encodeOctets(DWORD dwEncoding)
}
};
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -2065,7 +2065,7 @@ static void test_decodeOctets(DWORD dwEncoding)
}
};
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -2127,7 +2127,7 @@ static void test_encodeBits(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(bits) / sizeof(bits[0]); i++)
for (i = 0; i < ARRAY_SIZE(bits); i++)
{
CRYPT_BIT_BLOB blob;
BOOL ret;
@ -2162,7 +2162,7 @@ static void test_decodeBits(DWORD dwEncoding)
DWORD bufSize = 0;
/* normal cases */
for (i = 0; i < sizeof(bits) / sizeof(bits[0]); i++)
for (i = 0; i < ARRAY_SIZE(bits); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_BITS, bits[i].encoded,
bits[i].encoded[1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL, &buf,
@ -2249,7 +2249,7 @@ static void test_encodeBasicConstraints(DWORD dwEncoding)
BYTE *buf = NULL;
/* First test with the simpler info2 */
for (i = 0; i < sizeof(constraints2) / sizeof(constraints2[0]); i++)
for (i = 0; i < ARRAY_SIZE(constraints2); i++)
{
ret = pCryptEncodeObjectEx(dwEncoding, X509_BASIC_CONSTRAINTS2,
&constraints2[i].info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf,
@ -2312,7 +2312,7 @@ static void test_decodeBasicConstraints(DWORD dwEncoding)
DWORD bufSize = 0;
/* First test with simpler info2 */
for (i = 0; i < sizeof(constraints2) / sizeof(constraints2[0]); i++)
for (i = 0; i < ARRAY_SIZE(constraints2); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_BASIC_CONSTRAINTS2,
constraints2[i].encoded, constraints2[i].encoded[1] + 2,
@ -2494,7 +2494,7 @@ static void test_encodeRsaPublicKey(DWORD dwEncoding)
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Finally, all valid */
hdr->aiKeyAlg = CALG_RSA_KEYX;
for (i = 0; i < sizeof(rsaPubKeys) / sizeof(rsaPubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(rsaPubKeys); i++)
{
memcpy(toEncode + sizeof(BLOBHEADER) + sizeof(RSAPUBKEY),
rsaPubKeys[i].modulus, rsaPubKeys[i].modulusLen);
@ -2540,7 +2540,7 @@ static void test_decodeRsaPublicKey(DWORD dwEncoding)
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Now try success cases */
for (i = 0; i < sizeof(rsaPubKeys) / sizeof(rsaPubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(rsaPubKeys); i++)
{
bufSize = 0;
ret = pCryptDecodeObjectEx(dwEncoding, RSA_CSP_PUBLICKEYBLOB,
@ -2590,7 +2590,7 @@ static const BYTE mixedSequence[] = { 0x30, 0x27, 0x17, 0x0d, 0x30, 0x35, 0x30,
static void test_encodeSequenceOfAny(DWORD dwEncoding)
{
CRYPT_DER_BLOB blobs[sizeof(ints) / sizeof(ints[0])];
CRYPT_DER_BLOB blobs[ARRAY_SIZE(ints)];
CRYPT_SEQUENCE_OF_ANY seq;
DWORD i;
BOOL ret;
@ -2598,12 +2598,12 @@ static void test_encodeSequenceOfAny(DWORD dwEncoding)
DWORD bufSize = 0;
/* Encode a homogeneous sequence */
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
blobs[i].cbData = ints[i].encoded[1] + 2;
blobs[i].pbData = (BYTE *)ints[i].encoded;
}
seq.cValue = sizeof(ints) / sizeof(ints[0]);
seq.cValue = ARRAY_SIZE(ints);
seq.rgValue = blobs;
ret = pCryptEncodeObjectEx(dwEncoding, X509_SEQUENCE_OF_ANY, &seq,
@ -2646,9 +2646,8 @@ static void test_decodeSequenceOfAny(DWORD dwEncoding)
CRYPT_SEQUENCE_OF_ANY *seq = (CRYPT_SEQUENCE_OF_ANY *)buf;
DWORD i;
ok(seq->cValue == sizeof(ints) / sizeof(ints[0]),
"Wrong elements %d\n", seq->cValue);
for (i = 0; i < min(seq->cValue, sizeof(ints) / sizeof(ints[0])); i++)
ok(seq->cValue == ARRAY_SIZE(ints), "Wrong elements %d\n", seq->cValue);
for (i = 0; i < min(seq->cValue, ARRAY_SIZE(ints)); i++)
{
ok(seq->rgValue[i].cbData == ints[i].encoded[1] + 2,
"Expected %d bytes, got %d\n", ints[i].encoded[1] + 2,
@ -2666,8 +2665,7 @@ static void test_decodeSequenceOfAny(DWORD dwEncoding)
{
CRYPT_SEQUENCE_OF_ANY *seq = (CRYPT_SEQUENCE_OF_ANY *)buf;
ok(seq->cValue == sizeof(ints) / sizeof(ints[0]),
"Wrong elements %d\n", seq->cValue);
ok(seq->cValue == ARRAY_SIZE(ints), "Wrong elements %d\n", seq->cValue);
/* Just check the first element since it's all that changed */
ok(seq->rgValue[0].cbData == times[0].encodedTime[1] + 2,
"Expected %d bytes, got %d\n", times[0].encodedTime[1] + 2,
@ -2713,7 +2711,7 @@ static void test_encodeExtensions(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(exts) / sizeof(exts[i]); i++)
for (i = 0; i < ARRAY_SIZE(exts); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2737,7 +2735,7 @@ static void test_decodeExtensions(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(exts) / sizeof(exts[i]); i++)
for (i = 0; i < ARRAY_SIZE(exts); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2851,7 +2849,7 @@ static void test_encodePublicKeyInfo(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(pubKeys) / sizeof(pubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(pubKeys); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2907,7 +2905,7 @@ static void test_decodePublicKeyInfo(DWORD dwEncoding)
BYTE *buf = NULL;
DWORD bufSize = 0;
for (i = 0; i < sizeof(pubKeys) / sizeof(pubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(pubKeys); i++)
{
/* The NULL form decodes to the decoded member */
ret = pCryptDecodeObjectEx(dwEncoding, X509_PUBLIC_KEY_INFO,
@ -3260,7 +3258,7 @@ static void test_decodeCertToBeSigned(DWORD dwEncoding)
* CRYPT_E_ASN1_BADTAG, because at a minimum a cert must have a non-zero
* serial number, an issuer, a subject, and a public key.
*/
for (i = 0; i < sizeof(corruptCerts) / sizeof(corruptCerts[0]); i++)
for (i = 0; i < ARRAY_SIZE(corruptCerts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED,
corruptCerts[i], corruptCerts[i][1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -4688,7 +4686,7 @@ static void test_decodeCRLToBeSigned(DWORD dwEncoding)
BYTE *buf = NULL;
DWORD size = 0, i;
for (i = 0; i < sizeof(corruptCRLs) / sizeof(corruptCRLs[0]); i++)
for (i = 0; i < ARRAY_SIZE(corruptCRLs); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED,
corruptCRLs[i], corruptCRLs[i][1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -4854,7 +4852,7 @@ static void test_encodeEnhancedKeyUsage(DWORD dwEncoding)
LocalFree(buf);
}
/* Test with a few usages */
usage.cUsageIdentifier = sizeof(keyUsages) / sizeof(keyUsages[0]);
usage.cUsageIdentifier = ARRAY_SIZE(keyUsages);
usage.rgpszUsageIdentifier = (LPSTR *)keyUsages;
ret = pCryptEncodeObjectEx(dwEncoding, X509_ENHANCED_KEY_USAGE, &usage,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
@ -4898,8 +4896,8 @@ static void test_decodeEnhancedKeyUsage(DWORD dwEncoding)
ok(size >= sizeof(CERT_ENHKEY_USAGE),
"Wrong size %d\n", size);
ok(usage->cUsageIdentifier == sizeof(keyUsages) / sizeof(keyUsages[0]),
"Wrong CRL entries count %d\n", usage->cUsageIdentifier);
ok(usage->cUsageIdentifier == ARRAY_SIZE(keyUsages),
"Wrong CRL entries count %d\n", usage->cUsageIdentifier);
for (i = 0; i < usage->cUsageIdentifier; i++)
ok(!strcmp(usage->rgpszUsageIdentifier[i], keyUsages[i]),
"Expected OID %s, got %s\n", keyUsages[i],
@ -6109,7 +6107,7 @@ static void test_decodePKCSContentInfo(DWORD dwEncoding)
"1.2.3", content_constructed_abcd + 8, 10 }
};
for (i = 0; i < sizeof(tests)/sizeof(*tests); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, tests[i].encoded,
tests[i].encoded_size, CRYPT_DECODE_ALLOC_FLAG, NULL, &buf, &size);
@ -7397,9 +7395,7 @@ static void test_decodeNameConstraints(DWORD dwEncoding)
U(IPAddressWithMinSubtree.Base).IPAddress.pbData = (LPBYTE)encodedIPAddr;
U(IPAddressWithMinMaxSubtree.Base).IPAddress.cbData = sizeof(encodedIPAddr);
U(IPAddressWithMinMaxSubtree.Base).IPAddress.pbData = (LPBYTE)encodedIPAddr;
for (i = 0;
i < sizeof(encodedNameConstraints) / sizeof(encodedNameConstraints[0]);
i++)
for (i = 0; i < ARRAY_SIZE(encodedNameConstraints); i++)
{
DWORD size;
@ -7749,7 +7745,7 @@ static void test_encodeCertPolicyMappings(DWORD dwEncoding)
DWORD size, i;
/* Each of the mapping OIDs is equivalent, so check with all of them */
for (i = 0; i < sizeof(mappingOids) / sizeof(mappingOids[0]); i++)
for (i = 0; i < ARRAY_SIZE(mappingOids); i++)
{
memset(&info, 0, sizeof(info));
ret = pCryptEncodeObjectEx(dwEncoding, mappingOids[i], &info,
@ -7814,7 +7810,7 @@ static void test_decodeCertPolicyMappings(DWORD dwEncoding)
BOOL ret;
/* Each of the mapping OIDs is equivalent, so check with all of them */
for (i = 0; i < sizeof(mappingOids) / sizeof(mappingOids[0]); i++)
for (i = 0; i < ARRAY_SIZE(mappingOids); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, mappingOids[i],
emptySequence, sizeof(emptySequence), CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -8509,173 +8505,6 @@ static void testPortPublicKeyInfo(void)
ok(ret,"CryptAcquireContextA failed\n");
}
static const BYTE eccCert[] = {
0x30,0x82,0x01,0x46,0x30,0x81,0xec,0x02,0x09,0x00,0xe7,0x6b,
0x26,0x86,0x0a,0x82,0xff,0xe9,0x30,0x0a,0x06,0x08,0x2a,0x86,
0x48,0xce,0x3d,0x04,0x03,0x02,0x30,0x2b,0x31,0x0b,0x30,0x09,
0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x44,0x45,0x31,0x0d,0x30,
0x0b,0x06,0x03,0x55,0x04,0x0a,0x0c,0x04,0x57,0x69,0x6e,0x65,
0x31,0x0d,0x30,0x0b,0x06,0x03,0x55,0x04,0x03,0x0c,0x04,0x57,
0x69,0x6e,0x65,0x30,0x1e,0x17,0x0d,0x31,0x37,0x30,0x39,0x32,
0x37,0x31,0x33,0x34,0x31,0x30,0x34,0x5a,0x17,0x0d,0x32,0x37,
0x30,0x39,0x32,0x35,0x31,0x33,0x34,0x31,0x30,0x34,0x5a,0x30,
0x2b,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,
0x44,0x45,0x31,0x0d,0x30,0x0b,0x06,0x03,0x55,0x04,0x0a,0x0c,
0x04,0x54,0x65,0x73,0x74,0x31,0x0d,0x30,0x0b,0x06,0x03,0x55,
0x04,0x03,0x0c,0x04,0x54,0x65,0x73,0x74,0x30,0x59,0x30,0x13,
0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x08,0x2a,
0x86,0x48,0xce,0x3d,0x03,0x01,0x07,0x03,0x42,0x00,0x04,0xed,
0xfc,0x77,0xd8,0xb9,0xe7,0xf3,0xf8,0xce,0x13,0xb8,0x7f,0x0f,
0x78,0xea,0x73,0x87,0x29,0x10,0xe1,0x6d,0x10,0xce,0x57,0x60,
0x3b,0x3e,0xb4,0x5f,0x0d,0x20,0xc1,0xeb,0x6d,0x74,0xe9,0x7b,
0x11,0x51,0x9a,0x00,0xe8,0xe9,0x12,0x84,0xb9,0x07,0x7e,0x7b,
0x62,0x67,0x12,0x67,0x08,0xe5,0x2e,0x27,0xce,0xa2,0x57,0x15,
0xad,0xc5,0x1f,0x30,0x0a,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,
0x04,0x03,0x02,0x03,0x49,0x00,0x30,0x46,0x02,0x21,0x00,0xd7,
0x29,0xce,0x5a,0xef,0x74,0x85,0xd1,0x18,0x5f,0x6e,0xf1,0xba,
0x53,0xd4,0xcd,0xdd,0xe0,0x5d,0xf1,0x5e,0x48,0x51,0xea,0x63,
0xc0,0xe8,0xe2,0xf6,0xfa,0x4c,0xaf,0x02,0x21,0x00,0xe3,0x94,
0x15,0x3b,0x6c,0x71,0x6e,0x44,0x22,0xcb,0xa0,0x88,0xcd,0x0a,
0x5a,0x50,0x29,0x7c,0x5c,0xd6,0x6c,0xd2,0xe0,0x7f,0xcd,0x02,
0x92,0x21,0x4c,0x2c,0x92,0xee };
static const BYTE ecdsaSig[] = {
0x30,0x46,0x02,0x21,0x00,0xd7,0x29,0xce,0x5a,0xef,0x74,0x85,
0xd1,0x18,0x5f,0x6e,0xf1,0xba,0x53,0xd4,0xcd,0xdd,0xe0,0x5d,
0xf1,0x5e,0x48,0x51,0xea,0x63,0xc0,0xe8,0xe2,0xf6,0xfa,0x4c,
0xaf,0x02,0x21,0x00,0xe3,0x94,0x15,0x3b,0x6c,0x71,0x6e,0x44,
0x22,0xcb,0xa0,0x88,0xcd,0x0a,0x5a,0x50,0x29,0x7c,0x5c,0xd6,
0x6c,0xd2,0xe0,0x7f,0xcd,0x02,0x92,0x21,0x4c,0x2c,0x92,0xee };
static const BYTE eccPubKey[] = {
0x30,0x59,0x30,0x13,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,
0x01,0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,0x01,0x07,0x03,
0x42,0x00,0x04,0xed,0xfc,0x77,0xd8,0xb9,0xe7,0xf3,0xf8,0xce,
0x13,0xb8,0x7f,0x0f,0x78,0xea,0x73,0x87,0x29,0x10,0xe1,0x6d,
0x10,0xce,0x57,0x60,0x3b,0x3e,0xb4,0x5f,0x0d,0x20,0xc1,0xeb,
0x6d,0x74,0xe9,0x7b,0x11,0x51,0x9a,0x00,0xe8,0xe9,0x12,0x84,
0xb9,0x07,0x7e,0x7b,0x62,0x67,0x12,0x67,0x08,0xe5,0x2e,0x27,
0xce,0xa2,0x57,0x15,0xad,0xc5,0x1f };
static void testECDSACert(void)
{
DWORD decode_flags = CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG;
CERT_SIGNED_CONTENT_INFO *info;
CERT_PUBLIC_KEY_INFO *pubkey;
CERT_ECC_SIGNATURE *ecc_sig;
LPSTR *ecc_curve;
DWORD size;
BOOL ret;
int i;
info = NULL;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, X509_CERT, eccCert, sizeof(eccCert), decode_flags,
NULL, &info, &size);
ok(ret, "CryptDecodeObjectEx failed with %d\n", GetLastError());
ok(!strcmp(info->SignatureAlgorithm.pszObjId, szOID_ECDSA_SHA256),
"Expected 1.2.840.10045.4.3.2, got %s\n", info->SignatureAlgorithm.pszObjId);
ok(!info->SignatureAlgorithm.Parameters.cbData,
"Expected no parameter data, got %d bytes\n", info->SignatureAlgorithm.Parameters.cbData);
ok(!info->SignatureAlgorithm.Parameters.pbData,
"Expected no parameter data, got %p pointer\n", info->SignatureAlgorithm.Parameters.pbData);
ok(info->Signature.cbData == sizeof(ecdsaSig),
"Expected %d bytes, got %d\n", (int)sizeof(ecdsaSig), info->Signature.cbData);
ok(info->Signature.pbData != NULL, "Got NULL pointer\n");
ok(!info->Signature.cUnusedBits, "Expected no unused bytes, got %d\n", info->Signature.cUnusedBits);
for (i = 0; i < info->Signature.cbData; i++)
{
ok(ecdsaSig[i] == info->Signature.pbData[i], "Expected %02x, got %02x at offset %d\n",
ecdsaSig[i], info->Signature.pbData[i], i);
}
ecc_sig = NULL;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, X509_ECC_SIGNATURE, info->Signature.pbData,
info->Signature.cbData, decode_flags, NULL, &ecc_sig, &size);
ok(ret, "CryptDecodeObjectEx failed with %d\n", GetLastError());
if (ret)
{
ok(ecc_sig->r.cbData == 32, "Expected 32 bytes, got %d\n", ecc_sig->r.cbData);
ok(ecc_sig->r.pbData != NULL, "Got NULL pointer\n");
ok(ecc_sig->s.cbData == 32, "Expected 32 bytes, got %d\n", ecc_sig->s.cbData);
ok(ecc_sig->s.pbData != NULL, "Got NULL pointer\n");
for (i = 0; i < ecc_sig->r.cbData; i++)
{
ok(ecdsaSig[4+32-i] == ecc_sig->r.pbData[i], "Expected %02x, got %02x at offset %d\n",
ecdsaSig[4+32-i], ecc_sig->r.pbData[i], i);
}
for (i = 0; i < ecc_sig->s.cbData; i++)
{
ok(ecdsaSig[4+35+32-i] == ecc_sig->s.pbData[i], "Expected %02x, got %02x at offset %d\n",
ecdsaSig[4+35+32-i], ecc_sig->s.pbData[i], i);
}
LocalFree(ecc_sig);
}
LocalFree(info);
info = NULL;
decode_flags &= ~CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, X509_CERT, eccCert, sizeof(eccCert), decode_flags,
NULL, &info, &size);
ok(ret, "CryptDecodeObjectEx failed with %d\n", GetLastError());
ok(info->Signature.cbData == sizeof(ecdsaSig),
"Expected %d bytes, got %d\n", (int)sizeof(ecdsaSig), info->Signature.cbData);
ok(info->Signature.pbData != NULL, "Got NULL pointer\n");
ok(!info->Signature.cUnusedBits, "Expected no unused bytes, got %d\n", info->Signature.cUnusedBits);
for (i = 0; i < info->Signature.cbData; i++)
{
ok(ecdsaSig[sizeof(ecdsaSig)-i-1] == info->Signature.pbData[i], "Expected %02x, got %02x at offset %d\n",
ecdsaSig[sizeof(ecdsaSig)-i-1], info->Signature.pbData[i], i);
}
LocalFree(info);
pubkey = NULL;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO, eccPubKey, sizeof(eccPubKey),
decode_flags, NULL, &pubkey, &size);
ok(ret, "CryptDecodeObjectEx failed with %d\n", GetLastError());
ok(!strcmp(pubkey->Algorithm.pszObjId, szOID_ECC_PUBLIC_KEY),
"Expected 1.2.840.10045.2.1, got %s\n", pubkey->Algorithm.pszObjId);
ok(pubkey->Algorithm.Parameters.cbData == 10,
"Expected 10 bytes parameters, got %d bytes\n", pubkey->Algorithm.Parameters.cbData);
ok(pubkey->Algorithm.Parameters.pbData != NULL,
"Expected pointer to parameters, got NULL\n");
ecc_curve = NULL;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, X509_OBJECT_IDENTIFIER, pubkey->Algorithm.Parameters.pbData,
pubkey->Algorithm.Parameters.cbData, decode_flags, NULL, &ecc_curve, &size);
ok(ret || broken(GetLastError() == ERROR_FILE_NOT_FOUND /* < Vista */),
"CryptDecodeObjectEx failed with %d\n", GetLastError());
if (ret)
{
ok(!strcmp(*ecc_curve, szOID_ECC_CURVE_P256), "Expected 1.2.840.10045.3.1.7, got %s\n", *ecc_curve);
LocalFree(ecc_curve);
}
ecc_curve = NULL;
ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, szOID_ECC_PUBLIC_KEY, pubkey->Algorithm.Parameters.pbData,
pubkey->Algorithm.Parameters.cbData, decode_flags, NULL, &ecc_curve, &size);
ok(ret || broken(GetLastError() == ERROR_FILE_NOT_FOUND /* < Vista */),
"CryptDecodeObjectEx failed with %d\n", GetLastError());
if (ret)
{
ok(!strcmp(*ecc_curve, szOID_ECC_CURVE_P256), "Expected 1.2.840.10045.3.1.7, got %s\n", *ecc_curve);
LocalFree(ecc_curve);
}
ok(pubkey->PublicKey.cbData == 65, "Expected 32 bytes parameters, got %d bytes\n", pubkey->PublicKey.cbData);
ok(pubkey->PublicKey.pbData != NULL, "Expected pointer to parameters, got NULL\n");
for (i = 0; i < pubkey->PublicKey.cbData; i++)
{
ok(eccPubKey[26+i] == pubkey->PublicKey.pbData[i], "Expected %02x, got %02x at offset %d\n",
eccPubKey[26+i], pubkey->PublicKey.pbData[i], i);
}
LocalFree(pubkey);
}
START_TEST(encode)
{
static const DWORD encodings[] = { X509_ASN_ENCODING, PKCS_7_ASN_ENCODING,
@ -8692,7 +8521,7 @@ START_TEST(encode)
return;
}
for (i = 0; i < sizeof(encodings) / sizeof(encodings[0]); i++)
for (i = 0; i < ARRAY_SIZE(encodings); i++)
{
test_encodeInt(encodings[i]);
test_decodeInt(encodings[i]);
@ -8769,5 +8598,4 @@ START_TEST(encode)
test_decodeRsaPrivateKey(encodings[i]);
}
testPortPublicKeyInfo();
testECDSACert();
}

View file

@ -36,7 +36,7 @@ static void test_findAttribute(void)
BYTE blobbin[] = {0x02,0x01,0x01};
static CHAR oid[] = "1.2.3";
CRYPT_ATTR_BLOB blobs[] = { { sizeof blobbin, blobbin }, };
CRYPT_ATTRIBUTE attr = { oid, sizeof(blobs) / sizeof(blobs[0]), blobs };
CRYPT_ATTRIBUTE attr = { oid, ARRAY_SIZE(blobs), blobs };
/* returns NULL, last error not set */
SetLastError(0xdeadbeef);
@ -128,10 +128,8 @@ static void test_findRDNAttr(void)
CERT_RDN_ATTR attrs[] = {
{ oid, CERT_RDN_IA5_STRING, { sizeof bin, bin } },
};
CERT_RDN rdns[] = {
{ sizeof(attrs) / sizeof(attrs[0]), attrs },
};
CERT_NAME_INFO nameInfo = { sizeof(rdns) / sizeof(rdns[0]), rdns };
CERT_RDN rdns[] = { { ARRAY_SIZE(attrs), attrs } };
CERT_NAME_INFO nameInfo = { ARRAY_SIZE(rdns), rdns };
if (0)
{

View file

@ -575,7 +575,7 @@ static CRYPT_DATA_BLOB b1[] = {
{ sizeof(u2), u2 },
{ sizeof(u2), u2 },
};
static const struct update_accum a1 = { sizeof(b1) / sizeof(b1[0]), b1 };
static const struct update_accum a1 = { ARRAY_SIZE(b1), b1 };
/* The updates of a definite-length encoded message */
static BYTE u3[] = { 0x30,0x13,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x07,0x01,0xa0,0x06,0x04,0x04 };
@ -583,7 +583,7 @@ static CRYPT_DATA_BLOB b2[] = {
{ sizeof(u3), u3 },
{ sizeof(u2), u2 },
};
static const struct update_accum a2 = { sizeof(b2) / sizeof(b2[0]), b2 };
static const struct update_accum a2 = { ARRAY_SIZE(b2), b2 };
/* The updates of an indefinite-length encoded message */
static BYTE u4[] = { 0x30,0x80,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x07,0x01,0xa0,0x80,0x24,0x80 };
@ -597,7 +597,7 @@ static CRYPT_DATA_BLOB b3[] = {
{ sizeof(u2), u2 },
{ sizeof(u6), u6 },
};
static const struct update_accum a3 = { sizeof(b3) / sizeof(b3[0]), b3 };
static const struct update_accum a3 = { ARRAY_SIZE(b3), b3 };
static void check_updates(LPCSTR header, const struct update_accum *expected,
const struct update_accum *got)

View file

@ -106,7 +106,7 @@ static void testOIDToAlgID(void)
alg = CertOIDToAlgId("1.2.3");
ok(!alg, "Expected failure, got %d\n", alg);
for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
{
alg = CertOIDToAlgId(oidToAlgID[i].oid);
ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
@ -124,7 +124,7 @@ static void testAlgIDToOID(void)
oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
ok(!oid && GetLastError() == 0xdeadbeef,
"Didn't expect last error (%08x) to be set\n", GetLastError());
for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
{
oid = CertAlgIdToOID(algIDToOID[i].algID);
/* Allow failure, not every version of Windows supports every algo */
@ -424,7 +424,7 @@ static void test_registerDefaultOIDFunction(void)
DWORD type, size;
LPSTR ptr;
size = sizeof(dllBuf) / sizeof(dllBuf[0]);
size = ARRAY_SIZE(dllBuf);
rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
ok(rc == 0,
"Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc);
@ -547,86 +547,63 @@ static void test_findOIDInfo(void)
static WCHAR sha256ECDSA[] = { 's','h','a','2','5','6','E','C','D','S','A',0 };
static WCHAR sha1[] = { 's','h','a','1',0 };
static CHAR oid_rsa_md5[] = szOID_RSA_MD5, oid_sha256[] = szOID_NIST_sha256;
static CHAR oid_ecda_sha25[] = szOID_ECDSA_SHA256;
static CHAR oid_ecdsa_sha256[] = szOID_ECDSA_SHA256;
ALG_ID alg = CALG_SHA1;
ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
const struct oid_info
{
DWORD key_type;
void *key;
const char *oid;
ALG_ID algid;
ALG_ID broken_algid;
} oid_test_info [] =
{
{ CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, szOID_RSA_MD5, CALG_MD5 },
{ CRYPT_OID_INFO_NAME_KEY, sha1, szOID_OIWSEC_sha1, CALG_SHA1 },
{ CRYPT_OID_INFO_ALGID_KEY, &alg, szOID_OIWSEC_sha1, CALG_SHA1 },
{ CRYPT_OID_INFO_SIGN_KEY, algs, szOID_RSA_MD5RSA, CALG_MD5 },
{ CRYPT_OID_INFO_OID_KEY, oid_sha256, szOID_NIST_sha256, CALG_SHA_256, -1 },
};
PCCRYPT_OID_INFO info;
static const WCHAR sha256W[] = {'s','h','a','2','5','6',0};
int i;
info = CryptFindOIDInfo(0, NULL, 0);
ok(info == NULL, "Expected NULL\n");
info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, 0);
ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
if (info)
for (i = 0; i < ARRAY_SIZE(oid_test_info); i++)
{
ok(!strcmp(info->pszOID, szOID_RSA_MD5), "Expected %s, got %s\n",
szOID_RSA_MD5, info->pszOID);
ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
U(*info).Algid);
}
info = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, sha1, 0);
ok(info != NULL, "Expected to find sha1\n");
if (info)
{
ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
szOID_OIWSEC_sha1, info->pszOID);
ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
U(*info).Algid);
}
info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY, &alg, 0);
ok(info != NULL, "Expected to find sha1\n");
if (info)
{
ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
szOID_OIWSEC_sha1, info->pszOID);
ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
U(*info).Algid);
}
info = CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY, algs, 0);
ok(info != NULL, "Expected to find md5RSA\n");
if (info)
{
ok(!strcmp(info->pszOID, szOID_RSA_MD5RSA), "Expected %s, got %s\n",
szOID_RSA_MD5RSA, info->pszOID);
ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
U(*info).Algid);
const struct oid_info *test = &oid_test_info[i];
info = CryptFindOIDInfo(test->key_type, test->key, 0);
ok(info != NULL, "Failed to find %s.\n", test->oid);
if (info)
{
ok(!strcmp(info->pszOID, test->oid), "Unexpected OID %s, expected %s\n", info->pszOID, test->oid);
ok(U(*info).Algid == test->algid || broken(U(*info).Algid == test->broken_algid),
"Unexpected Algid %d, expected %d\n", U(*info).Algid, test->algid);
}
}
info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_sha256, 0);
ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
if (info)
{
ok(!strcmp(info->pszOID, szOID_NIST_sha256), "Expected %s, got %s\n",
szOID_NIST_sha256, info->pszOID);
ok(!lstrcmpW(info->pwszName, sha256W), "pwszName = %s\n", wine_dbgstr_w(info->pwszName));
ok(U(*info).Algid == CALG_SHA_256 || U(*info).Algid == -1,
"Expected CALG_MD5 or -1, got %d\n", U(*info).Algid);
}
info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecda_sha25, 0);
info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_ecdsa_sha256, 0);
if (info)
{
DWORD *data;
ok(info->cbSize == sizeof(*info),
"Expected %d, got %d\n", (int)sizeof(*info), info->cbSize);
ok(!strcmp(info->pszOID, oid_ecda_sha25),
"Expected %s, got %s\n", oid_ecda_sha25, info->pszOID);
ok(!lstrcmpW(info->pwszName, sha256ECDSA),
"Expected %s, got %s\n", wine_dbgstr_w(sha256ECDSA), wine_dbgstr_w(info->pwszName));
ok(info->cbSize == sizeof(*info), "Unexpected structure size %d.\n", info->cbSize);
ok(!strcmp(info->pszOID, oid_ecdsa_sha256), "Expected %s, got %s\n", oid_ecdsa_sha256, info->pszOID);
ok(!lstrcmpW(info->pwszName, sha256ECDSA), "Expected %s, got %s\n",
wine_dbgstr_w(sha256ECDSA), wine_dbgstr_w(info->pwszName));
ok(info->dwGroupId == CRYPT_SIGN_ALG_OID_GROUP_ID,
"Expected CRYPT_SIGN_ALG_OID_GROUP_ID, got %u\n", info->dwGroupId);
ok(U(*info).Algid == CALG_OID_INFO_CNG_ONLY,
"Expected CALG_OID_INFO_CNG_ONLY, got %d\n", U(*info).Algid);
data = (DWORD *)info->ExtraInfo.pbData;
ok(info->ExtraInfo.cbData == 8,
"Expected 8, got %d\n", info->ExtraInfo.cbData);
ok(data[0] == CALG_OID_INFO_PARAMETERS,
"Expected CALG_OID_INFO_PARAMETERS, got %x\n", data[0]);
ok(info->ExtraInfo.cbData == 8, "Expected 8, got %d\n", info->ExtraInfo.cbData);
ok(data[0] == CALG_OID_INFO_PARAMETERS, "Expected CALG_OID_INFO_PARAMETERS, got %x\n", data[0]);
ok(data[1] == CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG,
"Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %x\n", data[1]);
"Expected CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG, got %x\n", data[1]);
ok(!lstrcmpW(info->pwszCNGAlgid, BCRYPT_SHA256_ALGORITHM), "Expected %s, got %s\n",
wine_dbgstr_w(BCRYPT_SHA256_ALGORITHM), wine_dbgstr_w(info->pwszCNGAlgid));

View file

@ -187,9 +187,8 @@ static void test_SIPRetrieveSubjectGUID(void)
ok (ret > 0, "expected GEVA(windir) to succeed, last error %d\n", GetLastError());
strcat(regeditPath, "\\");
strcat(regeditPath, regeditExe);
MultiByteToWideChar( CP_ACP, 0, regeditPath,
strlen(regeditPath)+1, regeditPathW,
sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
MultiByteToWideChar(CP_ACP, 0, regeditPath, strlen(regeditPath)+1, regeditPathW,
ARRAY_SIZE(regeditPathW));
SetLastError(0xdeadbeef);
memset(&subject, 1, sizeof(GUID));
@ -221,9 +220,7 @@ static void test_SIPRetrieveSubjectGUID(void)
/* Now with an empty file */
GetTempPathA(sizeof(path), path);
GetTempFileNameA(path, "sip", 0 , tempfile);
MultiByteToWideChar( CP_ACP, 0, tempfile,
strlen(tempfile)+1, tempfileW,
sizeof(tempfileW)/sizeof(tempfileW[0]) );
MultiByteToWideChar(CP_ACP, 0, tempfile, strlen(tempfile)+1, tempfileW, ARRAY_SIZE(tempfileW));
SetLastError(0xdeadbeef);
memset(&subject, 1, sizeof(GUID));

View file

@ -385,7 +385,7 @@ static void testRegStoreSavedCerts(void)
BOOL ret;
DWORD res,i;
for (i = 0; i < sizeof(reg_store_saved_certs) / sizeof(reg_store_saved_certs[0]); i++)
for (i = 0; i < ARRAY_SIZE(reg_store_saved_certs); i++)
{
DWORD err;
@ -2081,7 +2081,7 @@ static void testCertRegisterSystemStore(void)
const CERT_CONTEXT *cert, *cert2;
unsigned int i;
for (i = 0; i < sizeof(reg_system_store_test_data) / sizeof(reg_system_store_test_data[0]); i++) {
for (i = 0; i < ARRAY_SIZE(reg_system_store_test_data); i++) {
cur_flag = reg_system_store_test_data[i].cert_store;
ret = CertRegisterSystemStore(WineTestW, cur_flag, NULL, NULL);
if (!ret)
@ -2469,7 +2469,7 @@ static void delete_test_key(void)
RegQueryInfoKeyW(test_key, NULL, NULL, NULL, &num_subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
for (idx = num_subkeys; idx-- > 0;)
{
subkey_name_len = sizeof(subkey_name)/sizeof(WCHAR);
subkey_name_len = ARRAY_SIZE(subkey_name);
RegEnumKeyExW(test_key, idx, subkey_name, &subkey_name_len, NULL, NULL, NULL, NULL);
RegDeleteKeyW(test_key, subkey_name);
}

View file

@ -250,7 +250,7 @@ static void test_CertRDNValueToStrA(void)
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ok(!buffer[0], "Expected empty string\n");
for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
for (i = 0; i < ARRAY_SIZE(attrs); i++)
{
ret = pCertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value,
buffer, sizeof(buffer));
@ -341,15 +341,13 @@ static void test_CertRDNValueToStrW(void)
SetLastError(0xdeadbeef);
ret = pCertRDNValueToStrW(0, &blob, NULL, 0);
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ret = pCertRDNValueToStrW(0, &blob, buffer,
sizeof(buffer) / sizeof(buffer[0]));
ret = pCertRDNValueToStrW(0, &blob, buffer, ARRAY_SIZE(buffer));
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ok(!buffer[0], "Expected empty string\n");
for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
for (i = 0; i < ARRAY_SIZE(attrs); i++)
{
ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value,
buffer, sizeof(buffer) / sizeof(buffer[0]));
ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, ARRAY_SIZE(buffer));
todo_wine_if (attrs[i].todo)
{
ok(ret == lstrlenW(attrs[i].str) + 1,
@ -550,8 +548,7 @@ static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType,
todo_wine_if (todo)
ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
lstrlenW(expected) + 1, i);
i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer,
sizeof(buffer) / sizeof(buffer[0]));
i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer, ARRAY_SIZE(buffer));
todo_wine_if (todo)
ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
lstrlenW(expected) + 1, i);
@ -795,7 +792,7 @@ static void test_CertStrToNameA(void)
&size, NULL);
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"Expected ERROR_MORE_DATA, got %08x\n", GetLastError());
for (i = 0; i < sizeof(namesA) / sizeof(namesA[0]); i++)
for (i = 0; i < ARRAY_SIZE(namesA); i++)
{
size = sizeof(buf);
ret = pCertStrToNameA(X509_ASN_ENCODING, namesA[i].x500, 0, NULL, buf,
@ -889,7 +886,7 @@ static void test_CertStrToNameW(void)
ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
"Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
ok(errorPtr && *errorPtr == '1', "Expected first error character was 1\n");
for (i = 0; i < sizeof(namesW) / sizeof(namesW[0]); i++)
for (i = 0; i < ARRAY_SIZE(namesW); i++)
{
size = sizeof(buf);
ret = pCertStrToNameW(X509_ASN_ENCODING, namesW[i].x500, 0, NULL, buf,