Debian Codegraph @

winpr/libwinpr/ncrypt/test/TestNCryptProviders.c

raw
1 /**
2 * WinPR: Windows Portable Runtime
3 * Test for NCrypt library
4 *
5 * Copyright 2021 David Fort <[email protected]>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 #include <winpr/error.h>
20 #include <winpr/ncrypt.h>
21 #include <winpr/string.h>
22 #include <winpr/wlog.h>
23 #include <winpr/smartcard.h>
24
25 #define TAG "testNCrypt"
26
27 int TestNCryptProviders(int argc, char* argv[])
28 {
29 SECURITY_STATUS status = 0;
30 DWORD nproviders = 0;
31 NCryptProviderName* providers = nullptr;
32
33 WINPR_UNUSED(argc);
34 WINPR_UNUSED(argv);
35
36 status = NCryptEnumStorageProviders(&nproviders, &providers, NCRYPT_SILENT_FLAG);
37 if (status != ERROR_SUCCESS)
38 return -1;
39
40 for (DWORD i = 0; i < nproviders; i++)
41 {
42 const NCryptProviderName* provider = &providers[i];
43 char providerNameStr[256] = WINPR_C_ARRAY_INIT;
44
45 (void)ConvertWCharToUtf8(provider->pszName, providerNameStr, ARRAYSIZE(providerNameStr));
46 printf("%d: %s\n", i, providerNameStr);
47 }
48
49 NCryptFreeBuffer(providers);
50 return 0;
51 }