ReactOS 0.4.16-dev-2491-g3dc6630
asn.c
Go to the documentation of this file.
1/* Unit test suite for wintrust asn functions
2 *
3 * Copyright 2007 Juan Lang
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 */
20#include <stdarg.h>
21#include "windef.h"
22#include "winbase.h"
23#include "winerror.h"
24#include "wincrypt.h"
25#include "wintrust.h"
26
27#include "wine/test.h"
28
29static BOOL (WINAPI *pCryptDecodeObjectEx)(DWORD,LPCSTR,const BYTE*,DWORD,DWORD,PCRYPT_DECODE_PARA,void*,DWORD*);
30static BOOL (WINAPI *pCryptEncodeObjectEx)(DWORD,LPCSTR,const void*,DWORD,PCRYPT_ENCODE_PARA,void*,DWORD*);
31
32static const BYTE falseCriteria[] = { 0x30,0x06,0x01,0x01,0x00,0x01,0x01,0x00 };
33static const BYTE trueCriteria[] = { 0x30,0x06,0x01,0x01,0xff,0x01,0x01,0xff };
34
36{
37 BOOL ret;
38 DWORD size = 0;
39 LPBYTE buf;
40 SPC_FINANCIAL_CRITERIA criteria = { FALSE, FALSE };
41
42 if (!pCryptEncodeObjectEx)
43 {
44 win_skip("CryptEncodeObjectEx() is not available. Skipping the encodeFinancialCriteria tests\n");
45 return;
46 }
48 &criteria, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
49 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
50 if (ret)
51 {
52 ok(size == sizeof(falseCriteria), "Unexpected size %ld\n", size);
53 ok(!memcmp(buf, falseCriteria, size), "Unexpected value\n");
55 }
56 criteria.fFinancialInfoAvailable = criteria.fMeetsCriteria = TRUE;
58 &criteria, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
59 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
60 if (ret)
61 {
62 ok(size == sizeof(trueCriteria), "Unexpected size %ld\n", size);
63 ok(!memcmp(buf, trueCriteria, size), "Unexpected value\n");
65 }
66}
67
69{
70 BOOL ret;
72 DWORD size = sizeof(criteria);
73
74 if (!pCryptDecodeObjectEx)
75 {
76 win_skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCFinancialCriteria tests\n");
77 return;
78 }
79
81 falseCriteria, sizeof(falseCriteria), 0, NULL, &criteria, &size);
82 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
83 if (ret)
84 {
85 ok(!criteria.fFinancialInfoAvailable, "expected FALSE\n");
86 ok(!criteria.fMeetsCriteria, "expected FALSE\n");
87 }
89 trueCriteria, sizeof(trueCriteria), 0, NULL, &criteria, &size);
90 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
91 if (ret)
92 {
93 ok(criteria.fFinancialInfoAvailable, "expected TRUE\n");
94 ok(criteria.fMeetsCriteria, "expected TRUE\n");
95 }
96}
97
98static WCHAR url[] = { 'h','t','t','p',':','/','/','w','i','n','e','h','q','.',
99 'o','r','g',0 };
100static const WCHAR nihongoURL[] = { 'h','t','t','p',':','/','/',0x226f,
101 0x575b, 0 };
102static const BYTE emptyURLSPCLink[] = { 0x80,0x00 };
103static const BYTE urlSPCLink[] = {
1040x80,0x11,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,0x65,0x68,0x71,
1050x2e,0x6f,0x72,0x67};
106static const BYTE fileSPCLink[] = {
1070xa2,0x14,0x80,0x12,0x00,0x68,0x00,0x74,0x00,0x74,0x00,0x70,0x00,0x3a,0x00,
1080x2f,0x00,0x2f,0x22,0x6f,0x57,0x5b };
109static const BYTE emptyMonikerSPCLink[] = {
1100xa1,0x14,0x04,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1110x00,0x00,0x00,0x00,0x00,0x04,0x00 };
112static BYTE data[] = { 0xba, 0xad, 0xf0, 0x0d };
113static const BYTE monikerSPCLink[] = {
1140xa1,0x18,0x04,0x10,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,
1150xea,0xea,0xea,0xea,0xea,0x04,0x04,0xba,0xad,0xf0,0x0d };
116
117static void test_encodeSPCLink(void)
118{
119 BOOL ret;
120 DWORD size = 0;
121 LPBYTE buf;
122 SPC_LINK link = { 0 };
123
124 if (!pCryptEncodeObjectEx)
125 {
126 win_skip("CryptEncodeObjectEx() is not available. Skipping the encodeSPCLink tests\n");
127 return;
128 }
129
130 SetLastError(0xdeadbeef);
131 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
134 "Expected E_INVALIDARG, got %08lx\n", GetLastError());
135 link.dwLinkChoice = SPC_URL_LINK_CHOICE;
136 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
138 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
139 if (ret)
140 {
141 ok(size == sizeof(emptyURLSPCLink), "Unexpected size %ld\n", size);
142 ok(!memcmp(buf, emptyURLSPCLink, size), "Unexpected value\n");
143 LocalFree(buf);
144 }
145 /* With an invalid char: */
146 link.pwszUrl = (LPWSTR)nihongoURL;
147 size = 1;
148 SetLastError(0xdeadbeef);
149 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
151 ok(!ret &&
153 GetLastError() == OSS_BAD_PTR /* WinNT */),
154 "Expected CRYPT_E_INVALID_IA5_STRING, got %08lx\n", GetLastError());
155 /* Unlike the crypt32 string encoding routines, size is not set to the
156 * index of the first invalid character.
157 */
158 ok(size == 0, "Expected size 0, got %ld\n", size);
159 link.pwszUrl = url;
160 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
162 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
163 if (ret)
164 {
165 ok(size == sizeof(urlSPCLink), "Unexpected size %ld\n", size);
166 ok(!memcmp(buf, urlSPCLink, size), "Unexpected value\n");
167 LocalFree(buf);
168 }
169 link.dwLinkChoice = SPC_FILE_LINK_CHOICE;
170 link.pwszFile = (LPWSTR)nihongoURL;
171 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
173 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
174 if (ret)
175 {
176 ok(size == sizeof(fileSPCLink), "Unexpected size %ld\n", size);
177 ok(!memcmp(buf, fileSPCLink, size), "Unexpected value\n");
178 LocalFree(buf);
179 }
180 link.dwLinkChoice = SPC_MONIKER_LINK_CHOICE;
181 memset(&link.Moniker, 0, sizeof(link.Moniker));
182 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
184 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
185 if (ret)
186 {
187 ok(size == sizeof(emptyMonikerSPCLink), "Unexpected size %ld\n", size);
188 ok(!memcmp(buf, emptyMonikerSPCLink, size), "Unexpected value\n");
189 LocalFree(buf);
190 }
191 memset(&link.Moniker.ClassId, 0xea, sizeof(link.Moniker.ClassId));
192 link.Moniker.SerializedData.pbData = data;
193 link.Moniker.SerializedData.cbData = sizeof(data);
194 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT, &link,
196 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
197 if (ret)
198 {
199 ok(size == sizeof(monikerSPCLink), "Unexpected size %ld\n", size);
200 ok(!memcmp(buf, monikerSPCLink, size), "Unexpected value\n");
201 LocalFree(buf);
202 }
203}
204
205static const BYTE badMonikerSPCLink[] = {
2060xa1,0x19,0x04,0x11,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,0xea,
2070xea,0xea,0xea,0xea,0xea,0xea,0x04,0x04,0xba,0xad,0xf0,0x0d };
208
209static void test_decodeSPCLink(void)
210{
211 BOOL ret;
212 LPBYTE buf = NULL;
213 DWORD size = 0;
214 SPC_LINK *link;
215
216 if (!pCryptDecodeObjectEx)
217 {
218 win_skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCLink tests\n");
219 return;
220 }
221
222 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
224 &buf, &size);
225 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
226 if (ret)
227 {
228 link = (SPC_LINK *)buf;
229 ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
230 "Expected SPC_URL_LINK_CHOICE, got %ld\n", link->dwLinkChoice);
231 ok(lstrlenW(link->pwszUrl) == 0, "Expected empty string\n");
232 LocalFree(buf);
233 }
234 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
236 &buf, &size);
237 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
238 if (ret)
239 {
240 link = (SPC_LINK *)buf;
241 ok(link->dwLinkChoice == SPC_URL_LINK_CHOICE,
242 "Expected SPC_URL_LINK_CHOICE, got %ld\n", link->dwLinkChoice);
243 ok(!lstrcmpW(link->pwszUrl, url), "Unexpected URL\n");
244 LocalFree(buf);
245 }
246 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
248 &buf, &size);
249 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
250 if (ret)
251 {
252 link = (SPC_LINK *)buf;
253 ok(link->dwLinkChoice == SPC_FILE_LINK_CHOICE,
254 "Expected SPC_FILE_LINK_CHOICE, got %ld\n", link->dwLinkChoice);
255 ok(!lstrcmpW(link->pwszFile, nihongoURL), "Unexpected file\n");
256 LocalFree(buf);
257 }
258 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
260 NULL, &buf, &size);
261 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
262 if (ret)
263 {
264 SPC_SERIALIZED_OBJECT emptyMoniker = { { 0 } };
265
266 link = (SPC_LINK *)buf;
267 ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
268 "Expected SPC_MONIKER_LINK_CHOICE, got %ld\n", link->dwLinkChoice);
269 ok(!memcmp(&link->Moniker.ClassId, &emptyMoniker.ClassId,
270 sizeof(emptyMoniker.ClassId)), "Unexpected value\n");
271 ok(link->Moniker.SerializedData.cbData == 0,
272 "Expected no serialized data\n");
273 LocalFree(buf);
274 }
275 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
277 &buf, &size);
278 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
279 if (ret)
280 {
281 SPC_UUID id;
282
283 link = (SPC_LINK *)buf;
284 ok(link->dwLinkChoice == SPC_MONIKER_LINK_CHOICE,
285 "Expected SPC_MONIKER_LINK_CHOICE, got %ld\n", link->dwLinkChoice);
286 memset(&id, 0xea, sizeof(id));
287 ok(!memcmp(&link->Moniker.ClassId, &id, sizeof(id)),
288 "Unexpected value\n");
289 ok(link->Moniker.SerializedData.cbData == sizeof(data),
290 "Unexpected data size %ld\n", link->Moniker.SerializedData.cbData);
291 ok(!memcmp(link->Moniker.SerializedData.pbData, data, sizeof(data)),
292 "Unexpected value\n");
293 LocalFree(buf);
294 }
295 SetLastError(0xdeadbeef);
296 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_LINK_STRUCT,
298 NULL, &buf, &size);
299 ok(!ret &&
301 GetLastError() == OSS_DATA_ERROR /* WinNT */),
302 "Expected CRYPT_E_BAD_ENCODE, got %08lx\n", GetLastError());
303}
304
305static const BYTE emptySequence[] = { 0x30,0x00 };
306static BYTE flags[] = { 1 };
307static const BYTE onlyFlagsPEImage[] = { 0x30,0x04,0x03,0x02,0x00,0x01 };
308static const BYTE onlyEmptyFilePEImage[] = {
3090x30,0x06,0xa0,0x04,0xa2,0x02,0x80,0x00 };
3110x30,0x0a,0x03,0x02,0x00,0x01,0xa0,0x04,0xa2,0x02,0x80,0x00 };
312static const BYTE flagsAndFilePEImage[] = {
3130x30,0x1c,0x03,0x02,0x00,0x01,0xa0,0x16,0xa2,0x14,0x80,0x12,0x00,0x68,0x00,
3140x74,0x00,0x74,0x00,0x70,0x00,0x3a,0x00,0x2f,0x00,0x2f,0x22,0x6f,0x57,0x5b };
315
316static void test_encodeSPCPEImage(void)
317{
318 BOOL ret;
319 DWORD size = 0;
320 LPBYTE buf;
321 SPC_PE_IMAGE_DATA imageData = { { 0 } };
322 SPC_LINK link = { 0 };
323
324 if (!pCryptEncodeObjectEx)
325 {
326 win_skip("CryptEncodeObjectEx() is not available. Skipping the encodeSPCPEImage tests\n");
327 return;
328 }
329
330 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
331 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
332 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
333 if (ret)
334 {
335 ok(size == sizeof(emptySequence), "Unexpected size %ld\n", size);
337 "Unexpected value\n");
338 LocalFree(buf);
339 }
340 /* With an invalid link: */
341 imageData.pFile = &link;
342 SetLastError(0xdeadbeef);
343 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
344 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
346 "Expected E_INVALIDARG, got %08lx\n", GetLastError());
347 /* With just unused bits field set: */
348 imageData.pFile = NULL;
349 imageData.Flags.cUnusedBits = 1;
350 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
351 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
352 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
353 if (ret)
354 {
355 ok(size == sizeof(emptySequence), "Unexpected size %ld\n", size);
357 "Unexpected value\n");
358 LocalFree(buf);
359 }
360 /* With flags set: */
361 imageData.Flags.cUnusedBits = 0;
362 imageData.Flags.pbData = flags;
363 imageData.Flags.cbData = sizeof(flags);
364 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
365 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
366 if (!ret && GetLastError() == OSS_TOO_LONG)
367 {
368 skip("SPC_PE_IMAGE_DATA_STRUCT not supported\n");
369 return;
370 }
371 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
372 if (ret)
373 {
374 ok(size == sizeof(onlyFlagsPEImage), "Unexpected size %ld\n", size);
376 "Unexpected value\n");
377 LocalFree(buf);
378 }
379 /* With just an empty file: */
380 imageData.Flags.cbData = 0;
381 link.dwLinkChoice = SPC_FILE_LINK_CHOICE;
382 imageData.pFile = &link;
383 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
384 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
385 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
386 if (ret)
387 {
388 ok(size == sizeof(onlyEmptyFilePEImage), "Unexpected size %ld\n", size);
390 "Unexpected value\n");
391 LocalFree(buf);
392 }
393 /* With flags and an empty file: */
394 imageData.Flags.pbData = flags;
395 imageData.Flags.cbData = sizeof(flags);
396 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
397 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
398 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
399 if (ret)
400 {
401 ok(size == sizeof(flagsAndEmptyFilePEImage), "Unexpected size %ld\n",
402 size);
404 sizeof(flagsAndEmptyFilePEImage)), "Unexpected value\n");
405 LocalFree(buf);
406 }
407 /* Finally, a non-empty file: */
408 link.pwszFile = (LPWSTR)nihongoURL;
409 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
410 &imageData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
411 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
412 if (ret)
413 {
414 ok(size == sizeof(flagsAndFilePEImage), "Unexpected size %ld\n", size);
416 "Unexpected value\n");
417 LocalFree(buf);
418 }
419}
420
421static void test_decodeSPCPEImage(void)
422{
423 static const WCHAR emptyString[] = { 0 };
424 BOOL ret;
425 LPBYTE buf = NULL;
426 DWORD size = 0;
427 SPC_PE_IMAGE_DATA *imageData;
428
429 if (!pCryptDecodeObjectEx)
430 {
431 win_skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCPEImage tests\n");
432 return;
433 }
434
435 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
438 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
439 if (ret)
440 {
441 imageData = (SPC_PE_IMAGE_DATA *)buf;
442 ok(imageData->Flags.cbData == 0, "Expected empty flags, got %ld\n",
443 imageData->Flags.cbData);
444 ok(imageData->pFile == NULL, "Expected no file\n");
445 LocalFree(buf);
446 }
447 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
450 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
451 if (ret)
452 {
453 imageData = (SPC_PE_IMAGE_DATA *)buf;
454 ok(imageData->Flags.cbData == sizeof(flags),
455 "Unexpected flags size %ld\n", imageData->Flags.cbData);
456 if (imageData->Flags.cbData)
457 ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
458 "Unexpected flags\n");
459 ok(imageData->pFile == NULL, "Expected no file\n");
460 LocalFree(buf);
461 }
462 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
465 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
466 if (ret)
467 {
468 imageData = (SPC_PE_IMAGE_DATA *)buf;
469 ok(imageData->Flags.cbData == 0, "Expected empty flags, got %ld\n",
470 imageData->Flags.cbData);
471 ok(imageData->pFile != NULL, "Expected a file\n");
472 if (imageData->pFile)
473 {
475 "Expected SPC_FILE_LINK_CHOICE, got %ld\n",
476 imageData->pFile->dwLinkChoice);
477 ok(!lstrcmpW(imageData->pFile->pwszFile, emptyString),
478 "Unexpected file\n");
479 }
480 LocalFree(buf);
481 }
482 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
485 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
486 if (ret)
487 {
488 imageData = (SPC_PE_IMAGE_DATA *)buf;
489 ok(imageData->Flags.cbData == sizeof(flags),
490 "Unexpected flags size %ld\n", imageData->Flags.cbData);
491 if (imageData->Flags.cbData)
492 ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
493 "Unexpected flags\n");
494 ok(imageData->pFile != NULL, "Expected a file\n");
495 if (imageData->pFile)
496 {
498 "Expected SPC_FILE_LINK_CHOICE, got %ld\n",
499 imageData->pFile->dwLinkChoice);
500 ok(!lstrcmpW(imageData->pFile->pwszFile, emptyString),
501 "Unexpected file\n");
502 }
503 LocalFree(buf);
504 }
505 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_PE_IMAGE_DATA_STRUCT,
508 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
509 if (ret)
510 {
511 imageData = (SPC_PE_IMAGE_DATA *)buf;
512 ok(imageData->Flags.cbData == sizeof(flags),
513 "Unexpected flags size %ld\n", imageData->Flags.cbData);
514 if (imageData->Flags.cbData)
515 ok(!memcmp(imageData->Flags.pbData, flags, sizeof(flags)),
516 "Unexpected flags\n");
517 ok(imageData->pFile != NULL, "Expected a file\n");
518 if (imageData->pFile)
519 {
521 "Expected SPC_FILE_LINK_CHOICE, got %ld\n",
522 imageData->pFile->dwLinkChoice);
523 ok(!lstrcmpW(imageData->pFile->pwszFile, nihongoURL),
524 "Unexpected file\n");
525 }
526 LocalFree(buf);
527 }
528}
529
530static const BYTE emptyIndirectData[] = {
531 0x30,0x0c,0x30,0x02,0x06,0x00,0x30,0x06,0x30,0x02,0x06,0x00,0x04,0x00 };
532static const BYTE spcidcWithOnlyDigest[] = {
533 0x30,0x20,0x30,0x02,0x06,0x00,0x30,0x1a,0x30,0x02,0x06,0x00,0x04,0x14,0x01,0x02,
534 0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,
535 0x13,0x14 };
537 0x30,0x27,0x30,0x02,0x06,0x00,0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,
538 0x1a,0x05,0x00,0x04,0x14,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,
539 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14 };
541 0x30,0x29,0x30,0x02,0x06,0x00,0x30,0x23,0x30,0x0b,0x06,0x05,0x2b,0x0e,0x03,0x02,
542 0x1a,0x74,0x65,0x73,0x74,0x04,0x14,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
543 0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14 };
545 0x30,0x33,0x30,0x0c,0x06,0x0a,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0f,
546 0x30,0x23,0x30,0x0b,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x74,0x65,0x73,0x74,0x04,
547 0x14,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
548 0x10,0x11,0x12,0x13,0x14 };
549static const BYTE spcidcWithEverything[] = {
550 0x30,0x35,0x30,0x0e,0x06,0x0a,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,0x02,0x01,0x0f,
551 0x30,0x00,0x30,0x23,0x30,0x0b,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x74,0x65,0x73,
552 0x74,0x04,0x14,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,
553 0x0e,0x0f,0x10,0x11,0x12,0x13,0x14 };
554
555static BYTE fakeDigest[] = {
556 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,
557 0x11,0x12,0x13,0x14 };
558static BYTE parameters[] = { 't','e','s','t' };
559
561{
562 static char SPC_PE_IMAGE_DATA_OBJID_[] = SPC_PE_IMAGE_DATA_OBJID;
563 static char szOID_OIWSEC_sha1_[] = szOID_OIWSEC_sha1;
564
565 SPC_INDIRECT_DATA_CONTENT indirectData = { { 0 } };
566 DWORD size = 0;
567 LPBYTE buf;
568 BOOL ret;
569
570 if (!pCryptEncodeObjectEx)
571 {
572 win_skip("CryptEncodeObjectEx() is not available. Skipping the encodeSPCIndirectDataContent tests\n");
573 return;
574 }
575
577 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
578 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
579 if (ret)
580 {
581 ok(size == sizeof(emptyIndirectData), "Unexpected size %ld\n", size);
582 if (size == sizeof(emptyIndirectData))
584 "Unexpected value\n");
585 LocalFree(buf);
586 }
587 /* With only digest */
588 indirectData.Digest.cbData = sizeof(fakeDigest);
589 indirectData.Digest.pbData = fakeDigest;
591 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
592 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
593 if (ret)
594 {
595 ok(size == sizeof(spcidcWithOnlyDigest), "Unexpected size %ld\n", size);
596 if (size == sizeof(spcidcWithOnlyDigest))
598 "Unexpected value\n");
599 LocalFree(buf);
600 }
601 /* With digest and digest algorithm */
602 indirectData.DigestAlgorithm.pszObjId = szOID_OIWSEC_sha1_;
604 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
605 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
606 if (ret)
607 {
608 ok(size == sizeof(spcidcWithDigestAndAlgorithm), "Unexpected size %ld\n",
609 size);
610 if (size == sizeof(spcidcWithDigestAndAlgorithm))
613 "Unexpected value\n");
614 LocalFree(buf);
615 }
616 /* With digest algorithm parameters */
617 indirectData.DigestAlgorithm.Parameters.cbData = sizeof(parameters);
620 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
621 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
622 if (ret)
623 {
625 "Unexpected size %ld\n", size);
629 "Unexpected value\n");
630 LocalFree(buf);
631 }
632 /* With everything except Data.Value */
633 indirectData.Data.pszObjId = SPC_PE_IMAGE_DATA_OBJID_;
635 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
636 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
637 if (ret)
638 {
640 "Unexpected size %ld\n", size);
644 "Unexpected value\n");
645 LocalFree(buf);
646 }
647 /* With everything */
648 indirectData.Data.Value.cbData = sizeof(emptySequence);
649 indirectData.Data.Value.pbData = (void*)emptySequence;
651 &indirectData, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
652 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
653 if (ret)
654 {
655 ok(size == sizeof(spcidcWithEverything), "Unexpected size %ld\n", size);
656 if (size == sizeof(spcidcWithEverything))
658 "Unexpected value\n");
659 LocalFree(buf);
660 }
661}
662
664{
665 static const BYTE asn1Null[] = { 0x05,0x00 };
666
667 BOOL ret;
668 LPBYTE buf = NULL;
669 DWORD size = 0;
670 SPC_INDIRECT_DATA_CONTENT *indirectData;
671
672 if (!pCryptDecodeObjectEx)
673 {
674 win_skip("CryptDecodeObjectEx() is not available. Skipping the decodeSPCIndirectDataContent tests\n");
675 return;
676 }
677
681 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
682 if (ret)
683 {
684 indirectData = (SPC_INDIRECT_DATA_CONTENT *)buf;
685 ok(indirectData->Data.pszObjId != NULL, "Expected non-NULL data objid\n");
686 if (indirectData->Data.pszObjId)
687 ok(!strcmp(indirectData->Data.pszObjId, ""),
688 "Expected empty data objid\n");
689 ok(indirectData->Data.Value.cbData == 0, "Expected no data value\n");
690 ok(indirectData->DigestAlgorithm.pszObjId != NULL,
691 "Expected non-NULL digest algorithm objid\n");
692 if (indirectData->DigestAlgorithm.pszObjId)
693 ok(!strcmp(indirectData->DigestAlgorithm.pszObjId, ""),
694 "Expected empty digest algorithm objid\n");
695 ok(indirectData->DigestAlgorithm.Parameters.cbData == 0,
696 "Expected no digest algorithm parameters\n");
697 ok(indirectData->Digest.cbData == 0, "Expected no digest\n");
698 LocalFree(buf);
699 }
703 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
704 if (ret)
705 {
706 indirectData = (SPC_INDIRECT_DATA_CONTENT *)buf;
707 ok(indirectData->Digest.cbData == sizeof(fakeDigest),
708 "Unexpected digest size %ld\n", indirectData->Digest.cbData);
709 if (indirectData->Digest.cbData == sizeof(fakeDigest))
710 ok(!memcmp(indirectData->Digest.pbData, fakeDigest,
711 sizeof(fakeDigest)),
712 "Unexpected flags\n");
713 LocalFree(buf);
714 }
718 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
719 if (ret)
720 {
721 indirectData = (SPC_INDIRECT_DATA_CONTENT *)buf;
722 ok(indirectData->DigestAlgorithm.pszObjId != NULL,
723 "Expected non-NULL digest algorithm objid\n");
724 if (indirectData->DigestAlgorithm.pszObjId)
726 "Expected szOID_OIWSEC_sha1, got \"%s\"\n",
727 indirectData->DigestAlgorithm.pszObjId);
728 ok(indirectData->DigestAlgorithm.Parameters.cbData == sizeof(asn1Null),
729 "Unexpected digest algorithm parameters size %ld\n",
730 indirectData->DigestAlgorithm.Parameters.cbData);
731 if (indirectData->DigestAlgorithm.Parameters.cbData == sizeof(asn1Null))
733 asn1Null, sizeof(asn1Null)),
734 "Unexpected digest algorithm parameters\n");
735 ok(indirectData->Digest.cbData == sizeof(fakeDigest),
736 "Unexpected digest size %ld\n", indirectData->Digest.cbData);
737 if (indirectData->Digest.cbData == sizeof(fakeDigest))
738 ok(!memcmp(indirectData->Digest.pbData, fakeDigest,
739 sizeof(fakeDigest)),
740 "Unexpected flags\n");
741 LocalFree(buf);
742 }
746 /* what? */
748 "Expected CRYPT_E_ASN1_EOD, got %08lx\n", GetLastError());
749 if (ret)
750 LocalFree(buf);
754 /* huh??? */
756 "Expected CRYPT_E_ASN1_EOD, got %08lx\n", GetLastError());
757 if (ret)
758 LocalFree(buf);
762 /* ?????? */
764 "Expected CRYPT_E_ASN1_EOD, got %08lx\n", GetLastError());
765 if (ret)
766 LocalFree(buf);
767}
768
769static WCHAR foo[] = { 'f','o','o',0 };
770static WCHAR guidStr[] = { '{','8','b','c','9','6','b','0','0','-',
771 '8','d','a','1','-','1','1','c','f','-','8','7','3','6','-','0','0',
772 'a','a','0','0','a','4','8','5','e','b','}',0 };
773
774static const BYTE emptyCatMemberInfo[] = { 0x30,0x05,0x1e,0x00,0x02,0x01,0x00 };
7760x30,0x0b,0x1e,0x06,0x00,0x66,0x00,0x6f,0x00,0x6f,0x02,0x01,0x00 };
777static const BYTE catMemberInfoWithGuid[] = {
7780x30,0x51,0x1e,0x4c,0x00,0x7b,0x00,0x38,0x00,0x62,0x00,0x63,0x00,0x39,0x00,0x36,
7790x00,0x62,0x00,0x30,0x00,0x30,0x00,0x2d,0x00,0x38,0x00,0x64,0x00,0x61,0x00,0x31,
7800x00,0x2d,0x00,0x31,0x00,0x31,0x00,0x63,0x00,0x66,0x00,0x2d,0x00,0x38,0x00,0x37,
7810x00,0x33,0x00,0x36,0x00,0x2d,0x00,0x30,0x00,0x30,0x00,0x61,0x00,0x61,0x00,0x30,
7820x00,0x30,0x00,0x61,0x00,0x34,0x00,0x38,0x00,0x35,0x00,0x65,0x00,0x62,0x00,0x7d,
7830x02,0x01,0x00 };
784
786{
788 BOOL ret;
789 DWORD size = 0;
790 LPBYTE buf;
791
792 memset(&info, 0, sizeof(info));
793
794 if (!pCryptEncodeObjectEx)
795 {
796 win_skip("CryptEncodeObjectEx() is not available. Skipping the encodeCatMemberInfo tests\n");
797 return;
798 }
799
800 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
802 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
803 if (ret)
804 {
805 ok(size == sizeof(emptyCatMemberInfo), "Unexpected size %ld\n", size);
807 "Unexpected value\n");
808 LocalFree(buf);
809 }
810 info.pwszSubjGuid = foo;
811 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
813 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
814 if (ret)
815 {
816 ok(size == sizeof(catMemberInfoWithSillyGuid), "Unexpected size %ld\n",
817 size);
819 sizeof(catMemberInfoWithSillyGuid)), "Unexpected value\n");
820 LocalFree(buf);
821 }
822 info.pwszSubjGuid = guidStr;
823 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
825 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
826 if (ret)
827 {
828 ok(size == sizeof(catMemberInfoWithGuid), "Unexpected size %ld\n",
829 size);
831 "Unexpected value\n");
832 LocalFree(buf);
833 }
834}
835
837{
838 BOOL ret;
839 LPBYTE buf;
840 DWORD size;
842
843 if (!pCryptDecodeObjectEx)
844 {
845 win_skip("CryptDecodeObjectEx() is not available. Skipping the decodeCatMemberInfo tests\n");
846 return;
847 }
848
849 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
852 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
853 if (ret)
854 {
856 ok(!info->pwszSubjGuid || !info->pwszSubjGuid[0],
857 "expected empty pwszSubjGuid\n");
858 ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %ld\n",
859 info->dwCertVersion);
860 LocalFree(buf);
861 }
862 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
865 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
866 if (ret)
867 {
869 ok(info->pwszSubjGuid && !lstrcmpW(info->pwszSubjGuid, foo),
870 "unexpected pwszSubjGuid\n");
871 ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %ld\n",
872 info->dwCertVersion);
873 LocalFree(buf);
874 }
875 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_MEMBERINFO_STRUCT,
878 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
879 if (ret)
880 {
882 ok(info->pwszSubjGuid && !lstrcmpW(info->pwszSubjGuid, guidStr),
883 "unexpected pwszSubjGuid\n");
884 ok(info->dwCertVersion == 0, "expected dwCertVersion == 0, got %ld\n",
885 info->dwCertVersion);
886 LocalFree(buf);
887 }
888}
889
890static const BYTE emptyCatNameValue[] = {
8910x30,0x07,0x1e,0x00,0x02,0x01,0x00,0x04,0x00 };
892static const BYTE catNameValueWithTag[] = {
8930x30,0x0d,0x1e,0x06,0x00,0x66,0x00,0x6f,0x00,0x6f,0x02,0x01,0x00,0x04,0x00 };
894static const BYTE catNameValueWithFlags[] = {
8950x30,0x0a,0x1e,0x00,0x02,0x04,0xf0,0x0d,0xd0,0x0d,0x04,0x00 };
896static const BYTE catNameValueWithValue[] = {
8970x30,0x0b,0x1e,0x00,0x02,0x01,0x00,0x04,0x04,0x01,0x02,0x03,0x04 };
898
899static BYTE aVal[] = { 1,2,3,4 };
900
901static void test_encodeCatNameValue(void)
902{
903 static WCHAR foo[] = { 'f','o','o',0 };
904 BOOL ret;
905 LPBYTE buf;
906 DWORD size;
908
909 memset(&value, 0, sizeof(value));
910 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
912 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
913 if (ret)
914 {
915 ok(size == sizeof(emptyCatNameValue), "Unexpected size %ld\n", size);
917 "Unexpected value\n");
918 LocalFree(buf);
919 }
920 value.pwszTag = foo;
921 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
923 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
924 if (ret)
925 {
926 ok(size == sizeof(catNameValueWithTag), "Unexpected size %ld\n", size);
928 "Unexpected value\n");
929 LocalFree(buf);
930 }
931 value.pwszTag = NULL;
932 value.fdwFlags = 0xf00dd00d;
933 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
935 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
936 if (ret)
937 {
938 ok(size == sizeof(catNameValueWithFlags), "Unexpected size %ld\n", size);
940 "Unexpected value\n");
941 LocalFree(buf);
942 }
943 value.fdwFlags = 0;
944 value.Value.cbData = sizeof(aVal);
945 value.Value.pbData = aVal;
946 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
948 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
949 if (ret)
950 {
951 ok(size == sizeof(catNameValueWithValue), "Unexpected size %ld\n", size);
953 "Unexpected value\n");
954 LocalFree(buf);
955 }
956}
957
958static void test_decodeCatNameValue(void)
959{
960 BOOL ret;
961 LPBYTE buf;
962 DWORD size;
964
965 buf = NULL;
966 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
969 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
970 if (ret)
971 {
973 ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
974 ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08lx\n",
975 value->fdwFlags);
976 ok(value->Value.cbData == 0, "expected 0-length value, got %ld\n",
977 value->Value.cbData);
978 LocalFree(buf);
979 }
980 buf = NULL;
981 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
984 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
985 if (ret)
986 {
988 ok(value->pwszTag && !lstrcmpW(value->pwszTag, foo),
989 "unexpected pwszTag\n");
990 ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08lx\n",
991 value->fdwFlags);
992 ok(value->Value.cbData == 0, "expected 0-length value, got %ld\n",
993 value->Value.cbData);
994 LocalFree(buf);
995 }
996 buf = NULL;
997 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
1000 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1001 if (ret)
1002 {
1003 value = (CAT_NAMEVALUE *)buf;
1004 ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
1005 ok(value->fdwFlags == 0xf00dd00d,
1006 "expected fdwFlags == 0xf00dd00d, got %08lx\n", value->fdwFlags);
1007 ok(value->Value.cbData == 0, "expected 0-length value, got %ld\n",
1008 value->Value.cbData);
1009 LocalFree(buf);
1010 }
1011 buf = NULL;
1012 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, CAT_NAMEVALUE_STRUCT,
1015 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1016 if (ret)
1017 {
1018 value = (CAT_NAMEVALUE *)buf;
1019 ok(!value->pwszTag || !value->pwszTag[0], "expected empty pwszTag\n");
1020 ok(value->fdwFlags == 0, "expected fdwFlags == 0, got %08lx\n",
1021 value->fdwFlags);
1022 ok(value->Value.cbData == sizeof(aVal), "unexpected size %ld\n",
1023 value->Value.cbData);
1024 ok(!memcmp(value->Value.pbData, aVal, value->Value.cbData),
1025 "unexpected value\n");
1026 LocalFree(buf);
1027 }
1028}
1029
1030static const WCHAR progName[] = { 'A',' ','p','r','o','g','r','a','m',0 };
10320x30,0x16,0xa0,0x14,0x80,0x12,0x00,0x41,0x00,0x20,0x00,0x70,0x00,0x72,0x00,0x6f,
10330x00,0x67,0x00,0x72,0x00,0x61,0x00,0x6d };
1034static WCHAR winehq[] = { 'h','t','t','p',':','/','/','w','i','n','e','h','q',
1035 '.','o','r','g','/',0 };
10370x30,0x16,0xa1,0x14,0x80,0x12,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,
10380x65,0x68,0x71,0x2e,0x6f,0x72,0x67,0x2f };
10400x30,0x16,0xa2,0x14,0x80,0x12,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x69,0x6e,
10410x65,0x68,0x71,0x2e,0x6f,0x72,0x67,0x2f };
1042
1043static void test_encodeSpOpusInfo(void)
1044{
1045 BOOL ret;
1046 LPBYTE buf;
1047 DWORD size;
1049 SPC_LINK moreInfo;
1050
1051 memset(&info, 0, sizeof(info));
1052 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1054 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
1055 if (ret)
1056 {
1057 ok(size == sizeof(emptySequence), "unexpected size %ld\n", size);
1058 ok(!memcmp(buf, emptySequence, size), "unexpected value\n");
1059 LocalFree(buf);
1060 }
1061 info.pwszProgramName = progName;
1062 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1064 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
1065 if (ret)
1066 {
1067 ok(size == sizeof(spOpusInfoWithProgramName), "unexpected size %ld\n",
1068 size);
1070 "unexpected value\n");
1071 LocalFree(buf);
1072 }
1073 info.pwszProgramName = NULL;
1074 memset(&moreInfo, 0, sizeof(moreInfo));
1075 info.pMoreInfo = &moreInfo;
1076 SetLastError(0xdeadbeef);
1077 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1080 "expected E_INVALIDARG, got %08lx\n", GetLastError());
1082 moreInfo.pwszUrl = winehq;
1083 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1085 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
1086 if (ret)
1087 {
1088 ok(size == sizeof(spOpusInfoWithMoreInfo),
1089 "unexpected size %ld\n", size);
1091 "unexpected value\n");
1092 LocalFree(buf);
1093 }
1094 info.pMoreInfo = NULL;
1095 info.pPublisherInfo = &moreInfo;
1096 ret = pCryptEncodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1098 ok(ret, "CryptEncodeObjectEx failed: %08lx\n", GetLastError());
1099 if (ret)
1100 {
1102 "unexpected size %ld\n", size);
1104 "unexpected value\n");
1105 LocalFree(buf);
1106 }
1107}
1108
1109static void test_decodeSpOpusInfo(void)
1110{
1111 BOOL ret;
1112 DWORD size;
1114
1115 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1117 &info, &size);
1118 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1119 if (ret)
1120 {
1121 ok(!info->pwszProgramName, "expected NULL\n");
1122 ok(!info->pMoreInfo, "expected NULL\n");
1123 ok(!info->pPublisherInfo, "expected NULL\n");
1124 LocalFree(info);
1125 }
1126 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1129 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1130 if (ret)
1131 {
1132 ok(info->pwszProgramName && !lstrcmpW(info->pwszProgramName,
1133 progName), "unexpected program name\n");
1134 ok(!info->pMoreInfo, "expected NULL\n");
1135 ok(!info->pPublisherInfo, "expected NULL\n");
1136 LocalFree(info);
1137 }
1138 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1141 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1142 if (ret)
1143 {
1144 ok(!info->pwszProgramName, "expected NULL\n");
1145 ok(info->pMoreInfo != NULL, "expected a value for pMoreInfo\n");
1146 if (info->pMoreInfo)
1147 {
1148 ok(info->pMoreInfo->dwLinkChoice == SPC_URL_LINK_CHOICE,
1149 "unexpected link choice %ld\n", info->pMoreInfo->dwLinkChoice);
1150 ok(!lstrcmpW(info->pMoreInfo->pwszUrl, winehq),
1151 "unexpected link value\n");
1152 }
1153 ok(!info->pPublisherInfo, "expected NULL\n");
1154 LocalFree(info);
1155 }
1156 ret = pCryptDecodeObjectEx(X509_ASN_ENCODING, SPC_SP_OPUS_INFO_STRUCT,
1159 ok(ret, "CryptDecodeObjectEx failed: %08lx\n", GetLastError());
1160 if (ret)
1161 {
1162 ok(!info->pwszProgramName, "expected NULL\n");
1163 ok(!info->pMoreInfo, "expected NULL\n");
1164 ok(info->pPublisherInfo != NULL,
1165 "expected a value for pPublisherInfo\n");
1166 if (info->pPublisherInfo)
1167 {
1168 ok(info->pPublisherInfo->dwLinkChoice == SPC_URL_LINK_CHOICE,
1169 "unexpected link choice %ld\n",
1170 info->pPublisherInfo->dwLinkChoice);
1171 ok(!lstrcmpW(info->pPublisherInfo->pwszUrl, winehq),
1172 "unexpected link value\n");
1173 }
1174 LocalFree(info);
1175 }
1176}
1177
1179{
1180 HMODULE hCrypt32 = LoadLibraryA("crypt32.dll");
1181 pCryptDecodeObjectEx = (void*)GetProcAddress(hCrypt32, "CryptDecodeObjectEx");
1182 pCryptEncodeObjectEx = (void*)GetProcAddress(hCrypt32, "CryptEncodeObjectEx");
1183
1198
1199 FreeLibrary(hCrypt32);
1200}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
const WCHAR * link
Definition: db.cpp:998
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define lstrlenW
Definition: compat.h:750
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint id
Definition: glext.h:5910
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define win_skip
Definition: minitest.h:67
static const BYTE onlyEmptyFilePEImage[]
Definition: asn.c:308
static const BYTE spcidcWithEverything[]
Definition: asn.c:549
static const BYTE catNameValueWithFlags[]
Definition: asn.c:894
static WCHAR url[]
Definition: asn.c:98
static void test_decodeSPCIndirectDataContent(void)
Definition: asn.c:663
static const BYTE emptyCatMemberInfo[]
Definition: asn.c:774
static void test_encodeSPCLink(void)
Definition: asn.c:117
static WCHAR foo[]
Definition: asn.c:769
static void test_decodeSpOpusInfo(void)
Definition: asn.c:1109
static WCHAR guidStr[]
Definition: asn.c:770
static BYTE parameters[]
Definition: asn.c:558
static void test_encodeSPCPEImage(void)
Definition: asn.c:316
static const BYTE badMonikerSPCLink[]
Definition: asn.c:205
static const BYTE emptyCatNameValue[]
Definition: asn.c:890
static const BYTE emptyIndirectData[]
Definition: asn.c:530
static BYTE aVal[]
Definition: asn.c:899
static const BYTE spOpusInfoWithProgramName[]
Definition: asn.c:1031
static void test_decodeSPCFinancialCriteria(void)
Definition: asn.c:68
static void test_encodeCatNameValue(void)
Definition: asn.c:901
static void test_decodeSPCLink(void)
Definition: asn.c:209
static const BYTE flagsAndEmptyFilePEImage[]
Definition: asn.c:310
static const BYTE catNameValueWithTag[]
Definition: asn.c:892
static const BYTE catMemberInfoWithGuid[]
Definition: asn.c:777
static const BYTE spOpusInfoWithMoreInfo[]
Definition: asn.c:1036
static void test_encodeSpOpusInfo(void)
Definition: asn.c:1043
static const BYTE fileSPCLink[]
Definition: asn.c:106
static const BYTE PCRYPT_DECODE_PARA
Definition: asn.c:29
static void test_decodeSPCPEImage(void)
Definition: asn.c:421
static WCHAR winehq[]
Definition: asn.c:1034
static void test_decodeCatMemberInfo(void)
Definition: asn.c:836
static const BYTE spcidcWithEverythingExceptDataValue[]
Definition: asn.c:544
static void test_encodeSPCFinancialCriteria(void)
Definition: asn.c:35
static const BYTE catMemberInfoWithSillyGuid[]
Definition: asn.c:775
static const BYTE void DWORD *static const void PCRYPT_ENCODE_PARA
Definition: asn.c:30
static const BYTE emptyURLSPCLink[]
Definition: asn.c:102
static const BYTE flagsAndFilePEImage[]
Definition: asn.c:312
static const WCHAR progName[]
Definition: asn.c:1030
static const BYTE trueCriteria[]
Definition: asn.c:33
static const BYTE monikerSPCLink[]
Definition: asn.c:113
static const BYTE spcidcWithDigestAndAlgorithm[]
Definition: asn.c:536
static const BYTE spOpusInfoWithPublisherInfo[]
Definition: asn.c:1039
static void test_encodeCatMemberInfo(void)
Definition: asn.c:785
static const BYTE spcidcWithOnlyDigest[]
Definition: asn.c:532
static const BYTE emptySequence[]
Definition: asn.c:305
static const BYTE void DWORD *static const void void DWORD *static const BYTE falseCriteria[]
Definition: asn.c:32
static BYTE flags[]
Definition: asn.c:306
static const BYTE onlyFlagsPEImage[]
Definition: asn.c:307
static void test_encodeSPCIndirectDataContent(void)
Definition: asn.c:560
static const BYTE emptyMonikerSPCLink[]
Definition: asn.c:109
static const BYTE spcidcWithDigestAndAlgorithmParams[]
Definition: asn.c:540
static BYTE fakeDigest[]
Definition: asn.c:555
static const BYTE catNameValueWithValue[]
Definition: asn.c:896
static void test_decodeCatNameValue(void)
Definition: asn.c:958
static const WCHAR nihongoURL[]
Definition: asn.c:100
static const BYTE urlSPCLink[]
Definition: asn.c:103
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define memset(x, y, z)
Definition: compat.h:39
BYTE * pbData
Definition: wincrypt.h:112
CRYPT_OBJID_BLOB Parameters
Definition: wincrypt.h:136
CRYPT_OBJID_BLOB Value
Definition: wincrypt.h:141
DWORD cUnusedBits
Definition: wincrypt.h:207
BYTE * pbData
Definition: wincrypt.h:206
CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm
Definition: wintrust.h:558
CRYPT_ATTRIBUTE_TYPE_VALUE Data
Definition: wintrust.h:557
CRYPT_HASH_BLOB Digest
Definition: wintrust.h:559
CRYPT_BIT_BLOB Flags
Definition: wintrust.h:551
PSPC_LINK pFile
Definition: wintrust.h:552
unsigned char * LPBYTE
Definition: typedefs.h:53
Definition: pdh_main.c:96
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define CRYPT_DECODE_ALLOC_FLAG
Definition: wincrypt.h:3612
#define szOID_OIWSEC_sha1
Definition: wincrypt.h:3253
#define CRYPT_ENCODE_ALLOC_FLAG
Definition: wincrypt.h:3599
#define WINAPI
Definition: msvc.h:6
#define OSS_BAD_PTR
Definition: winerror.h:4463
#define CRYPT_E_BAD_ENCODE
Definition: winerror.h:4419
#define OSS_TOO_LONG
Definition: winerror.h:4468
#define CRYPT_E_INVALID_IA5_STRING
Definition: winerror.h:4440
#define CRYPT_E_ASN1_EOD
Definition: winerror.h:4501
#define OSS_DATA_ERROR
Definition: winerror.h:4457
#define SPC_INDIRECT_DATA_CONTENT_STRUCT
Definition: wintrust.h:503
BYTE SPC_UUID[SPC_UUID_LENGTH]
Definition: wintrust.h:515
#define SPC_PE_IMAGE_DATA_OBJID
Definition: wintrust.h:485
#define SPC_PE_IMAGE_DATA_STRUCT
Definition: wintrust.h:504
#define SPC_SP_OPUS_INFO_STRUCT
Definition: wintrust.h:507
#define SPC_FILE_LINK_CHOICE
Definition: wintrust.h:536
#define CAT_MEMBERINFO_STRUCT
Definition: wintrust.h:512
#define SPC_MONIKER_LINK_CHOICE
Definition: wintrust.h:535
#define SPC_LINK_STRUCT
Definition: wintrust.h:505
#define SPC_FINANCIAL_CRITERIA_STRUCT
Definition: wintrust.h:502
#define CAT_NAMEVALUE_STRUCT
Definition: wintrust.h:511
#define SPC_URL_LINK_CHOICE
Definition: wintrust.h:534
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193