jscript: Add index, input and lastIndex properties to regexp functions results.
[wine] / dlls / crypt32 / tests / str.c
1 /*
2  * Unit test suite for crypt32.dll's Cert*ToStr and CertStrToName functions.
3  *
4  * Copyright 2006 Juan Lang, Aric Stewart for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winerror.h>
25 #include <wincrypt.h>
26
27 #include "wine/test.h"
28
29 /*#define DUMP_STRINGS*/
30 #ifdef DUMP_STRINGS
31 #include "wine/debug.h"
32 #endif
33
34 typedef struct _CertRDNAttrEncoding {
35     LPCSTR pszObjId;
36     DWORD  dwValueType;
37     CERT_RDN_VALUE_BLOB Value;
38     LPCSTR str;
39 } CertRDNAttrEncoding, *PCertRDNAttrEncoding;
40
41 typedef struct _CertRDNAttrEncodingW {
42     LPCSTR pszObjId;
43     DWORD  dwValueType;
44     CERT_RDN_VALUE_BLOB Value;
45     LPCWSTR str;
46 } CertRDNAttrEncodingW, *PCertRDNAttrEncodingW;
47
48 static BYTE bin1[] = { 0x55, 0x53 };
49 static BYTE bin2[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x73, 0x6f, 0x74,
50  0x61 };
51 static BYTE bin3[] = { 0x4d, 0x69, 0x6e, 0x6e, 0x65, 0x61, 0x70, 0x6f,
52  0x6c, 0x69, 0x73 };
53 static BYTE bin4[] = { 0x43, 0x6f, 0x64, 0x65, 0x57, 0x65, 0x61, 0x76,
54  0x65, 0x72, 0x73 };
55 static BYTE bin5[] = { 0x57, 0x69, 0x6e, 0x65, 0x20, 0x44, 0x65, 0x76,
56  0x65, 0x6c, 0x6f, 0x70, 0x6d, 0x65, 0x6e, 0x74 };
57 static BYTE bin6[] = { 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73,
58  0x74 };
59 static BYTE bin7[] = { 0x61, 0x72, 0x69, 0x63, 0x40, 0x63, 0x6f, 0x64,
60  0x65, 0x77, 0x65, 0x61, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x63, 0x6f, 0x6d };
61
62 static const BYTE cert[] = 
63 {0x30,0x82,0x2,0xbb,0x30,0x82,0x2,0x24,0x2,0x9,0x0,0xe3,0x5a,0x10,0xf1,0xfc,
64  0x4b,0xf3,0xa2,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
65  0x0,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,
66  0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,
67  0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0x7,0x13,0xb,0x4d,
68  0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,0x73,0x31,0x14,0x30,0x12,0x6,0x3,
69  0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,0x57,0x65,0x61,0x76,0x65,0x72,0x73,
70  0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,0x13,0x10,0x57,0x69,0x6e,0x65,0x20,
71  0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,0x65,0x6e,0x74,0x31,0x12,0x30,0x10,
72  0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,
73  0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x9,0x1,0x16,
74  0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,0x65,0x77,0x65,0x61,0x76,0x65,
75  0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x1e,0x17,0xd,0x30,0x36,0x30,0x31,0x32,
76  0x35,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x17,0xd,0x30,0x36,0x30,0x32,0x32,
77  0x34,0x31,0x33,0x35,0x37,0x32,0x34,0x5a,0x30,0x81,0xa1,0x31,0xb,0x30,0x9,0x6,
78  0x3,0x55,0x4,0x6,0x13,0x2,0x55,0x53,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x8,
79  0x13,0x9,0x4d,0x69,0x6e,0x6e,0x65,0x73,0x6f,0x74,0x61,0x31,0x14,0x30,0x12,0x6,
80  0x3,0x55,0x4,0x7,0x13,0xb,0x4d,0x69,0x6e,0x6e,0x65,0x61,0x70,0x6f,0x6c,0x69,
81  0x73,0x31,0x14,0x30,0x12,0x6,0x3,0x55,0x4,0xa,0x13,0xb,0x43,0x6f,0x64,0x65,
82  0x57,0x65,0x61,0x76,0x65,0x72,0x73,0x31,0x19,0x30,0x17,0x6,0x3,0x55,0x4,0xb,
83  0x13,0x10,0x57,0x69,0x6e,0x65,0x20,0x44,0x65,0x76,0x65,0x6c,0x6f,0x70,0x6d,
84  0x65,0x6e,0x74,0x31,0x12,0x30,0x10,0x6,0x3,0x55,0x4,0x3,0x13,0x9,0x6c,0x6f,
85  0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x31,0x23,0x30,0x21,0x6,0x9,0x2a,0x86,0x48,
86  0x86,0xf7,0xd,0x1,0x9,0x1,0x16,0x14,0x61,0x72,0x69,0x63,0x40,0x63,0x6f,0x64,
87  0x65,0x77,0x65,0x61,0x76,0x65,0x72,0x73,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9f,
88  0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x1,0x5,0x0,0x3,0x81,
89  0x8d,0x0,0x30,0x81,0x89,0x2,0x81,0x81,0x0,0x9b,0xb5,0x8f,0xaf,0xfb,0x9a,0xaf,
90  0xdc,0xa2,0x4d,0xb1,0xc8,0x72,0x44,0xef,0x79,0x7f,0x28,0xb6,0xfe,0x50,0xdc,
91  0x8a,0xf7,0x11,0x2f,0x90,0x70,0xed,0xa4,0xa9,0xd,0xbf,0x82,0x3e,0x56,0xd8,
92  0x36,0xb6,0x9,0x52,0x83,0xab,0x65,0x95,0x0,0xe2,0xea,0x3c,0x4f,0x85,0xb8,0xc,
93  0x41,0x42,0x77,0x5c,0x9d,0x44,0xeb,0xcf,0x7d,0x60,0x64,0x7a,0x6c,0x4c,0xac,
94  0x4a,0x9a,0x23,0x25,0x15,0xd7,0x92,0xb4,0x10,0xe7,0x95,0xad,0x4b,0x93,0xda,
95  0x6a,0x76,0xe0,0xa5,0xd2,0x13,0x8,0x12,0x30,0x68,0xde,0xb9,0x5b,0x6e,0x2a,
96  0x97,0x43,0xaa,0x7b,0x22,0x33,0x34,0xb1,0xca,0x5d,0x19,0xd8,0x42,0x26,0x45,
97  0xc6,0xe9,0x1d,0xee,0x7,0xc2,0x27,0x95,0x87,0xd8,0x12,0xec,0x4b,0x16,0x9f,0x2,
98  0x3,0x1,0x0,0x1,0x30,0xd,0x6,0x9,0x2a,0x86,0x48,0x86,0xf7,0xd,0x1,0x1,0x4,0x5,
99  0x0,0x3,0x81,0x81,0x0,0x96,0xf9,0xf6,0x6a,0x3d,0xd9,0xca,0x6e,0xd5,0x76,0x73,
100  0xab,0x75,0xc1,0xcc,0x98,0x44,0xc3,0xa9,0x90,0x68,0x88,0x76,0xb9,0xeb,0xb6,
101  0xbe,0x60,0x62,0xb9,0x67,0x1e,0xcc,0xf4,0xe1,0xe7,0x6c,0xc8,0x67,0x3f,0x1d,
102  0xf3,0x68,0x86,0x30,0xee,0xaa,0x92,0x61,0x37,0xd7,0x82,0x90,0x28,0xaa,0x7a,
103  0x18,0x88,0x60,0x14,0x88,0x75,0xc0,0x4a,0x4e,0x7d,0x48,0xe7,0x3,0xa6,0xfd,
104  0xd7,0xce,0x3c,0xe5,0x9b,0xaf,0x2f,0xdc,0xbb,0x7c,0xbd,0x20,0x49,0xd9,0x68,
105  0x37,0xeb,0x5d,0xbb,0xe2,0x6d,0x66,0xe3,0x11,0xc1,0xa7,0x88,0x49,0xc6,0x6f,
106  0x65,0xd3,0xce,0xae,0x26,0x19,0x3,0x2e,0x4f,0x78,0xa5,0xa,0x97,0x7e,0x4f,0xc4,
107  0x91,0x8a,0xf8,0x5,0xef,0x5b,0x3b,0x49,0xbf,0x5f,0x2b};
108
109 static char issuerStr[] =
110  "US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com";
111 static char issuerStrSemicolon[] =
112  "US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com";
113 static char issuerStrCRLF[] =
114  "US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com";
115 static char subjectStr[] =
116  "2.5.4.6=US, 2.5.4.8=Minnesota, 2.5.4.7=Minneapolis, 2.5.4.10=CodeWeavers, 2.5.4.11=Wine Development, 2.5.4.3=localhost, 1.2.840.113549.1.9.1=aric@codeweavers.com";
117 static char subjectStrSemicolon[] =
118  "2.5.4.6=US; 2.5.4.8=Minnesota; 2.5.4.7=Minneapolis; 2.5.4.10=CodeWeavers; 2.5.4.11=Wine Development; 2.5.4.3=localhost; 1.2.840.113549.1.9.1=aric@codeweavers.com";
119 static char subjectStrCRLF[] =
120  "2.5.4.6=US\r\n2.5.4.8=Minnesota\r\n2.5.4.7=Minneapolis\r\n2.5.4.10=CodeWeavers\r\n2.5.4.11=Wine Development\r\n2.5.4.3=localhost\r\n1.2.840.113549.1.9.1=aric@codeweavers.com";
121 static char x500SubjectStr[] = "C=US, S=Minnesota, L=Minneapolis, O=CodeWeavers, OU=Wine Development, CN=localhost, E=aric@codeweavers.com";
122 static char x500SubjectStrSemicolonReverse[] = "E=aric@codeweavers.com; CN=localhost; OU=Wine Development; O=CodeWeavers; L=Minneapolis; S=Minnesota; C=US";
123 static WCHAR issuerStrW[] = {
124  'U','S',',',' ','M','i','n','n','e','s','o','t','a',',',' ','M','i','n','n',
125  'e','a','p','o','l','i','s',',',' ','C','o','d','e','W','e','a','v','e','r',
126  's',',',' ','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',
127  ',',' ','l','o','c','a','l','h','o','s','t',',',' ','a','r','i','c','@','c',
128  'o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
129 static WCHAR issuerStrSemicolonW[] = {
130  'U','S',';',' ','M','i','n','n','e','s','o','t','a',';',' ','M','i','n','n',
131  'e','a','p','o','l','i','s',';',' ','C','o','d','e','W','e','a','v','e','r',
132  's',';',' ','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',
133  ';',' ','l','o','c','a','l','h','o','s','t',';',' ','a','r','i','c','@','c',
134  'o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
135 static WCHAR issuerStrCRLFW[] = {
136  'U','S','\r','\n','M','i','n','n','e','s','o','t','a','\r','\n','M','i','n',
137  'n','e','a','p','o','l','i','s','\r','\n','C','o','d','e','W','e','a','v','e',
138  'r','s','\r','\n','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n',
139  't','\r','\n','l','o','c','a','l','h','o','s','t','\r','\n','a','r','i','c',
140  '@','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0 };
141 static WCHAR subjectStrW[] = {
142  '2','.','5','.','4','.','6','=','U','S',',',' ','2','.','5','.','4','.','8',
143  '=','M','i','n','n','e','s','o','t','a',',',' ','2','.','5','.','4','.','7',
144  '=','M','i','n','n','e','a','p','o','l','i','s',',',' ','2','.','5','.','4',
145  '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s',',',' ','2','.',
146  '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
147  'm','e','n','t',',',' ','2','.','5','.','4','.','3','=','l','o','c','a','l',
148  'h','o','s','t',',',' ','1','.','2','.','8','4','0','.','1','1','3','5','4',
149  '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
150  'a','v','e','r','s','.','c','o','m',0 };
151 static WCHAR subjectStrSemicolonW[] = {
152  '2','.','5','.','4','.','6','=','U','S',';',' ','2','.','5','.','4','.','8',
153  '=','M','i','n','n','e','s','o','t','a',';',' ','2','.','5','.','4','.','7',
154  '=','M','i','n','n','e','a','p','o','l','i','s',';',' ','2','.','5','.','4',
155  '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s',';',' ','2','.',
156  '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
157  'm','e','n','t',';',' ','2','.','5','.','4','.','3','=','l','o','c','a','l',
158  'h','o','s','t',';',' ','1','.','2','.','8','4','0','.','1','1','3','5','4',
159  '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
160  'a','v','e','r','s','.','c','o','m',0 };
161 static WCHAR subjectStrCRLFW[] = {
162  '2','.','5','.','4','.','6','=','U','S','\r','\n','2','.','5','.','4','.','8',
163  '=','M','i','n','n','e','s','o','t','a','\r','\n','2','.','5','.','4','.','7',
164  '=','M','i','n','n','e','a','p','o','l','i','s','\r','\n','2','.','5','.','4',
165  '.','1','0','=','C','o','d','e','W','e','a','v','e','r','s','\r','\n','2','.',
166  '5','.','4','.','1','1','=','W','i','n','e',' ','D','e','v','e','l','o','p',
167  'm','e','n','t','\r','\n','2','.','5','.','4','.','3','=','l','o','c','a','l',
168  'h','o','s','t','\r','\n','1','.','2','.','8','4','0','.','1','1','3','5','4',
169  '9','.','1','.','9','.','1','=','a','r','i','c','@','c','o','d','e','w','e',
170  'a','v','e','r','s','.','c','o','m',0 };
171 static WCHAR x500SubjectStrSemicolonReverseW[] = {
172  'E','=','a','r','i','c','@','c','o','d','e','w','e','a','v','e','r','s','.','c',
173  'o','m',';',' ','C','N','=','l','o','c','a','l','h','o','s','t',';',' ','O','U',
174  '=','W','i','n','e',' ','D','e','v','e','l','o','p','m','e','n','t',';',' ','O',
175  '=','C','o','d','e','W','e','a','v','e','r','s',';',' ','L','=','M','i','n','n',
176  'e','a','p','o','l','i','s',';',' ','S','=','M','i','n','n','e','s','o','t','a',
177  ';',' ','C','=','U','S',0 };
178
179 typedef BOOL (WINAPI *CryptDecodeObjectFunc)(DWORD, LPCSTR, const BYTE *,
180  DWORD, DWORD, void *, DWORD *);
181 typedef DWORD (WINAPI *CertNameToStrAFunc)(DWORD,LPVOID,DWORD,LPSTR,DWORD);
182 typedef DWORD (WINAPI *CertNameToStrWFunc)(DWORD,LPVOID,DWORD,LPWSTR,DWORD);
183 typedef DWORD (WINAPI *CertRDNValueToStrAFunc)(DWORD, PCERT_RDN_VALUE_BLOB,
184  LPSTR, DWORD);
185 typedef DWORD (WINAPI *CertRDNValueToStrWFunc)(DWORD, PCERT_RDN_VALUE_BLOB,
186  LPWSTR, DWORD);
187 typedef BOOL (WINAPI *CertStrToNameAFunc)(DWORD dwCertEncodingType,
188  LPCSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded,
189  DWORD *pcbEncoded, LPCSTR *ppszError);
190 typedef BOOL (WINAPI *CertStrToNameWFunc)(DWORD dwCertEncodingType,
191  LPCWSTR pszX500, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded,
192  DWORD *pcbEncoded, LPCWSTR *ppszError);
193
194 static HMODULE dll;
195 static CertNameToStrAFunc pCertNameToStrA;
196 static CertNameToStrWFunc pCertNameToStrW;
197 static CryptDecodeObjectFunc pCryptDecodeObject;
198 static CertRDNValueToStrAFunc pCertRDNValueToStrA;
199 static CertRDNValueToStrWFunc pCertRDNValueToStrW;
200 static CertStrToNameAFunc pCertStrToNameA;
201 static CertStrToNameWFunc pCertStrToNameW;
202
203 static void test_CertRDNValueToStrA(void)
204 {
205     CertRDNAttrEncoding attrs[] = {
206      { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
207        { sizeof(bin1), bin1 }, "US" },
208      { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
209        { sizeof(bin2), bin2 }, "Minnesota" },
210      { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
211        { sizeof(bin3), bin3 }, "Minneapolis" },
212      { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
213        { sizeof(bin4), bin4 }, "CodeWeavers" },
214      { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
215        { sizeof(bin5), bin5 }, "Wine Development" },
216      { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
217        { sizeof(bin6), bin6 }, "localhost" },
218      { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
219        { sizeof(bin7), bin7 }, "aric@codeweavers.com" },
220     };
221     DWORD i, ret;
222     char buffer[2000];
223     CERT_RDN_VALUE_BLOB blob = { 0, NULL };
224
225     if (!pCertRDNValueToStrA) return;
226
227     /* This crashes
228     ret = pCertRDNValueToStrA(0, NULL, NULL, 0);
229      */
230     /* With empty input, it generates the empty string */
231     SetLastError(0xdeadbeef);
232     ret = pCertRDNValueToStrA(0, &blob, NULL, 0);
233     ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
234     ret = pCertRDNValueToStrA(0, &blob, buffer, sizeof(buffer));
235     ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
236     ok(!buffer[0], "Expected empty string\n");
237
238     for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
239     {
240         ret = pCertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value,
241          buffer, sizeof(buffer));
242         ok(ret == strlen(attrs[i].str) + 1, "Expected length %d, got %d\n",
243          lstrlenA(attrs[i].str) + 1, ret);
244         ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n", attrs[i].str,
245          buffer);
246     }
247 }
248
249 static void test_CertRDNValueToStrW(void)
250 {
251     static const WCHAR usW[] = { 'U','S',0 };
252     static const WCHAR minnesotaW[] = { 'M','i','n','n','e','s','o','t','a',0 };
253     static const WCHAR minneapolisW[] = { 'M','i','n','n','e','a','p','o','l',
254      'i','s',0 };
255     static const WCHAR codeweaversW[] = { 'C','o','d','e','W','e','a','v','e',
256      'r','s',0 };
257     static const WCHAR wineDevW[] = { 'W','i','n','e',' ','D','e','v','e','l',
258      'o','p','m','e','n','t',0 };
259     static const WCHAR localhostW[] = { 'l','o','c','a','l','h','o','s','t',0 };
260     static const WCHAR aricW[] = { 'a','r','i','c','@','c','o','d','e','w','e',
261      'a','v','e','r','s','.','c','o','m',0 };
262     CertRDNAttrEncodingW attrs[] = {
263      { "2.5.4.6", CERT_RDN_PRINTABLE_STRING,
264        { sizeof(bin1), bin1 }, usW },
265      { "2.5.4.8", CERT_RDN_PRINTABLE_STRING,
266        { sizeof(bin2), bin2 }, minnesotaW },
267      { "2.5.4.7", CERT_RDN_PRINTABLE_STRING,
268        { sizeof(bin3), bin3 }, minneapolisW },
269      { "2.5.4.10", CERT_RDN_PRINTABLE_STRING,
270        { sizeof(bin4), bin4 }, codeweaversW },
271      { "2.5.4.11", CERT_RDN_PRINTABLE_STRING,
272        { sizeof(bin5), bin5 }, wineDevW },
273      { "2.5.4.3", CERT_RDN_PRINTABLE_STRING,
274        { sizeof(bin6), bin6 }, localhostW },
275      { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
276        { sizeof(bin7), bin7 }, aricW },
277     };
278     DWORD i, ret;
279     WCHAR buffer[2000];
280     CERT_RDN_VALUE_BLOB blob = { 0, NULL };
281
282     if (!pCertRDNValueToStrW)
283     {
284         win_skip("CertRDNValueToStrW is not available\n");
285         return;
286     }
287
288     /* This crashes
289     ret = pCertRDNValueToStrW(0, NULL, NULL, 0);
290      */
291     /* With empty input, it generates the empty string */
292     SetLastError(0xdeadbeef);
293     ret = pCertRDNValueToStrW(0, &blob, NULL, 0);
294     ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
295     ret = pCertRDNValueToStrW(0, &blob, buffer,
296      sizeof(buffer) / sizeof(buffer[0]));
297     ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
298     ok(!buffer[0], "Expected empty string\n");
299
300     for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
301     {
302         ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value,
303          buffer, sizeof(buffer) / sizeof(buffer[0]));
304         ok(ret == lstrlenW(attrs[i].str) + 1, "Expected length %d, got %d\n",
305          lstrlenW(attrs[i].str) + 1, ret);
306         ok(!lstrcmpW(buffer, attrs[i].str), "Unexpected value\n");
307 #ifdef DUMP_STRINGS
308         trace("Expected %s, got %s\n",
309          wine_dbgstr_w(attrs[i].str), wine_dbgstr_w(buffer));
310 #endif
311     }
312 }
313
314 static void test_NameToStrConversionA(PCERT_NAME_BLOB pName, DWORD dwStrType,
315  LPCSTR expected, BOOL todo)
316 {
317     char buffer[2000] = { 0 };
318     DWORD i;
319
320     i = pCertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, NULL, 0);
321     if (todo)
322         todo_wine
323         ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
324          lstrlenA(expected) + 1, i);
325     else
326         ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
327          lstrlenA(expected) + 1, i);
328     i = pCertNameToStrA(X509_ASN_ENCODING,pName, dwStrType, buffer,
329      sizeof(buffer));
330     if (todo)
331         todo_wine
332         ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
333          lstrlenA(expected) + 1, i);
334     else
335         ok(i == strlen(expected) + 1, "Expected %d chars, got %d\n",
336          lstrlenA(expected) + 1, i);
337     if (todo)
338         todo_wine
339         ok(!strcmp(buffer, expected), "Expected %s, got %s\n", expected,
340          buffer);
341     else
342         ok(!strcmp(buffer, expected), "Expected %s, got %s\n", expected,
343          buffer);
344 }
345
346 static BYTE encodedSimpleCN[] = {
347 0x30,0x0c,0x31,0x0a,0x30,0x08,0x06,0x03,0x55,0x04,0x03,0x13,0x01,0x31 };
348 static BYTE encodedSingleQuotedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
349  0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x27,0x31,0x27 };
350 static BYTE encodedSpacedCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,
351  0x55,0x04,0x03,0x13,0x03,0x20,0x31,0x20 };
352 static BYTE encodedQuotedCN[] = { 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,
353  0x55, 0x04,0x03,0x1e,0x06,0x00,0x22,0x00,0x31,0x00,0x22, };
354 static BYTE encodedMultipleAttrCN[] = { 0x30,0x0e,0x31,0x0c,0x30,0x0a,
355  0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x31,0x2b,0x32 };
356 static BYTE encodedCommaCN[] = {
357 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x2c,
358 0x62 };
359 static BYTE encodedEqualCN[] = {
360 0x30,0x0e,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x61,0x3d,
361 0x62 };
362 static BYTE encodedLessThanCN[] = {
363 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3c
364 };
365 static BYTE encodedGreaterThanCN[] = {
366 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3e
367 };
368 static BYTE encodedHashCN[] = {
369 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x23
370 };
371 static BYTE encodedSemiCN[] = {
372 0x30,0x0d,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x03,0x1e,0x02,0x00,0x3b
373 };
374
375 static void test_CertNameToStrA(void)
376 {
377     PCCERT_CONTEXT context;
378     CERT_NAME_BLOB blob;
379
380     if (!pCertNameToStrA)
381     {
382         win_skip("CertNameToStrA is not available\n");
383         return;
384     }
385
386     context = CertCreateCertificateContext(X509_ASN_ENCODING, cert,
387      sizeof(cert));
388     ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
389      GetLastError());
390     if (context)
391     {
392         DWORD ret;
393
394         /* This crashes
395         ret = pCertNameToStrA(0, NULL, 0, NULL, 0);
396          */
397         /* Test with a bogus encoding type */
398         SetLastError(0xdeadbeef);
399         ret = pCertNameToStrA(0, &context->pCertInfo->Issuer, 0, NULL, 0);
400         ok(ret == 1 && GetLastError() == ERROR_FILE_NOT_FOUND,
401          "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %d - %08x\n",
402          ret, GetLastError());
403         SetLastError(0xdeadbeef);
404         ret = pCertNameToStrA(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
405          0, NULL, 0);
406         ok(ret && GetLastError() == ERROR_SUCCESS,
407          "Expected positive return and ERROR_SUCCESS, got %d - %08x\n",
408          ret, GetLastError());
409
410         test_NameToStrConversionA(&context->pCertInfo->Issuer,
411          CERT_SIMPLE_NAME_STR, issuerStr, FALSE);
412         test_NameToStrConversionA(&context->pCertInfo->Issuer,
413          CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
414          issuerStrSemicolon, FALSE);
415         test_NameToStrConversionA(&context->pCertInfo->Issuer,
416          CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
417          issuerStrCRLF, FALSE);
418         test_NameToStrConversionA(&context->pCertInfo->Subject,
419          CERT_OID_NAME_STR, subjectStr, FALSE);
420         test_NameToStrConversionA(&context->pCertInfo->Subject,
421          CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
422          subjectStrSemicolon, FALSE);
423         test_NameToStrConversionA(&context->pCertInfo->Subject,
424          CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
425          subjectStrCRLF, FALSE);
426         test_NameToStrConversionA(&context->pCertInfo->Subject,
427          CERT_X500_NAME_STR, x500SubjectStr, FALSE);
428         test_NameToStrConversionA(&context->pCertInfo->Subject,
429          CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG,
430          x500SubjectStrSemicolonReverse, FALSE);
431
432         CertFreeCertificateContext(context);
433     }
434     blob.pbData = encodedSimpleCN;
435     blob.cbData = sizeof(encodedSimpleCN);
436     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=1", FALSE);
437     blob.pbData = encodedSingleQuotedCN;
438     blob.cbData = sizeof(encodedSingleQuotedCN);
439     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN='1'", FALSE);
440     blob.pbData = encodedSpacedCN;
441     blob.cbData = sizeof(encodedSpacedCN);
442     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\" 1 \"", FALSE);
443     blob.pbData = encodedQuotedCN;
444     blob.cbData = sizeof(encodedQuotedCN);
445     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"\"\"1\"\"\"",
446      FALSE);
447     blob.pbData = encodedMultipleAttrCN;
448     blob.cbData = sizeof(encodedMultipleAttrCN);
449     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"1+2\"", FALSE);
450     blob.pbData = encodedCommaCN;
451     blob.cbData = sizeof(encodedCommaCN);
452     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a,b\"", FALSE);
453     blob.pbData = encodedEqualCN;
454     blob.cbData = sizeof(encodedEqualCN);
455     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"a=b\"", FALSE);
456     blob.pbData = encodedLessThanCN;
457     blob.cbData = sizeof(encodedLessThanCN);
458     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"<\"", FALSE);
459     blob.pbData = encodedGreaterThanCN;
460     blob.cbData = sizeof(encodedGreaterThanCN);
461     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\">\"", FALSE);
462     blob.pbData = encodedHashCN;
463     blob.cbData = sizeof(encodedHashCN);
464     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\"#\"", FALSE);
465     blob.pbData = encodedSemiCN;
466     blob.cbData = sizeof(encodedSemiCN);
467     test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=\";\"", FALSE);
468 }
469
470 static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType,
471  LPCWSTR expected)
472 {
473     WCHAR buffer[2000] = { 0 };
474     DWORD i;
475
476     i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, NULL, 0);
477     ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
478      lstrlenW(expected) + 1, i);
479     i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer,
480      sizeof(buffer) / sizeof(buffer[0]));
481     ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
482      lstrlenW(expected) + 1, i);
483     ok(!lstrcmpW(buffer, expected), "Unexpected value\n");
484 #ifdef DUMP_STRINGS
485     trace("Expected %s, got %s\n",
486      wine_dbgstr_w(expected), wine_dbgstr_w(buffer));
487 #endif
488 }
489
490 static void test_CertNameToStrW(void)
491 {
492     PCCERT_CONTEXT context;
493
494     if (!pCertNameToStrW)
495     {
496         win_skip("CertNameToStrW is not available\n");
497         return;
498     }
499
500     context = CertCreateCertificateContext(X509_ASN_ENCODING, cert,
501      sizeof(cert));
502     ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
503      GetLastError());
504     if (context)
505     {
506         DWORD ret;
507
508         /* This crashes
509         ret = pCertNameToStrW(0, NULL, 0, NULL, 0);
510          */
511         /* Test with a bogus encoding type */
512         SetLastError(0xdeadbeef);
513         ret = pCertNameToStrW(0, &context->pCertInfo->Issuer, 0, NULL, 0);
514         ok(ret == 1 && GetLastError() == ERROR_FILE_NOT_FOUND,
515          "Expected retval 1 and ERROR_FILE_NOT_FOUND, got %d - %08x\n",
516          ret, GetLastError());
517         SetLastError(0xdeadbeef);
518         ret = pCertNameToStrW(X509_ASN_ENCODING, &context->pCertInfo->Issuer,
519          0, NULL, 0);
520         ok(ret && GetLastError() == ERROR_SUCCESS,
521          "Expected positive return and ERROR_SUCCESS, got %d - %08x\n",
522          ret, GetLastError());
523
524         test_NameToStrConversionW(&context->pCertInfo->Issuer,
525          CERT_SIMPLE_NAME_STR, issuerStrW);
526         test_NameToStrConversionW(&context->pCertInfo->Issuer,
527          CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
528          issuerStrSemicolonW);
529         test_NameToStrConversionW(&context->pCertInfo->Issuer,
530          CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
531          issuerStrCRLFW);
532         test_NameToStrConversionW(&context->pCertInfo->Subject,
533          CERT_OID_NAME_STR, subjectStrW);
534         test_NameToStrConversionW(&context->pCertInfo->Subject,
535          CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG,
536          subjectStrSemicolonW);
537         test_NameToStrConversionW(&context->pCertInfo->Subject,
538          CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
539          subjectStrCRLFW);
540         test_NameToStrConversionW(&context->pCertInfo->Subject,
541          CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG, x500SubjectStrSemicolonReverseW);
542
543         CertFreeCertificateContext(context);
544     }
545 }
546
547 struct StrToNameA
548 {
549     LPCSTR x500;
550     DWORD encodedSize;
551     const BYTE *encoded;
552 };
553
554 static const struct StrToNameA namesA[] = {
555  { "CN=1", sizeof(encodedSimpleCN), encodedSimpleCN },
556  { "CN=\"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
557  { "CN = \"1\"", sizeof(encodedSimpleCN), encodedSimpleCN },
558  { "CN='1'", sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
559  { "CN=\" 1 \"", sizeof(encodedSpacedCN), encodedSpacedCN },
560  { "CN=\"\"\"1\"\"\"", sizeof(encodedQuotedCN), encodedQuotedCN },
561  { "CN=\"1+2\"", sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
562  { "CN=\"a,b\"", sizeof(encodedCommaCN), encodedCommaCN },
563  { "CN=\"a=b\"", sizeof(encodedEqualCN), encodedEqualCN },
564  { "CN=\"<\"", sizeof(encodedLessThanCN), encodedLessThanCN },
565  { "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
566  { "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
567  { "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
568 };
569
570 static void test_CertStrToNameA(void)
571 {
572     BOOL ret;
573     DWORD size, i;
574     BYTE buf[100];
575
576     if (!pCertStrToNameA)
577     {
578         win_skip("CertStrToNameA is not available\n");
579         return;
580     }
581
582     /* Crash
583     ret = pCertStrToNameA(0, NULL, 0, NULL, NULL, NULL, NULL);
584      */
585     ret = pCertStrToNameA(0, NULL, 0, NULL, NULL, &size, NULL);
586     ok(!ret, "Expected failure\n");
587     ret = pCertStrToNameA(0, "bogus", 0, NULL, NULL, &size, NULL);
588     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
589      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
590     ret = pCertStrToNameA(0, "foo=1", 0, NULL, NULL, &size, NULL);
591     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
592      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
593     ret = pCertStrToNameA(0, "CN=1", 0, NULL, NULL, &size, NULL);
594     ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
595      "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
596     ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1", 0, NULL, NULL, &size, NULL);
597     ok(ret, "CertStrToNameA failed: %08x\n", GetLastError());
598     size = sizeof(buf);
599     ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=\"\"1\"\"", 0, NULL, buf, &size,
600      NULL);
601     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
602      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
603     ret = pCertStrToNameA(X509_ASN_ENCODING, "CN=1+2", 0, NULL, buf,
604      &size, NULL);
605     todo_wine ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
606      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
607     for (i = 0; i < sizeof(namesA) / sizeof(namesA[0]); i++)
608     {
609         size = sizeof(buf);
610         ret = pCertStrToNameA(X509_ASN_ENCODING, namesA[i].x500, 0, NULL, buf,
611          &size, NULL);
612         ok(ret, "CertStrToNameA failed on string %s: %08x\n", namesA[i].x500,
613          GetLastError());
614         ok(size == namesA[i].encodedSize,
615          "Expected size %d, got %d\n", namesA[i].encodedSize, size);
616         if (ret)
617             ok(!memcmp(buf, namesA[i].encoded, namesA[i].encodedSize),
618              "Unexpected value for string %s\n", namesA[i].x500);
619     }
620 }
621
622 struct StrToNameW
623 {
624     LPCWSTR x500;
625     DWORD encodedSize;
626     const BYTE *encoded;
627 };
628
629 static const WCHAR badlyQuotedCN_W[] = { 'C','N','=','"','"','1','"','"',0 };
630 static const WCHAR simpleCN_W[] = { 'C','N','=','1',0 };
631 static const WCHAR simpleCN2_W[] = { 'C','N','=','"','1','"',0 };
632 static const WCHAR simpleCN3_W[] = { 'C','N',' ','=',' ','"','1','"',0 };
633 static const WCHAR singledQuotedCN_W[] = { 'C','N','=','\'','1','\'',0 };
634 static const WCHAR spacedCN_W[] = { 'C','N','=','"',' ','1',' ','"',0 };
635 static const WCHAR quotedCN_W[] = { 'C','N','=','"','"','"','1','"','"','"',0 };
636 static const WCHAR multipleAttrCN_W[] = { 'C','N','=','"','1','+','2','"',0 };
637 static const WCHAR japaneseCN_W[] = { 'C','N','=',0x226f,0x575b,0 };
638 static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06,
639  0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
640 static const WCHAR commaCN_W[] = { 'C','N','=','"','a',',','b','"',0 };
641 static const WCHAR equalCN_W[] = { 'C','N','=','"','a','=','b','"',0 };
642 static const WCHAR lessThanCN_W[] = { 'C','N','=','"','<','"',0 };
643 static const WCHAR greaterThanCN_W[] = { 'C','N','=','"','>','"',0 };
644 static const WCHAR hashCN_W[] = { 'C','N','=','"','#','"',0 };
645 static const WCHAR semiCN_W[] = { 'C','N','=','"',';','"',0 };
646
647 static const struct StrToNameW namesW[] = {
648  { simpleCN_W, sizeof(encodedSimpleCN), encodedSimpleCN },
649  { simpleCN2_W, sizeof(encodedSimpleCN), encodedSimpleCN },
650  { simpleCN3_W, sizeof(encodedSimpleCN), encodedSimpleCN },
651  { singledQuotedCN_W, sizeof(encodedSingleQuotedCN), encodedSingleQuotedCN },
652  { spacedCN_W, sizeof(encodedSpacedCN), encodedSpacedCN },
653  { quotedCN_W, sizeof(encodedQuotedCN), encodedQuotedCN },
654  { multipleAttrCN_W, sizeof(encodedMultipleAttrCN), encodedMultipleAttrCN },
655  { japaneseCN_W, sizeof(encodedJapaneseCN), encodedJapaneseCN },
656  { commaCN_W, sizeof(encodedCommaCN), encodedCommaCN },
657  { equalCN_W, sizeof(encodedEqualCN), encodedEqualCN },
658  { lessThanCN_W, sizeof(encodedLessThanCN), encodedLessThanCN },
659  { greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
660  { hashCN_W, sizeof(encodedHashCN), encodedHashCN },
661  { semiCN_W, sizeof(encodedSemiCN), encodedSemiCN },
662 };
663
664 static void test_CertStrToNameW(void)
665 {
666     static const WCHAR bogusW[] = { 'b','o','g','u','s',0 };
667     static const WCHAR fooW[] = { 'f','o','o','=','1',0 };
668     BOOL ret;
669     DWORD size, i;
670     LPCWSTR errorPtr;
671     BYTE buf[100];
672
673     if (!pCertStrToNameW)
674     {
675         win_skip("CertStrToNameW is not available\n");
676         return;
677     }
678
679     /* Crash
680     ret = pCertStrToNameW(0, NULL, 0, NULL, NULL, NULL, NULL);
681      */
682     ret = pCertStrToNameW(0, NULL, 0, NULL, NULL, &size, NULL);
683     ok(!ret, "Expected failure\n");
684     ret = pCertStrToNameW(0, bogusW, 0, NULL, NULL, &size, NULL);
685     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
686      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
687     ret = pCertStrToNameW(0, fooW, 0, NULL, NULL, &size, NULL);
688     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
689      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
690     ret = pCertStrToNameW(0, simpleCN_W, 0, NULL, NULL, &size, NULL);
691     ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
692      "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
693     ret = pCertStrToNameW(X509_ASN_ENCODING, simpleCN_W, 0, NULL, NULL, &size,
694      NULL);
695     ok(ret, "CertStrToNameW failed: %08x\n", GetLastError());
696     size = sizeof(buf);
697     ret = pCertStrToNameW(X509_ASN_ENCODING, badlyQuotedCN_W, 0, NULL, buf,
698      &size, NULL);
699     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
700      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
701     ret = pCertStrToNameW(X509_ASN_ENCODING, badlyQuotedCN_W, 0, NULL, buf,
702      &size, &errorPtr);
703     ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
704      "Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
705     ok(errorPtr && *errorPtr == '1', "Expected first error character was 1\n");
706     for (i = 0; i < sizeof(namesW) / sizeof(namesW[0]); i++)
707     {
708         size = sizeof(buf);
709         ret = pCertStrToNameW(X509_ASN_ENCODING, namesW[i].x500, 0, NULL, buf,
710          &size, NULL);
711         ok(ret, "Index %d: CertStrToNameW failed: %08x\n", i, GetLastError());
712         ok(size == namesW[i].encodedSize,
713          "Index %d: expected size %d, got %d\n", i, namesW[i].encodedSize,
714          size);
715         if (ret)
716             ok(!memcmp(buf, namesW[i].encoded, size),
717              "Index %d: unexpected value\n", i);
718     }
719 }
720
721 START_TEST(str)
722 {
723     dll = GetModuleHandleA("Crypt32.dll");
724
725     pCertNameToStrA = (CertNameToStrAFunc)GetProcAddress(dll,"CertNameToStrA");
726     pCertNameToStrW = (CertNameToStrWFunc)GetProcAddress(dll,"CertNameToStrW");
727     pCertRDNValueToStrA = (CertRDNValueToStrAFunc)GetProcAddress(dll,
728      "CertRDNValueToStrA");
729     pCertRDNValueToStrW = (CertRDNValueToStrWFunc)GetProcAddress(dll,
730      "CertRDNValueToStrW");
731     pCryptDecodeObject = (CryptDecodeObjectFunc)GetProcAddress(dll,
732      "CryptDecodeObject");
733     pCertStrToNameA = (CertStrToNameAFunc)GetProcAddress(dll,"CertStrToNameA");
734     pCertStrToNameW = (CertStrToNameWFunc)GetProcAddress(dll,"CertStrToNameW");
735
736     test_CertRDNValueToStrA();
737     test_CertRDNValueToStrW();
738     test_CertNameToStrA();
739     test_CertNameToStrW();
740     test_CertStrToNameA();
741     test_CertStrToNameW();
742 }