Home | History | Annotate | Line # | Download | only in test
      1 /*
      2  * Copyright 2020-2024 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 
     44     if (ok) {
     45         ok = test_provider(ctx);
     46         if (ok)
     47             ok = TEST_true(OSSL_PROVIDER_unload(prov));
     48         else
     49             OSSL_PROVIDER_unload(prov);
     50     }
     51 
     52     OSSL_LIB_CTX_free(ctx);
     53     return ok;
     54 }
     55 
     56 
     57 int setup_tests(void)
     58 {
     59     ADD_TEST(test_fallback_provider);
     60     ADD_TEST(test_explicit_provider);
     61     return 1;
     62 }
     63 
     64