| Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* Objects typed to subclasses of the these classes are constructed and filled in by |
| 9 | the parser as it parses test-template lines. There is not necessarily a one-to-one |
| 10 | correspondence between the template lines and either the PSA commands generated nor |
| 11 | PSA assets they manipulate. PSA assets (which persist through the test) and PSA |
| 12 | commands are therefore tracked in separate objects, but referenced here. */ |
| 13 | |
| 14 | #ifndef TEMPLATE_LINE_HPP |
| 15 | #define TEMPLATE_LINE_HPP |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 | #include <iterator> |
| 21 | #include <algorithm> |
| 22 | #include <new> |
| 23 | |
| 24 | /* This project's header files #including other project headers quickly becomes |
| 25 | unrealistically complicated. The only solution is for each .cpp to include |
| 26 | the headers it needs. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | using namespace std; |
| 31 | |
| 32 | class template_line |
| 33 | { |
| 34 | public: |
| 35 | // Data members: // low value to hide these behind setters and getters |
| 36 | // Everything about the test -- accumulated PSA commands, assets, etc.: |
| 37 | tf_fuzz_info *test_state; |
| 38 | /* Note: The following are pointers to the psa_asset and psa_call currently |
| 39 | being worked with. These objects these are first placed on the appropriate |
| 40 | vector in test_state of such objects, and then referenced here. */ |
| 41 | expect_info expect; // everything about expected results |
| 42 | set_data_info set_data; // everything about setting PSA-asset data |
| 43 | asset_name_id_info asset_info; // everything about the asset(s) for this line |
| 44 | string asset_2_name; // if there's a 2nd asset, then this is its name |
| 45 | string asset_3_name; // if there's a 3rd asset, then this is its name |
| 46 | string target_barrier; |
| 47 | /* asset to tell the psa_call objects to set and search barrier to when |
| 48 | re-ordering PSA calls. For key policies, this is not necessarily the |
| 49 | nominal asset of that call. For a policy call, it is that policy asset, |
| 50 | so that later re-settings of the same policy don't pollute the current |
| 51 | setting of that policy. However, for key sets and reads, it is not the |
| 52 | key asset, but its policy. */ |
| 53 | key_policy_info policy_info; // specific to crypto, but must be in base class |
| 54 | long call_ser_no; // unique identifer for psa_call tracker object |
| 55 | psa_asset_usage random_asset; |
| 56 | /* if asked to use some random asset from active or deleted, this says |
| 57 | which. psa_asset_usage::all if not using this feature. */ |
| 58 | bool assign_data_var_specified; // asset data to or from a named variable |
| 59 | string assign_data_var; // name of variable to dump (assign) data into |
| 60 | bool print_data; // true to print asset data to test log |
| 61 | bool hash_data; // true to hash data for later comparison |
| 62 | /* Vectors of asset names or IDs. These are used to create several similar |
| 63 | PSA calls from a single template line. */ |
| 64 | bool is_remove; // true if this template line is to remove an asset |
| 65 | // Methods (mostly for calling from within yyparse()): |
| 66 | virtual bool copy_template_to_call (psa_call *the_call) = 0; |
| 67 | virtual void setup_call (set_data_info set_data, bool random_data, |
| 68 | bool fill_in_template, bool create_call, |
| 69 | template_line *temLin, tf_fuzz_info *rsrc) = 0; |
| 70 | template_line (tf_fuzz_info *resources); // (constructor) |
| 71 | virtual ~template_line (void); |
| 72 | |
| 73 | protected: // a lot simpler to just let subclasses access these directly |
| 74 | // Data members: |
| 75 | // Parallel vectors of PSA-asset info, by asset identified: |
| 76 | /* Not all template lines involve expected data, but all that do use it, |
| 77 | use it the same, so include it here. */ |
| 78 | string asset_name; // parsed from template, assigned to psa_asset object |
| 79 | // Methods: |
| 80 | |
| 81 | private: |
| 82 | // Data members: |
| 83 | // Methods: |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | /* Note: The following are sub-classed from template_line (above), and then further |
| 88 | subclassed in sst_template_line.*pp, crypto_template_line.*pp, etc. Concep- |
| 89 | tually, these subclasses might be more logically put in those sub-classing |
| 90 | files, but this gives a more-even balance of file size and complexity. */ |
| 91 | |
| 92 | |
| 93 | class sst_template_line : public template_line |
| 94 | { |
| 95 | public: |
| 96 | // Data members: |
| 97 | // SST-asset info: |
| 98 | // PSA-call info: |
| 99 | // Methods: |
| 100 | bool copy_template_to_call (psa_call *the_call); |
| 101 | sst_template_line (tf_fuzz_info *resources); // (constructor) |
| 102 | ~sst_template_line (void); |
| 103 | |
| 104 | protected: |
| 105 | // Data members: |
| 106 | // Methods: |
| 107 | |
| 108 | private: |
| 109 | // Data members: |
| 110 | // Methods: |
| 111 | }; |
| 112 | |
| 113 | |
| 114 | class key_template_line : public template_line |
| 115 | { |
| 116 | public: |
| 117 | // Data members: |
| 118 | // Methods: |
| 119 | bool copy_template_to_call (psa_call *the_call); |
| 120 | string make_id_based_name (uint64_t id_n, string &name); |
| 121 | // create ID-based asset name |
| 122 | key_template_line (tf_fuzz_info *resources); // (constructor) |
| 123 | ~key_template_line (void); |
| 124 | |
| 125 | protected: |
| 126 | // Data members: |
| 127 | // Methods: |
| 128 | |
| 129 | private: |
| 130 | // Data members: |
| 131 | // Methods: |
| 132 | }; |
| 133 | |
| 134 | class policy_template_line : public template_line |
| 135 | { |
| 136 | public: |
| 137 | // Data members: |
| 138 | // Methods: |
| 139 | bool copy_template_to_call (psa_call *the_call); |
| 140 | policy_template_line (tf_fuzz_info *resources); // (constructor) |
| 141 | ~policy_template_line (void); |
| 142 | |
| 143 | protected: |
| 144 | // Data members: |
| 145 | // Methods: |
| 146 | |
| 147 | private: |
| 148 | // Data members: |
| 149 | // Methods: |
| 150 | string make_id_based_name (uint64_t id_n, string &name); |
| 151 | // create ID-based asset name |
| 152 | }; |
| 153 | |
| 154 | |
| 155 | class security_template_line : public template_line |
| 156 | { |
| 157 | public: |
| 158 | // Data members: // low value to hide these behind setters and getters |
| 159 | // Everything about the test -- accumulated PSA commands, assets, etc.: |
| 160 | // Methods (for calling from within yyparse()): |
| 161 | security_template_line (tf_fuzz_info *resources); // (constructor) |
| 162 | ~security_template_line (void); |
| 163 | |
| 164 | protected: // a lot simpler to just let subclasses access these directly |
| 165 | // Data members: |
| 166 | // Methods: |
| 167 | |
| 168 | private: |
| 169 | // Data members: |
| 170 | // Methods: |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | #endif // TEMPLATE_LINE_HPP |