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
24 #include "wine/debug.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
;
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
;
63 if (IsEqualGUID(iid
, &IID_ICryptographicBufferStatics
))
65 IUnknown_AddRef(iface
);
66 *out
= &factory
->ICryptographicBufferStatics_iface
;
70 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
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
);
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
);
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
);
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
);
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
);
116 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_ActivateInstance(
117 IActivationFactory
*iface
, IInspectable
**instance
)
119 FIXME("iface %p, instance %p stub!\n", iface
, instance
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
211 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_ConvertStringToBinary(
212 ICryptographicBufferStatics
*iface
, HSTRING value
, BinaryStringEncoding encoding
,
215 FIXME("iface %p, value %p, encoding %d, buffer %p stub!\n", iface
, value
, encoding
, buffer
);
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
);
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
,
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
);
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
;