1 | /*
|
---|
2 | * Copyright 2020-2021 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 <openssl/evp.h>
|
---|
13 | #include "testutil.h"
|
---|
14 |
|
---|
15 | static int test_provider(OSSL_LIB_CTX *ctx)
|
---|
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))
|
---|
23 | && TEST_ptr(prov = EVP_KEYMGMT_get0_provider(rsameth))
|
---|
24 | && TEST_str_eq(OSSL_PROVIDER_get0_name(prov), "default");
|
---|
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 | {
|
---|
37 | OSSL_LIB_CTX *ctx = NULL;
|
---|
38 | OSSL_PROVIDER *prov = NULL;
|
---|
39 | int ok;
|
---|
40 |
|
---|
41 | ok = TEST_ptr(ctx = OSSL_LIB_CTX_new())
|
---|
42 | && TEST_ptr(prov = OSSL_PROVIDER_load(ctx, "default"))
|
---|
43 | && test_provider(ctx)
|
---|
44 | && TEST_true(OSSL_PROVIDER_unload(prov));
|
---|
45 |
|
---|
46 | OSSL_LIB_CTX_free(ctx);
|
---|
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 |
|
---|