comctl32/tests: Flush events before testing edit control IME messages.
[wine.git] / dlls / cryptowinrt / main.c
blob720b137e4a93e63400dc1720a00ecaa5622a7d81
1 /*
2 * Copyright 2022 Nikolay Sivov for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winstring.h"
26 #include "wine/debug.h"
27 #include "objbase.h"
29 #include "initguid.h"
30 #include "activation.h"
32 #include "bcrypt.h"
34 #define WIDL_using_Windows_Foundation
35 #define WIDL_using_Windows_Foundation_Collections
36 #include "windows.foundation.h"
37 #define WIDL_using_Windows_Storage_Streams
38 #include "windows.storage.streams.h"
39 #define WIDL_using_Windows_Security_Cryptography
40 #include "windows.security.cryptography.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(crypto);
44 static const char *debugstr_hstring(HSTRING hstr)
46 const WCHAR *str;
47 UINT32 len;
48 if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)";
49 str = WindowsGetStringRawBuffer(hstr, &len);
50 return wine_dbgstr_wn(str, len);
53 struct cryptobuffer_factory
55 IActivationFactory IActivationFactory_iface;
56 ICryptographicBufferStatics ICryptographicBufferStatics_iface;
57 LONG refcount;
60 static inline struct cryptobuffer_factory *impl_from_IActivationFactory(IActivationFactory *iface)
62 return CONTAINING_RECORD(iface, struct cryptobuffer_factory, IActivationFactory_iface);
65 static inline struct cryptobuffer_factory *impl_from_ICryptographicBufferStatics(ICryptographicBufferStatics *iface)
67 return CONTAINING_RECORD(iface, struct cryptobuffer_factory, ICryptographicBufferStatics_iface);
70 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_QueryInterface(
71 IActivationFactory *iface, REFIID iid, void **out)
73 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
75 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
77 if (IsEqualGUID(iid, &IID_IUnknown) ||
78 IsEqualGUID(iid, &IID_IInspectable) ||
79 IsEqualGUID(iid, &IID_IAgileObject) ||
80 IsEqualGUID(iid, &IID_IActivationFactory))
82 IUnknown_AddRef(iface);
83 *out = &factory->IActivationFactory_iface;
84 return S_OK;
87 if (IsEqualGUID(iid, &IID_ICryptographicBufferStatics))
89 IUnknown_AddRef(iface);
90 *out = &factory->ICryptographicBufferStatics_iface;
91 return S_OK;
94 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
95 *out = NULL;
96 return E_NOINTERFACE;
99 static ULONG STDMETHODCALLTYPE cryptobuffer_factory_AddRef(IActivationFactory *iface)
101 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
102 ULONG refcount = InterlockedIncrement(&factory->refcount);
104 TRACE("iface %p, refcount %lu.\n", iface, refcount);
106 return refcount;
109 static ULONG STDMETHODCALLTYPE cryptobuffer_factory_Release(IActivationFactory *iface)
111 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
112 ULONG refcount = InterlockedDecrement(&factory->refcount);
114 TRACE("iface %p, refcount %lu.\n", iface, refcount);
116 return refcount;
119 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetIids(
120 IActivationFactory *iface, ULONG *iid_count, IID **iids)
122 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
123 return E_NOTIMPL;
126 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetRuntimeClassName(
127 IActivationFactory *iface, HSTRING *class_name)
129 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
130 return E_NOTIMPL;
133 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetTrustLevel(
134 IActivationFactory *iface, TrustLevel *trust_level)
136 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
137 return E_NOTIMPL;
140 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_ActivateInstance(
141 IActivationFactory *iface, IInspectable **instance)
143 FIXME("iface %p, instance %p stub!\n", iface, instance);
144 return E_NOTIMPL;
147 static const struct IActivationFactoryVtbl cryptobuffer_factory_vtbl =
149 cryptobuffer_factory_QueryInterface,
150 cryptobuffer_factory_AddRef,
151 cryptobuffer_factory_Release,
152 /* IInspectable methods */
153 cryptobuffer_factory_GetIids,
154 cryptobuffer_factory_GetRuntimeClassName,
155 cryptobuffer_factory_GetTrustLevel,
156 /* IActivationFactory methods */
157 cryptobuffer_factory_ActivateInstance,
160 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_QueryInterface(
161 ICryptographicBufferStatics *iface, REFIID iid, void **object)
163 struct cryptobuffer_factory *factory = impl_from_ICryptographicBufferStatics(iface);
164 return IActivationFactory_QueryInterface(&factory->IActivationFactory_iface, iid, object);
167 static ULONG STDMETHODCALLTYPE cryptobuffer_statics_AddRef(ICryptographicBufferStatics *iface)
169 struct cryptobuffer_factory *factory = impl_from_ICryptographicBufferStatics(iface);
170 return IActivationFactory_AddRef(&factory->IActivationFactory_iface);
173 static ULONG STDMETHODCALLTYPE cryptobuffer_statics_Release(ICryptographicBufferStatics *iface)
175 struct cryptobuffer_factory *factory = impl_from_ICryptographicBufferStatics(iface);
176 return IActivationFactory_Release(&factory->IActivationFactory_iface);
179 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GetIids(
180 ICryptographicBufferStatics *iface, ULONG *iid_count, IID **iids)
182 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
183 return E_NOTIMPL;
186 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GetRuntimeClassName(
187 ICryptographicBufferStatics *iface, HSTRING *class_name)
189 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
190 return E_NOTIMPL;
193 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GetTrustLevel(
194 ICryptographicBufferStatics *iface, TrustLevel *trust_level)
196 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
197 return E_NOTIMPL;
200 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_Compare(
201 ICryptographicBufferStatics *iface, IBuffer *object1, IBuffer *object2, boolean *is_equal)
203 FIXME("iface %p, object1 %p, object2 %p, is_equal %p stub!\n", iface, object1, object2, is_equal);
205 return E_NOTIMPL;
208 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GenerateRandom(
209 ICryptographicBufferStatics *iface, UINT32 length, IBuffer **buffer)
211 FIXME("iface %p, length %u, buffer %p stub!\n", iface, length, buffer);
213 return E_NOTIMPL;
216 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GenerateRandomNumber(
217 ICryptographicBufferStatics *iface, UINT32 *value)
219 TRACE("iface %p, value %p.\n", iface, value);
221 BCryptGenRandom(NULL, (UCHAR *)value, sizeof(*value), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
222 return S_OK;
225 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_CreateFromByteArray(
226 ICryptographicBufferStatics *iface, UINT32 value_size, BYTE *value, IBuffer **buffer)
228 FIXME("iface %p, value_size %u, value %p, buffer %p stub!\n", iface, value_size, value, buffer);
230 return E_NOTIMPL;
233 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_CopyToByteArray(
234 ICryptographicBufferStatics *iface, IBuffer *buffer, UINT32 *value_size, BYTE **value)
236 FIXME("iface %p, buffer %p, value_size %p, value %p stub!\n", iface, buffer, value_size, value);
238 return E_NOTIMPL;
241 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_DecodeFromHexString(
242 ICryptographicBufferStatics *iface, HSTRING value, IBuffer **buffer)
244 FIXME("iface %p, value %p, buffer %p stub!\n", iface, value, buffer);
246 return E_NOTIMPL;
249 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_EncodeToHexString(
250 ICryptographicBufferStatics *iface, IBuffer *buffer, HSTRING *value)
252 FIXME("iface %p, buffer %p, value %p stub!\n", iface, buffer, value);
254 return E_NOTIMPL;
257 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_DecodeFromBase64String(
258 ICryptographicBufferStatics *iface, HSTRING value, IBuffer **buffer)
260 FIXME("iface %p, value %p, buffer %p stub!\n", iface, value, buffer);
262 return E_NOTIMPL;
265 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_EncodeToBase64String(
266 ICryptographicBufferStatics *iface, IBuffer *buffer, HSTRING *value)
268 FIXME("iface %p, buffer %p, value %p stub!\n", iface, buffer, value);
270 return E_NOTIMPL;
273 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_ConvertStringToBinary(
274 ICryptographicBufferStatics *iface, HSTRING value, BinaryStringEncoding encoding,
275 IBuffer **buffer)
277 FIXME("iface %p, value %p, encoding %d, buffer %p stub!\n", iface, value, encoding, buffer);
279 return E_NOTIMPL;
282 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_ConvertBinaryToString(
283 ICryptographicBufferStatics *iface, BinaryStringEncoding encoding, IBuffer *buffer, HSTRING *value)
285 FIXME("iface %p, encoding %d, buffer %p, value %p stub!\n", iface, encoding, buffer, value);
287 return E_NOTIMPL;
290 static const struct ICryptographicBufferStaticsVtbl cryptobuffer_statics_vtbl =
292 cryptobuffer_statics_QueryInterface,
293 cryptobuffer_statics_AddRef,
294 cryptobuffer_statics_Release,
295 /* IInspectable methods */
296 cryptobuffer_statics_GetIids,
297 cryptobuffer_statics_GetRuntimeClassName,
298 cryptobuffer_statics_GetTrustLevel,
299 /* ICryptographicBufferStatics methods */
300 cryptobuffer_statics_Compare,
301 cryptobuffer_statics_GenerateRandom,
302 cryptobuffer_statics_GenerateRandomNumber,
303 cryptobuffer_statics_CreateFromByteArray,
304 cryptobuffer_statics_CopyToByteArray,
305 cryptobuffer_statics_DecodeFromHexString,
306 cryptobuffer_statics_EncodeToHexString,
307 cryptobuffer_statics_DecodeFromBase64String,
308 cryptobuffer_statics_EncodeToBase64String,
309 cryptobuffer_statics_ConvertStringToBinary,
310 cryptobuffer_statics_ConvertBinaryToString,
313 static struct cryptobuffer_factory cryptobuffer_factory =
315 .IActivationFactory_iface.lpVtbl = &cryptobuffer_factory_vtbl,
316 .ICryptographicBufferStatics_iface.lpVtbl = &cryptobuffer_statics_vtbl,
317 .refcount = 1,
320 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out)
322 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out);
323 return CLASS_E_CLASSNOTAVAILABLE;
326 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
328 const WCHAR *name = WindowsGetStringRawBuffer(classid, NULL);
330 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid), factory);
332 *factory = NULL;
334 if (!wcscmp(name, RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer))
336 *factory = &cryptobuffer_factory.IActivationFactory_iface;
337 IUnknown_AddRef(*factory);
340 if (*factory) return S_OK;
341 return CLASS_E_CLASSNOTAVAILABLE;