]>
Commit | Line | Data |
---|---|---|
f995e5bd | 1 | /* |
38fc02a7 | 2 | * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. |
f995e5bd RL |
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 <openssl/evp.h> | |
13 | #include "testutil.h" | |
14 | ||
b4250010 | 15 | static int test_provider(OSSL_LIB_CTX *ctx) |
f995e5bd RL |
16 | { |
17 | EVP_KEYMGMT *rsameth = NULL; | |
18 | const OSSL_PROVIDER *prov = NULL; | |
19 | int ok; | |
20 | ||
21 | ok = TEST_true(OSSL_PROVIDER_available(ctx, "default")) | |
22 | && TEST_ptr(rsameth = EVP_KEYMGMT_fetch(ctx, "RSA", NULL)) | |
ed576acd | 23 | && TEST_ptr(prov = EVP_KEYMGMT_get0_provider(rsameth)) |
c4e91674 | 24 | && TEST_str_eq(OSSL_PROVIDER_get0_name(prov), "default"); |
f995e5bd RL |
25 | |
26 | EVP_KEYMGMT_free(rsameth); | |
27 | return ok; | |
28 | } | |
29 | ||
30 | static int test_fallback_provider(void) | |
31 | { | |
32 | return test_provider(NULL); | |
33 | } | |
34 | ||
35 | static int test_explicit_provider(void) | |
36 | { | |
b4250010 | 37 | OSSL_LIB_CTX *ctx = NULL; |
f995e5bd RL |
38 | OSSL_PROVIDER *prov = NULL; |
39 | int ok; | |
40 | ||
b4250010 | 41 | ok = TEST_ptr(ctx = OSSL_LIB_CTX_new()) |
f995e5bd RL |
42 | && TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "default")) |
43 | && test_provider(ctx) | |
44 | && TEST_true(OSSL_PROVIDER_unload(prov)); | |
45 | ||
b4250010 | 46 | OSSL_LIB_CTX_free(ctx); |
f995e5bd RL |
47 | return ok; |
48 | } | |
49 | ||
50 | ||
51 | int setup_tests(void) | |
52 | { | |
53 | ADD_TEST(test_fallback_provider); | |
54 | ADD_TEST(test_explicit_provider); | |
55 | return 1; | |
56 | } | |
57 |