]>
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 <openssl/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(const char *name) | |
24 | { | |
25 | OSSL_PROVIDER *prov = NULL; | |
26 | const char *greeting = NULL; | |
27 | char expected_greeting[256]; | |
28 | ||
f4b4574f | 29 | BIO_snprintf(expected_greeting, sizeof(expected_greeting), |
866cc233 SL |
30 | "Hello OpenSSL %.20s, greetings from %s!", |
31 | OPENSSL_VERSION_STR, name); | |
021a6552 RL |
32 | |
33 | return | |
34 | TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name)) | |
35 | && TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request)) | |
8c4412ed RL |
36 | && TEST_ptr(greeting = greeting_request[0].data) |
37 | && TEST_size_t_gt(greeting_request[0].data_size, 0) | |
021a6552 RL |
38 | && TEST_str_eq(greeting, expected_greeting) |
39 | && TEST_true(OSSL_PROVIDER_unload(prov)); | |
40 | } | |
41 | ||
42 | static int test_builtin_provider(void) | |
43 | { | |
44 | const char *name = "p_test_builtin"; | |
45 | ||
46 | return | |
47 | TEST_true(OSSL_PROVIDER_add_builtin(NULL, name, | |
80889e41 | 48 | PROVIDER_INIT_FUNCTION_NAME)) |
021a6552 RL |
49 | && test_provider(name); |
50 | } | |
51 | ||
2a2bc6fc | 52 | #ifndef NO_PROVIDER_MODULE |
021a6552 RL |
53 | static int test_loaded_provider(void) |
54 | { | |
55 | const char *name = "p_test"; | |
56 | ||
57 | return test_provider(name); | |
58 | } | |
59 | #endif | |
60 | ||
61 | int setup_tests(void) | |
62 | { | |
63 | ADD_TEST(test_builtin_provider); | |
2a2bc6fc | 64 | #ifndef NO_PROVIDER_MODULE |
021a6552 RL |
65 | ADD_TEST(test_loaded_provider); |
66 | #endif | |
67 | return 1; | |
68 | } | |
69 |