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 const char *debugstr_hstring(HSTRING hstr
)
38 if (hstr
&& !((ULONG_PTR
)hstr
>> 16)) return "(invalid)";
39 str
= WindowsGetStringRawBuffer(hstr
, &len
);
40 return wine_dbgstr_wn(str
, len
);
43 struct cryptobuffer_factory
45 IActivationFactory IActivationFactory_iface
;
46 ICryptographicBufferStatics ICryptographicBufferStatics_iface
;
50 static inline struct cryptobuffer_factory
*impl_from_IActivationFactory(IActivationFactory
*iface
)
52 return CONTAINING_RECORD(iface
, struct cryptobuffer_factory
, IActivationFactory_iface
);
55 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_QueryInterface(
56 IActivationFactory
*iface
, REFIID iid
, void **out
)
58 struct cryptobuffer_factory
*factory
= impl_from_IActivationFactory(iface
);
60 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
62 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
63 IsEqualGUID(iid
, &IID_IInspectable
) ||
64 IsEqualGUID(iid
, &IID_IAgileObject
) ||
65 IsEqualGUID(iid
, &IID_IActivationFactory
))
67 IUnknown_AddRef(iface
);
68 *out
= &factory
->IActivationFactory_iface
;
72 if (IsEqualGUID(iid
, &IID_ICryptographicBufferStatics
))
74 IUnknown_AddRef(iface
);
75 *out
= &factory
->ICryptographicBufferStatics_iface
;
79 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
84 static ULONG STDMETHODCALLTYPE
cryptobuffer_factory_AddRef(IActivationFactory
*iface
)
86 struct cryptobuffer_factory
*factory
= impl_from_IActivationFactory(iface
);
87 ULONG refcount
= InterlockedIncrement(&factory
->refcount
);
89 TRACE("iface %p, refcount %lu.\n", iface
, refcount
);
94 static ULONG STDMETHODCALLTYPE
cryptobuffer_factory_Release(IActivationFactory
*iface
)
96 struct cryptobuffer_factory
*factory
= impl_from_IActivationFactory(iface
);
97 ULONG refcount
= InterlockedDecrement(&factory
->refcount
);
99 TRACE("iface %p, refcount %lu.\n", iface
, refcount
);
104 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_GetIids(
105 IActivationFactory
*iface
, ULONG
*iid_count
, IID
**iids
)
107 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
111 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_GetRuntimeClassName(
112 IActivationFactory
*iface
, HSTRING
*class_name
)
114 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
118 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_GetTrustLevel(
119 IActivationFactory
*iface
, TrustLevel
*trust_level
)
121 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
125 static HRESULT STDMETHODCALLTYPE
cryptobuffer_factory_ActivateInstance(
126 IActivationFactory
*iface
, IInspectable
**instance
)
128 FIXME("iface %p, instance %p stub!\n", iface
, instance
);
132 static const struct IActivationFactoryVtbl cryptobuffer_factory_vtbl
=
134 cryptobuffer_factory_QueryInterface
,
135 cryptobuffer_factory_AddRef
,
136 cryptobuffer_factory_Release
,
137 /* IInspectable methods */
138 cryptobuffer_factory_GetIids
,
139 cryptobuffer_factory_GetRuntimeClassName
,
140 cryptobuffer_factory_GetTrustLevel
,
141 /* IActivationFactory methods */
142 cryptobuffer_factory_ActivateInstance
,
145 DEFINE_IINSPECTABLE(cryptobuffer_statics
, ICryptographicBufferStatics
, struct cryptobuffer_factory
, IActivationFactory_iface
);
147 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_Compare(
148 ICryptographicBufferStatics
*iface
, IBuffer
*object1
, IBuffer
*object2
, boolean
*is_equal
)
150 FIXME("iface %p, object1 %p, object2 %p, is_equal %p stub!\n", iface
, object1
, object2
, is_equal
);
155 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_GenerateRandom(
156 ICryptographicBufferStatics
*iface
, UINT32 length
, IBuffer
**buffer
)
158 FIXME("iface %p, length %u, buffer %p stub!\n", iface
, length
, buffer
);
163 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_GenerateRandomNumber(
164 ICryptographicBufferStatics
*iface
, UINT32
*value
)
166 TRACE("iface %p, value %p.\n", iface
, value
);
168 BCryptGenRandom(NULL
, (UCHAR
*)value
, sizeof(*value
), BCRYPT_USE_SYSTEM_PREFERRED_RNG
);
172 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_CreateFromByteArray(
173 ICryptographicBufferStatics
*iface
, UINT32 value_size
, BYTE
*value
, IBuffer
**buffer
)
175 FIXME("iface %p, value_size %u, value %p, buffer %p stub!\n", iface
, value_size
, value
, buffer
);
180 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_CopyToByteArray(
181 ICryptographicBufferStatics
*iface
, IBuffer
*buffer
, UINT32
*value_size
, BYTE
**value
)
183 FIXME("iface %p, buffer %p, value_size %p, value %p stub!\n", iface
, buffer
, value_size
, value
);
188 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_DecodeFromHexString(
189 ICryptographicBufferStatics
*iface
, HSTRING value
, IBuffer
**buffer
)
191 FIXME("iface %p, value %p, buffer %p stub!\n", iface
, value
, buffer
);
196 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_EncodeToHexString(
197 ICryptographicBufferStatics
*iface
, IBuffer
*buffer
, HSTRING
*value
)
199 FIXME("iface %p, buffer %p, value %p stub!\n", iface
, buffer
, value
);
204 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_DecodeFromBase64String(
205 ICryptographicBufferStatics
*iface
, HSTRING value
, IBuffer
**buffer
)
207 FIXME("iface %p, value %p, buffer %p stub!\n", iface
, value
, buffer
);
212 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_EncodeToBase64String(
213 ICryptographicBufferStatics
*iface
, IBuffer
*buffer
, HSTRING
*value
)
215 FIXME("iface %p, buffer %p, value %p stub!\n", iface
, buffer
, value
);
220 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_ConvertStringToBinary(
221 ICryptographicBufferStatics
*iface
, HSTRING value
, BinaryStringEncoding encoding
,
224 FIXME("iface %p, value %p, encoding %d, buffer %p stub!\n", iface
, value
, encoding
, buffer
);
229 static HRESULT STDMETHODCALLTYPE
cryptobuffer_statics_ConvertBinaryToString(
230 ICryptographicBufferStatics
*iface
, BinaryStringEncoding encoding
, IBuffer
*buffer
, HSTRING
*value
)
232 FIXME("iface %p, encoding %d, buffer %p, value %p stub!\n", iface
, encoding
, buffer
, value
);
237 static const struct ICryptographicBufferStaticsVtbl cryptobuffer_statics_vtbl
=
239 cryptobuffer_statics_QueryInterface
,
240 cryptobuffer_statics_AddRef
,
241 cryptobuffer_statics_Release
,
242 /* IInspectable methods */
243 cryptobuffer_statics_GetIids
,
244 cryptobuffer_statics_GetRuntimeClassName
,
245 cryptobuffer_statics_GetTrustLevel
,
246 /* ICryptographicBufferStatics methods */
247 cryptobuffer_statics_Compare
,
248 cryptobuffer_statics_GenerateRandom
,
249 cryptobuffer_statics_GenerateRandomNumber
,
250 cryptobuffer_statics_CreateFromByteArray
,
251 cryptobuffer_statics_CopyToByteArray
,
252 cryptobuffer_statics_DecodeFromHexString
,
253 cryptobuffer_statics_EncodeToHexString
,
254 cryptobuffer_statics_DecodeFromBase64String
,
255 cryptobuffer_statics_EncodeToBase64String
,
256 cryptobuffer_statics_ConvertStringToBinary
,
257 cryptobuffer_statics_ConvertBinaryToString
,
260 static struct cryptobuffer_factory cryptobuffer_factory
=
262 .IActivationFactory_iface
.lpVtbl
= &cryptobuffer_factory_vtbl
,
263 .ICryptographicBufferStatics_iface
.lpVtbl
= &cryptobuffer_statics_vtbl
,
267 IActivationFactory
*cryptobuffer_activation_factory
= &cryptobuffer_factory
.IActivationFactory_iface
;
269 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID riid
, void **out
)
271 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid
), debugstr_guid(riid
), out
);
272 return CLASS_E_CLASSNOTAVAILABLE
;
275 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
277 const WCHAR
*name
= WindowsGetStringRawBuffer(classid
, NULL
);
279 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid
), factory
);
283 if (!wcscmp(name
, RuntimeClass_Windows_Security_Cryptography_CryptographicBuffer
))
284 IActivationFactory_QueryInterface(cryptobuffer_activation_factory
, &IID_IActivationFactory
, (void **)factory
);
285 if (!wcscmp(name
, RuntimeClass_Windows_Security_Credentials_KeyCredentialManager
))
286 IActivationFactory_QueryInterface(credentials_activation_factory
, &IID_IActivationFactory
, (void **)factory
);
288 if (*factory
) return S_OK
;
289 return CLASS_E_CLASSNOTAVAILABLE
;