]>
Commit | Line | Data |
---|---|---|
021a6552 RL |
1 | /* |
2 | * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | #include <stddef.h> | |
11 | #include "internal/provider.h" | |
12 | #include "testutil.h" | |
13 | ||
14 | extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME; | |
15 | ||
16 | static char buf[256]; | |
17 | static size_t buf_l = 0; | |
18 | static OSSL_PARAM greeting_request[] = { | |
19 | { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l }, | |
20 | { NULL, 0, NULL, 0, NULL } | |
21 | }; | |
22 | ||
23 | static int test_provider(OSSL_PROVIDER *prov) | |
24 | { | |
25 | const char *name = NULL; | |
26 | const char *greeting = NULL; | |
27 | char expected_greeting[256]; | |
28 | int ret = 0; | |
29 | ||
30 | if (!TEST_ptr(name = ossl_provider_name(prov))) | |
31 | return 0; | |
32 | ||
33 | snprintf(expected_greeting, sizeof(expected_greeting), | |
34 | "Hello OpenSSL %.20s, greetings from %s!", | |
35 | OPENSSL_VERSION_STR, name); | |
36 | ||
37 | ret = | |
38 | TEST_true(ossl_provider_activate(prov)) | |
39 | && TEST_true(ossl_provider_get_params(prov, greeting_request)) | |
40 | && TEST_ptr(greeting = greeting_request[0].buffer) | |
41 | && TEST_size_t_gt(greeting_request[0].buffer_size, 0) | |
42 | && TEST_str_eq(greeting, expected_greeting); | |
43 | ||
44 | ossl_provider_free(prov); | |
45 | return ret; | |
46 | } | |
47 | ||
48 | static int test_builtin_provider(void) | |
49 | { | |
50 | const char *name = "p_test_builtin"; | |
51 | OSSL_PROVIDER *prov = NULL; | |
52 | ||
53 | return | |
54 | TEST_ptr(prov = | |
55 | ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME)) | |
56 | && test_provider(prov); | |
57 | } | |
58 | ||
59 | #ifndef OPENSSL_NO_SHARED | |
60 | static int test_loaded_provider(void) | |
61 | { | |
62 | const char *name = "p_test"; | |
63 | OSSL_PROVIDER *prov = NULL; | |
64 | ||
65 | return | |
66 | TEST_ptr(prov = ossl_provider_new(NULL, name, NULL)) | |
67 | && test_provider(prov); | |
68 | } | |
69 | #endif | |
70 | ||
71 | int setup_tests(void) | |
72 | { | |
73 | ADD_TEST(test_builtin_provider); | |
74 | #ifndef OPENSSL_NO_SHARED | |
75 | ADD_TEST(test_loaded_provider); | |
76 | #endif | |
77 | return 1; | |
78 | } | |
79 |