1 | /*
|
---|
2 | * Copyright 2022 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 <openssl/evp.h>
|
---|
11 | #include <openssl/provider.h>
|
---|
12 | #include "testutil.h"
|
---|
13 |
|
---|
14 | static OSSL_LIB_CTX *libctx = NULL;
|
---|
15 | static OSSL_PROVIDER *libprov = NULL;
|
---|
16 |
|
---|
17 | typedef enum OPTION_choice {
|
---|
18 | OPT_ERR = -1,
|
---|
19 | OPT_EOF = 0,
|
---|
20 | OPT_CONFIG_FILE,
|
---|
21 | OPT_TEST_ENUM
|
---|
22 | } OPTION_CHOICE;
|
---|
23 |
|
---|
24 | const OPTIONS *test_get_options(void)
|
---|
25 | {
|
---|
26 | static const OPTIONS test_options[] = {
|
---|
27 | OPT_TEST_OPTIONS_DEFAULT_USAGE,
|
---|
28 | { "config", OPT_CONFIG_FILE, '<',
|
---|
29 | "The configuration file to use for the libctx" },
|
---|
30 | { NULL }
|
---|
31 | };
|
---|
32 | return test_options;
|
---|
33 | }
|
---|
34 |
|
---|
35 | static int test_fips_version(int n)
|
---|
36 | {
|
---|
37 | const char *version = test_get_argument(n);
|
---|
38 |
|
---|
39 | if (!TEST_ptr(version))
|
---|
40 | return 0;
|
---|
41 | return TEST_int_eq(fips_provider_version_match(libctx, version), 1);
|
---|
42 | }
|
---|
43 |
|
---|
44 | int setup_tests(void)
|
---|
45 | {
|
---|
46 | char *config_file = NULL;
|
---|
47 | OPTION_CHOICE o;
|
---|
48 | int n;
|
---|
49 |
|
---|
50 | while ((o = opt_next()) != OPT_EOF) {
|
---|
51 | switch (o) {
|
---|
52 | case OPT_CONFIG_FILE:
|
---|
53 | config_file = opt_arg();
|
---|
54 | break;
|
---|
55 | case OPT_TEST_CASES:
|
---|
56 | break;
|
---|
57 | default:
|
---|
58 | case OPT_ERR:
|
---|
59 | return 0;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (!test_get_libctx(&libctx, NULL, config_file, &libprov, NULL))
|
---|
64 | return 0;
|
---|
65 |
|
---|
66 | n = test_get_argument_count();
|
---|
67 | if (n == 0)
|
---|
68 | return 0;
|
---|
69 |
|
---|
70 | ADD_ALL_TESTS(test_fips_version, n);
|
---|
71 | return 1;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void cleanup_tests(void)
|
---|
75 | {
|
---|
76 | OSSL_PROVIDER_unload(libprov);
|
---|
77 | OSSL_LIB_CTX_free(libctx);
|
---|
78 | }
|
---|