cmd: DIR command outputs free space for the path.
[wine.git] / dlls / cryptowinrt / main.c
blobe6f811b5d128d43d9da4222beec8b7e02aeab7c6
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 "initguid.h"
20 #include "private.h"
22 #include <assert.h>
24 #include "wine/debug.h"
25 #include "objbase.h"
27 #include "bcrypt.h"
29 #define WIDL_using_Windows_Security_Cryptography
30 #include "windows.security.cryptography.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(crypto);
34 struct cryptobuffer_factory
36 IActivationFactory IActivationFactory_iface;
37 ICryptographicBufferStatics ICryptographicBufferStatics_iface;
38 LONG refcount;
41 static inline struct cryptobuffer_factory *impl_from_IActivationFactory(IActivationFactory *iface)
43 return CONTAINING_RECORD(iface, struct cryptobuffer_factory, IActivationFactory_iface);
46 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_QueryInterface(
47 IActivationFactory *iface, REFIID iid, void **out)
49 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
51 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
53 if (IsEqualGUID(iid, &IID_IUnknown) ||
54 IsEqualGUID(iid, &IID_IInspectable) ||
55 IsEqualGUID(iid, &IID_IAgileObject) ||
56 IsEqualGUID(iid, &IID_IActivationFactory))
58 IUnknown_AddRef(iface);
59 *out = &factory->IActivationFactory_iface;
60 return S_OK;
63 if (IsEqualGUID(iid, &IID_ICryptographicBufferStatics))
65 IUnknown_AddRef(iface);
66 *out = &factory->ICryptographicBufferStatics_iface;
67 return S_OK;
70 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
71 *out = NULL;
72 return E_NOINTERFACE;
75 static ULONG STDMETHODCALLTYPE cryptobuffer_factory_AddRef(IActivationFactory *iface)
77 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
78 ULONG refcount = InterlockedIncrement(&factory->refcount);
80 TRACE("iface %p, refcount %lu.\n", iface, refcount);
82 return refcount;
85 static ULONG STDMETHODCALLTYPE cryptobuffer_factory_Release(IActivationFactory *iface)
87 struct cryptobuffer_factory *factory = impl_from_IActivationFactory(iface);
88 ULONG refcount = InterlockedDecrement(&factory->refcount);
90 TRACE("iface %p, refcount %lu.\n", iface, refcount);
92 return refcount;
95 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetIids(
96 IActivationFactory *iface, ULONG *iid_count, IID **iids)
98 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
99 return E_NOTIMPL;
102 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetRuntimeClassName(
103 IActivationFactory *iface, HSTRING *class_name)
105 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
106 return E_NOTIMPL;
109 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_GetTrustLevel(
110 IActivationFactory *iface, TrustLevel *trust_level)
112 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
113 return E_NOTIMPL;
116 static HRESULT STDMETHODCALLTYPE cryptobuffer_factory_ActivateInstance(
117 IActivationFactory *iface, IInspectable **instance)
119 FIXME("iface %p, instance %p stub!\n", iface, instance);
120 return E_NOTIMPL;
123 static const struct IActivationFactoryVtbl cryptobuffer_factory_vtbl =
125 cryptobuffer_factory_QueryInterface,
126 cryptobuffer_factory_AddRef,
127 cryptobuffer_factory_Release,
128 /* IInspectable methods */
129 cryptobuffer_factory_GetIids,
130 cryptobuffer_factory_GetRuntimeClassName,
131 cryptobuffer_factory_GetTrustLevel,
132 /* IActivationFactory methods */
133 cryptobuffer_factory_ActivateInstance,
136 DEFINE_IINSPECTABLE(cryptobuffer_statics, ICryptographicBufferStatics, struct cryptobuffer_factory, IActivationFactory_iface);
138 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_Compare(
139 ICryptographicBufferStatics *iface, IBuffer *object1, IBuffer *object2, boolean *is_equal)
141 FIXME("iface %p, object1 %p, object2 %p, is_equal %p stub!\n", iface, object1, object2, is_equal);
143 return E_NOTIMPL;
146 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GenerateRandom(
147 ICryptographicBufferStatics *iface, UINT32 length, IBuffer **buffer)
149 FIXME("iface %p, length %u, buffer %p stub!\n", iface, length, buffer);
151 return E_NOTIMPL;
154 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_GenerateRandomNumber(
155 ICryptographicBufferStatics *iface, UINT32 *value)
157 TRACE("iface %p, value %p.\n", iface, value);
159 BCryptGenRandom(NULL, (UCHAR *)value, sizeof(*value), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
160 return S_OK;
163 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_CreateFromByteArray(
164 ICryptographicBufferStatics *iface, UINT32 value_size, BYTE *value, IBuffer **buffer)
166 FIXME("iface %p, value_size %u, value %p, buffer %p stub!\n", iface, value_size, value, buffer);
168 return E_NOTIMPL;
171 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_CopyToByteArray(
172 ICryptographicBufferStatics *iface, IBuffer *buffer, UINT32 *value_size, BYTE **value)
174 FIXME("iface %p, buffer %p, value_size %p, value %p stub!\n", iface, buffer, value_size, value);
176 return E_NOTIMPL;
179 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_DecodeFromHexString(
180 ICryptographicBufferStatics *iface, HSTRING value, IBuffer **buffer)
182 FIXME("iface %p, value %p, buffer %p stub!\n", iface, value, buffer);
184 return E_NOTIMPL;
187 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_EncodeToHexString(
188 ICryptographicBufferStatics *iface, IBuffer *buffer, HSTRING *value)
190 FIXME("iface %p, buffer %p, value %p stub!\n", iface, buffer, value);
192 return E_NOTIMPL;
195 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_DecodeFromBase64String(
196 ICryptographicBufferStatics *iface, HSTRING value, IBuffer **buffer)
198 FIXME("iface %p, value %p, buffer %p stub!\n", iface, value, buffer);
200 return E_NOTIMPL;
203 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_EncodeToBase64String(
204 ICryptographicBufferStatics *iface, IBuffer *buffer, HSTRING *value)
206 FIXME("iface %p, buffer %p, value %p stub!\n", iface, buffer, value);
208 return E_NOTIMPL;
211 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_ConvertStringToBinary(
212 ICryptographicBufferStatics *iface, HSTRING value, BinaryStringEncoding encoding,
213 IBuffer **buffer)
215 FIXME("iface %p, value %p, encoding %d, buffer %p stub!\n", iface, value, encoding, buffer);
217 return E_NOTIMPL;
220 static HRESULT STDMETHODCALLTYPE cryptobuffer_statics_ConvertBinaryToString(
221 ICryptographicBufferStatics *iface, BinaryStringEncoding encoding, IBuffer *buffer, HSTRING *value)
223 FIXME("iface %p, encoding %d, buffer %p, value %p stub!\n", iface, encoding, buffer, value);
225 return E_NOTIMPL;
228 static const struct ICryptographicBufferStaticsVtbl cryptobuffer_statics_vtbl =
230 cryptobuffer_statics_QueryInterface,
231 cryptobuffer_statics_AddRef,
232 cryptobuffer_statics_Release,
233 /* IInspectable methods */
234 cryptobuffer_statics_GetIids,
235 cryptobuffer_statics_GetRuntimeClassName,
236 cryptobuffer_statics_GetTrustLevel,
237 /* ICryptographicBufferStatics methods */
238 cryptobuffer_statics_Compare,
239 cryptobuffer_statics_GenerateRandom,
240 cryptobuffer_statics_GenerateRandomNumber,
241 cryptobuffer_statics_CreateFromByteArray,
242 cryptobuffer_statics_CopyToByteArray,
243 cryptobuffer_statics_DecodeFromHexString,
244 cryptobuffer_statics_EncodeToHexString,
245 cryptobuffer_statics_DecodeFromBase64String,
246 cryptobuffer_statics_EncodeToBase64String,
247 cryptobuffer_statics_ConvertStringToBinary,
248 cryptobuffer_statics_ConvertBinaryToString,
251 static struct cryptobuffer_factory cryptobuffer_factory =
253 .IActivationFactory_iface.lpVtbl = &cryptobuffer_factory_vtbl,
254 .ICryptographicBufferStatics_iface.lpVtbl = &cryptobuffer_statics_vtbl,
255 .refcount = 1,
258 IActivationFactory *cryptobuffer_activation_factory = &cryptobuffer_factory.IActivationFactory_iface;
260 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out)
262 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out);
263 return CLASS_E_CLASSNOTAVAILABLE;
266 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
268 const WCHAR *name = WindowsGetStringRawBuffer(classid, NULL);
270 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid), factory);
272 *factory = NULL;
274 if (!wcscmp(name, RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer))
275 IActivationFactory_QueryInterface(cryptobuffer_activation_factory, &IID_IActivationFactory, (void **)factory);
276 if (!wcscmp(name, RuntimeClass_Windows_Security_Credentials_KeyCredentialManager))
277 IActivationFactory_QueryInterface(credentials_activation_factory, &IID_IActivationFactory, (void **)factory);
279 if (*factory) return S_OK;
280 return CLASS_E_CLASSNOTAVAILABLE;