Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 9 | #include <cstdlib> |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 10 | #include <iostream> |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 11 | |
| 12 | #include "boilerplate.hpp" |
| 13 | #include "variables.hpp" |
| 14 | #include "gibberish.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 15 | #include "string_ops.hpp" |
| 16 | #include "data_blocks.hpp" |
| 17 | #include "psa_asset.hpp" |
| 18 | #include "find_or_create_asset.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 19 | #include "tf_fuzz.hpp" |
| 20 | #include "crypto_asset.hpp" |
| 21 | #include "psa_call.hpp" |
| 22 | #include "crypto_call.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /********************************************************************************** |
| 26 | Methods of class policy_call follow: |
| 27 | **********************************************************************************/ |
| 28 | |
| 29 | /* Most of the policy classes, in their fill_in_prep_code() method, need to ensure |
| 30 | that, at a minimum, the policy variable (psa_key_attributes_t) exists, so, just |
| 31 | to cut down code duplication: */ |
| 32 | void policy_call::policy_fill_in_prep_code (void) |
| 33 | { |
| 34 | vector<variable_info>::iterator policy_variable; |
| 35 | |
| 36 | policy_variable = test_state->find_var (asset_info.get_name()); |
| 37 | if (policy_variable == test_state->variable.end()) { |
| 38 | // No such variable exists, so: |
| 39 | test_state->make_var (asset_info.get_name()); |
| 40 | policy_variable = test_state->find_var (asset_info.get_name()); |
| 41 | prep_code.assign (test_state->bplate->bplate_string[declare_policy]); |
| 42 | find_replace_1st ("$var", asset_info.get_name(), prep_code); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | |
| 47 | policy_call::policy_call (tf_fuzz_info *test_state, // (constructor) |
| 48 | long &call_ser_no, |
| 49 | asset_search how_asset_found) |
| 50 | : crypto_call(test_state, call_ser_no, how_asset_found) |
| 51 | { |
| 52 | // Note: Key attributes are set in the key_policy_info constructor. |
| 53 | } |
| 54 | policy_call::~policy_call (void) |
| 55 | { |
| 56 | // Nothing further to delete. |
| 57 | return; // just to have something to pin a breakpoint onto |
| 58 | } |
| 59 | |
| 60 | vector<psa_asset*>::iterator policy_call::resolve_asset (bool create_asset_bool, |
| 61 | psa_asset_usage where) { |
| 62 | vector<psa_asset*>::iterator found_asset; |
| 63 | vector<psa_asset*> *asset_vector; |
| 64 | int asset_pick; |
| 65 | |
| 66 | if (random_asset != psa_asset_usage::all) { |
| 67 | // != psa_asset_usage::all means to choose some known asset at random: |
| 68 | if (random_asset == psa_asset_usage::active) { |
| 69 | asset_vector = &(test_state->active_policy_asset); |
| 70 | asset_info.how_asset_found = asset_search::found_active; |
| 71 | } else if (random_asset == psa_asset_usage::deleted) { |
| 72 | asset_vector = &(test_state->deleted_policy_asset); |
| 73 | asset_info.how_asset_found = asset_search::found_deleted; |
| 74 | } else { |
| 75 | // "invalid" assets are not currently used. |
| 76 | cerr << "\nError: Tool-internal: Please report error 1102 to " << endl |
| 77 | << "TF-Fuzz developers." |
| 78 | << endl; |
| 79 | exit(1102); |
| 80 | } |
| 81 | if (asset_vector->size() > 0) { |
| 82 | /* Pick an active or deleted asset at random: */ |
| 83 | asset_pick = rand() % asset_vector->size(); |
| 84 | found_asset = asset_vector->begin() + asset_pick; |
| 85 | /* Copy asset information into template tracker: */ |
| 86 | asset_info.id_n = (*found_asset)->asset_info.id_n; |
| 87 | asset_info.asset_ser_no |
| 88 | = (*found_asset)->asset_info.asset_ser_no; |
| 89 | } else { |
| 90 | if (random_asset == psa_asset_usage::active) { |
| 91 | cerr << "\nError: A policy call asks for a " |
| 92 | << "randomly chosen active asset, when none " << endl |
| 93 | << "is currently defined." << endl; |
| 94 | exit(1010); |
| 95 | } else if (random_asset == psa_asset_usage::deleted) { |
| 96 | cerr << "\nError: A policy call asks for a " |
| 97 | << "randomly chosen deleted asset, when none " << endl |
| 98 | << "is currently defined." << endl; |
| 99 | exit(1011); |
| 100 | } // "invalid" assets are not currently used. |
| 101 | } |
| 102 | } else { |
| 103 | // Find the asset by name: |
| 104 | asset_info.how_asset_found = test_state->find_or_create_policy_asset ( |
| 105 | psa_asset_search::name, where, |
| 106 | asset_info.get_name(), 0, asset_info.asset_ser_no, |
| 107 | create_asset_bool, found_asset ); |
| 108 | if ( asset_info.how_asset_found == asset_search::unsuccessful |
| 109 | || asset_info.how_asset_found == asset_search::something_wrong ) { |
| 110 | cerr << "\nError: Tool-internal: Please report error 108 to " << endl |
| 111 | << "TF-Fuzz developers." |
| 112 | << endl; |
| 113 | exit(108); |
| 114 | } |
| 115 | } |
| 116 | return found_asset; |
| 117 | } |
| 118 | |
| 119 | /********************************************************************************** |
| 120 | End of methods of class policy_call. |
| 121 | **********************************************************************************/ |
| 122 | |
| 123 | |
| 124 | /********************************************************************************** |
| 125 | Methods of class key_call follow: |
| 126 | **********************************************************************************/ |
| 127 | |
| 128 | key_call::key_call (tf_fuzz_info *test_state, // (constructor) |
| 129 | long &call_ser_no, |
| 130 | asset_search how_asset_found) |
| 131 | : crypto_call(test_state, call_ser_no, how_asset_found) |
| 132 | { |
| 133 | asset_info.the_asset = nullptr; |
| 134 | } |
| 135 | key_call::~key_call (void) |
| 136 | { |
| 137 | // Nothing further to delete. |
| 138 | return; // just to have something to pin a breakpoint onto |
| 139 | } |
| 140 | |
| 141 | vector<psa_asset*>::iterator key_call::resolve_asset (bool create_asset_bool, |
| 142 | psa_asset_usage where) { |
| 143 | vector<psa_asset*>::iterator found_asset; |
| 144 | vector<psa_asset*> *asset_vector; |
| 145 | int asset_pick; |
| 146 | |
| 147 | if (random_asset != psa_asset_usage::all) { |
| 148 | // != psa_asset_usage::all means to choose some known asset at random: |
| 149 | if (random_asset == psa_asset_usage::active) { |
| 150 | asset_vector = &(test_state->active_key_asset); |
| 151 | asset_info.how_asset_found = asset_search::found_active; |
| 152 | } else if (random_asset == psa_asset_usage::deleted) { |
| 153 | asset_vector = &(test_state->deleted_key_asset); |
| 154 | asset_info.how_asset_found = asset_search::found_deleted; |
| 155 | } else { |
| 156 | // "invalid" assets are not currently used. |
| 157 | cerr << "\nError: Tool-internal: Please report error 1103 to " << endl |
| 158 | << "TF-Fuzz developers." |
| 159 | << endl; |
| 160 | exit(1103); |
| 161 | } |
| 162 | if (asset_vector->size() > 0) { |
| 163 | /* Pick an active or deleted asset at random: */ |
| 164 | asset_pick = rand() % asset_vector->size(); |
| 165 | found_asset = asset_vector->begin() + asset_pick; |
| 166 | /* Copy asset information into template tracker: */ |
| 167 | asset_info.id_n = (*found_asset)->asset_info.id_n; |
| 168 | asset_info.asset_ser_no |
| 169 | = (*found_asset)->asset_info.asset_ser_no; |
| 170 | } else { |
| 171 | if (random_asset == psa_asset_usage::active) { |
| 172 | cerr << "\nError: A key call asks for a " |
| 173 | << "randomly chosen active asset, when none " << endl |
| 174 | << "is currently defined." << endl; |
| 175 | exit(1012); |
| 176 | } else if (random_asset == psa_asset_usage::deleted) { |
| 177 | cerr << "\nError: A key call asks for a " |
| 178 | << "randomly chosen deleted asset, when none " << endl |
| 179 | << "is currently defined." << endl; |
| 180 | exit(1013); |
| 181 | } // "invalid" assets are not currently used. |
| 182 | } |
| 183 | } else { |
| 184 | // Find the asset by name: |
| 185 | asset_info.how_asset_found = test_state->find_or_create_key_asset ( |
| 186 | psa_asset_search::name, where, |
| 187 | asset_info.get_name(), 0, asset_info.asset_ser_no, |
| 188 | create_asset_bool, found_asset ); |
| 189 | if ( asset_info.how_asset_found == asset_search::unsuccessful |
| 190 | || asset_info.how_asset_found == asset_search::something_wrong ) { |
| 191 | cerr << "\nError: Tool-internal: Please report error 108 to " << endl |
| 192 | << "TF-Fuzz developers." |
| 193 | << endl; |
| 194 | exit(108); |
| 195 | } |
| 196 | } |
| 197 | return found_asset; |
| 198 | } |
| 199 | |
| 200 | /********************************************************************************** |
| 201 | End of methods of class key_call. |
| 202 | **********************************************************************************/ |
| 203 | |
| 204 | |
| 205 | /********************************************************************************** |
| 206 | Methods of class init_policy_call follow: |
| 207 | **********************************************************************************/ |
| 208 | |
| 209 | init_policy_call::init_policy_call (tf_fuzz_info *test_state, // (constructor) |
| 210 | long &call_ser_no, |
| 211 | asset_search how_asset_found) |
| 212 | : policy_call(test_state, call_ser_no, |
| 213 | how_asset_found) |
| 214 | { |
| 215 | // Copy the boilerplate text into local buffers: |
| 216 | prep_code.assign (""); |
| 217 | call_code.assign (test_state->bplate->bplate_string[init_policy]); |
| 218 | call_description = "initialize-policy call"; |
| 219 | } |
| 220 | init_policy_call::~init_policy_call (void) |
| 221 | { |
| 222 | return; // just to have something to pin a breakpoint onto |
| 223 | } |
| 224 | |
| 225 | bool init_policy_call::copy_call_to_asset (void) |
| 226 | { |
| 227 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 228 | } |
| 229 | |
| 230 | void init_policy_call::fill_in_prep_code (void) |
| 231 | { |
| 232 | policy_fill_in_prep_code(); |
| 233 | } |
| 234 | |
| 235 | void init_policy_call::fill_in_command (void) |
| 236 | { |
| 237 | // (call_code already loaded by constructor) |
| 238 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 239 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 240 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /********************************************************************************** |
| 244 | End of methods of class init_policy_call. |
| 245 | **********************************************************************************/ |
| 246 | |
| 247 | |
| 248 | /********************************************************************************** |
| 249 | Methods of class reset_policy_call follow: |
| 250 | **********************************************************************************/ |
| 251 | |
| 252 | reset_policy_call::reset_policy_call (tf_fuzz_info *test_state, // (constructor) |
| 253 | long &call_ser_no, |
| 254 | asset_search how_asset_found) |
| 255 | : policy_call(test_state, call_ser_no, |
| 256 | how_asset_found) |
| 257 | { |
| 258 | // Copy the boilerplate text into local buffers: |
| 259 | prep_code.assign (""); |
| 260 | call_code.assign (test_state->bplate->bplate_string[reset_policy]); |
| 261 | call_description = "policy reset call"; |
| 262 | } |
| 263 | reset_policy_call::~reset_policy_call (void) |
| 264 | { |
| 265 | return; // just to have something to pin a breakpoint onto |
| 266 | } |
| 267 | |
| 268 | bool reset_policy_call::copy_call_to_asset (void) |
| 269 | { |
| 270 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 271 | } |
| 272 | |
| 273 | void reset_policy_call::fill_in_prep_code (void) |
| 274 | { |
| 275 | policy_fill_in_prep_code(); |
| 276 | } |
| 277 | |
| 278 | void reset_policy_call::fill_in_command (void) |
| 279 | { |
| 280 | // (call_code already loaded by constructor) |
| 281 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 282 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 283 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /********************************************************************************** |
| 287 | End of methods of class reset_policy_call. |
| 288 | **********************************************************************************/ |
| 289 | |
| 290 | |
| 291 | /********************************************************************************** |
| 292 | Methods of class add_policy_usage_call follow: |
| 293 | **********************************************************************************/ |
| 294 | |
| 295 | add_policy_usage_call::add_policy_usage_call (tf_fuzz_info *test_state, // (constructor) |
| 296 | long &call_ser_no, |
| 297 | asset_search how_asset_found) |
| 298 | : policy_call(test_state, call_ser_no, |
| 299 | how_asset_found) |
| 300 | { |
| 301 | // Copy the boilerplate text into local buffers: |
| 302 | prep_code.assign (""); |
| 303 | call_code.assign (test_state->bplate->bplate_string[add_policy_usage]); |
| 304 | call_description = "policy add-usage call"; |
| 305 | } |
| 306 | add_policy_usage_call::~add_policy_usage_call (void) |
| 307 | { |
| 308 | return; // just to have something to pin a breakpoint onto |
| 309 | } |
| 310 | |
| 311 | bool add_policy_usage_call::copy_call_to_asset (void) |
| 312 | { |
| 313 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 314 | } |
| 315 | |
| 316 | void add_policy_usage_call::fill_in_prep_code (void) |
| 317 | { |
| 318 | policy_fill_in_prep_code(); |
| 319 | /* TODO: The variable this creates should have been declared already. Should |
| 320 | this instead produce an error if it doesn't exist? */ |
| 321 | } |
| 322 | |
| 323 | void add_policy_usage_call::fill_in_command (void) |
| 324 | { |
| 325 | // (call_code already loaded by constructor) |
| 326 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 327 | find_replace_1st ("$flag", policy.usage_string, call_code); |
| 328 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 329 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /********************************************************************************** |
| 333 | End of methods of class add_policy_usage_call. |
| 334 | **********************************************************************************/ |
| 335 | |
| 336 | |
| 337 | /********************************************************************************** |
| 338 | Methods of class set_policy_lifetime_call follow: |
| 339 | **********************************************************************************/ |
| 340 | |
| 341 | set_policy_lifetime_call::set_policy_lifetime_call (tf_fuzz_info *test_state, |
| 342 | long &call_ser_no, // (constructor) |
| 343 | asset_search how_asset_found) |
| 344 | : policy_call(test_state, call_ser_no, |
| 345 | how_asset_found) |
| 346 | { |
| 347 | // Copy the boilerplate text into local buffers: |
| 348 | prep_code.assign (""); |
| 349 | call_code.assign (test_state->bplate->bplate_string[set_policy_lifetime]); |
| 350 | call_description = "policy lifetime-set call"; |
| 351 | } |
| 352 | set_policy_lifetime_call::~set_policy_lifetime_call (void) |
| 353 | { |
| 354 | return; // just to have something to pin a breakpoint onto |
| 355 | } |
| 356 | |
| 357 | bool set_policy_lifetime_call::copy_call_to_asset (void) |
| 358 | { |
| 359 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 360 | } |
| 361 | |
| 362 | void set_policy_lifetime_call::fill_in_prep_code (void) |
| 363 | { |
| 364 | policy_fill_in_prep_code(); |
| 365 | } |
| 366 | |
| 367 | void set_policy_lifetime_call::fill_in_command (void) |
| 368 | { |
| 369 | // (call_code already loaded by constructor) |
| 370 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 371 | find_replace_1st ("$life", |
| 372 | policy.persistent? "PSA_KEY_LIFETIME_PERSISTENT" |
| 373 | : "PSA_KEY_LIFETIME_VOLATILE", |
| 374 | call_code); |
| 375 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 376 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /********************************************************************************** |
| 380 | End of methods of class set_policy_lifetime_call. |
| 381 | **********************************************************************************/ |
| 382 | |
| 383 | |
| 384 | /********************************************************************************** |
| 385 | Methods of class set_policy_size_call follow: |
| 386 | **********************************************************************************/ |
| 387 | |
| 388 | set_policy_size_call::set_policy_size_call (tf_fuzz_info *test_state, // (constructor) |
| 389 | long &call_ser_no, |
| 390 | asset_search how_asset_found) |
| 391 | : policy_call(test_state, call_ser_no, |
| 392 | how_asset_found) |
| 393 | { |
| 394 | // Copy the boilerplate text into local buffers: |
| 395 | prep_code.assign (""); |
| 396 | call_code.assign (test_state->bplate->bplate_string[set_policy_size]); |
| 397 | call_description = "policy size-set call"; |
| 398 | } |
| 399 | set_policy_size_call::~set_policy_size_call (void) |
| 400 | { |
| 401 | return; // just to have something to pin a breakpoint onto |
| 402 | } |
| 403 | |
| 404 | bool set_policy_size_call::copy_call_to_asset (void) |
| 405 | { |
| 406 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 407 | } |
| 408 | |
| 409 | void set_policy_size_call::fill_in_prep_code (void) |
| 410 | { |
| 411 | policy_fill_in_prep_code(); |
| 412 | } |
| 413 | |
| 414 | void set_policy_size_call::fill_in_command (void) |
| 415 | { |
| 416 | // (call_code already loaded by constructor) |
| 417 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 418 | find_replace_1st ("$size", to_string (policy.n_bits), call_code); |
| 419 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 420 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /********************************************************************************** |
| 424 | End of methods of class set_policy_size_call. |
| 425 | **********************************************************************************/ |
| 426 | |
| 427 | |
| 428 | /********************************************************************************** |
| 429 | Methods of class set_policy_type_call follow: |
| 430 | **********************************************************************************/ |
| 431 | |
| 432 | set_policy_type_call::set_policy_type_call (tf_fuzz_info *test_state, // (constructor) |
| 433 | long &call_ser_no, |
| 434 | asset_search how_asset_found) |
| 435 | : policy_call(test_state, call_ser_no, |
| 436 | how_asset_found) |
| 437 | { |
| 438 | // Copy the boilerplate text into local buffers: |
| 439 | prep_code.assign (""); |
| 440 | call_code.assign (test_state->bplate->bplate_string[set_policy_type]); |
| 441 | call_description = "policy type-set call"; |
| 442 | } |
| 443 | set_policy_type_call::~set_policy_type_call (void) |
| 444 | { |
| 445 | return; // just to have something to pin a breakpoint onto |
| 446 | } |
| 447 | |
| 448 | bool set_policy_type_call::copy_call_to_asset (void) |
| 449 | { |
| 450 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 451 | } |
| 452 | |
| 453 | void set_policy_type_call::fill_in_prep_code (void) |
| 454 | { |
| 455 | policy_fill_in_prep_code(); |
| 456 | } |
| 457 | |
| 458 | void set_policy_type_call::fill_in_command (void) |
| 459 | { |
| 460 | // (call_code already loaded by constructor) |
| 461 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 462 | find_replace_1st ("$type", policy.key_type, call_code); |
| 463 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 464 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /********************************************************************************** |
| 468 | End of methods of class set_policy_type_call. |
| 469 | **********************************************************************************/ |
| 470 | |
| 471 | |
| 472 | /********************************************************************************** |
| 473 | Methods of class set_policy_algorithm_call follow: |
| 474 | **********************************************************************************/ |
| 475 | |
| 476 | set_policy_algorithm_call::set_policy_algorithm_call (tf_fuzz_info *test_state, |
| 477 | long &call_ser_no, // (constructor) |
| 478 | asset_search how_asset_found) |
| 479 | : policy_call(test_state, call_ser_no, |
| 480 | how_asset_found) |
| 481 | { |
| 482 | // Copy the boilerplate text into local buffers: |
| 483 | prep_code.assign (""); |
| 484 | call_code.assign (test_state->bplate->bplate_string[set_policy_algorithm]); |
| 485 | call_description = "policy algorithm-set call"; |
| 486 | } |
| 487 | set_policy_algorithm_call::~set_policy_algorithm_call (void) |
| 488 | { |
| 489 | return; // just to have something to pin a breakpoint onto |
| 490 | } |
| 491 | |
| 492 | bool set_policy_algorithm_call::copy_call_to_asset (void) |
| 493 | { |
| 494 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 495 | } |
| 496 | |
| 497 | void set_policy_algorithm_call::fill_in_prep_code (void) |
| 498 | { |
| 499 | policy_fill_in_prep_code(); |
| 500 | } |
| 501 | |
| 502 | void set_policy_algorithm_call::fill_in_command (void) |
| 503 | { |
| 504 | // (call_code already loaded by constructor) |
| 505 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 506 | find_replace_1st ("$algorithm", policy.key_algorithm, call_code); |
| 507 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 508 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /********************************************************************************** |
| 512 | End of methods of class set_policy_algorithm_call. |
| 513 | **********************************************************************************/ |
| 514 | |
| 515 | |
| 516 | /********************************************************************************** |
| 517 | Methods of class set_policy_usage_call follow: |
| 518 | **********************************************************************************/ |
| 519 | |
| 520 | set_policy_usage_call::set_policy_usage_call (tf_fuzz_info *test_state, // (constructor) |
| 521 | long &call_ser_no, |
| 522 | asset_search how_asset_found) |
| 523 | : policy_call(test_state, call_ser_no, |
| 524 | how_asset_found) |
| 525 | { |
| 526 | // Copy the boilerplate text into local buffers: |
| 527 | prep_code.assign (""); |
| 528 | call_code.assign (test_state->bplate->bplate_string[set_policy_usage]); |
| 529 | call_description = "policy usage-set call"; |
| 530 | } |
| 531 | set_policy_usage_call::~set_policy_usage_call (void) |
| 532 | { |
| 533 | return; // just to have something to pin a breakpoint onto |
| 534 | } |
| 535 | |
| 536 | bool set_policy_usage_call::copy_call_to_asset (void) |
| 537 | { |
| 538 | return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset); |
| 539 | } |
| 540 | |
| 541 | void set_policy_usage_call::fill_in_prep_code (void) |
| 542 | { |
| 543 | policy_fill_in_prep_code(); |
| 544 | } |
| 545 | |
| 546 | void set_policy_usage_call::fill_in_command (void) |
| 547 | { |
| 548 | find_replace_1st ("$policy", asset_info.get_name(), call_code); |
| 549 | find_replace_1st ("$usage", "0", call_code); |
| 550 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 551 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /********************************************************************************** |
| 555 | End of methods of class set_policy_usage_call. |
| 556 | **********************************************************************************/ |
| 557 | |
| 558 | |
| 559 | /********************************************************************************** |
| 560 | Methods of class get_policy_lifetime_call follow: |
| 561 | **********************************************************************************/ |
| 562 | |
| 563 | get_policy_lifetime_call::get_policy_lifetime_call (tf_fuzz_info *test_state, |
| 564 | long &call_ser_no, // (constructor) |
| 565 | asset_search how_asset_found) |
| 566 | : policy_call(test_state, call_ser_no, |
| 567 | how_asset_found) |
| 568 | { |
| 569 | // Copy the boilerplate text into local buffers: |
| 570 | prep_code.assign (""); |
| 571 | call_code.assign (test_state->bplate->bplate_string[get_policy_lifetime]); |
| 572 | call_description = "policy lifetime-get call"; |
| 573 | } |
| 574 | get_policy_lifetime_call::~get_policy_lifetime_call (void) |
| 575 | { |
| 576 | return; // just to have something to pin a breakpoint onto |
| 577 | } |
| 578 | |
| 579 | bool get_policy_lifetime_call::copy_call_to_asset (void) |
| 580 | { |
| 581 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 582 | } |
| 583 | |
| 584 | void get_policy_lifetime_call::fill_in_prep_code (void) |
| 585 | { |
| 586 | string var_name = asset_info.get_name() + "_life"; |
| 587 | vector<variable_info>::iterator assign_variable; |
| 588 | |
| 589 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 590 | assign_variable = test_state->find_var (var_name); |
| 591 | if (assign_variable == test_state->variable.end()) { |
| 592 | // No such variable exists, so: |
| 593 | test_state->make_var (var_name); |
| 594 | prep_code.append (test_state->bplate->bplate_string[declare_policy_lifetime]); |
| 595 | find_replace_all ("$var", var_name, prep_code); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void get_policy_lifetime_call::fill_in_command (void) |
| 600 | { |
| 601 | // (call_code already loaded by constructor) |
| 602 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 603 | find_replace_1st ("$life", asset_info.get_name() + "_life", call_code); |
| 604 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 605 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /********************************************************************************** |
| 609 | End of methods of class get_policy_lifetime_call. |
| 610 | **********************************************************************************/ |
| 611 | |
| 612 | |
| 613 | /********************************************************************************** |
| 614 | Methods of class get_policy_size_call follow: |
| 615 | **********************************************************************************/ |
| 616 | |
| 617 | get_policy_size_call::get_policy_size_call (tf_fuzz_info *test_state, |
| 618 | long &call_ser_no, // (constructor) |
| 619 | asset_search how_asset_found) |
| 620 | : policy_call(test_state, call_ser_no, |
| 621 | how_asset_found) |
| 622 | { |
| 623 | // Copy the boilerplate text into local buffers: |
| 624 | prep_code.assign (""); |
| 625 | call_code.assign (test_state->bplate->bplate_string[get_policy_size]); |
| 626 | call_description = "policy size-get call"; |
| 627 | } |
| 628 | get_policy_size_call::~get_policy_size_call (void) |
| 629 | { |
| 630 | return; // just to have something to pin a breakpoint onto |
| 631 | } |
| 632 | |
| 633 | bool get_policy_size_call::copy_call_to_asset (void) |
| 634 | { |
| 635 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 636 | } |
| 637 | |
| 638 | void get_policy_size_call::fill_in_prep_code (void) |
| 639 | { |
| 640 | string var_name = asset_info.get_name() + "_size"; |
| 641 | vector<variable_info>::iterator assign_variable; |
| 642 | |
| 643 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 644 | assign_variable = test_state->find_var (var_name); |
| 645 | if (assign_variable == test_state->variable.end()) { |
| 646 | // No such variable exists, so: |
| 647 | test_state->make_var (var_name); |
| 648 | prep_code.append (test_state->bplate->bplate_string[declare_size_t]); |
| 649 | find_replace_all ("$var", var_name, prep_code); |
| 650 | find_replace_1st ("$init", to_string(exp_data.data.length()), prep_code); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | void get_policy_size_call::fill_in_command (void) |
| 655 | { |
| 656 | // (call_code already loaded by constructor) |
| 657 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 658 | find_replace_1st ("$size", asset_info.get_name() + "_size", call_code); |
| 659 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 660 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /********************************************************************************** |
| 664 | End of methods of class get_policy_size_call. |
| 665 | **********************************************************************************/ |
| 666 | |
| 667 | |
| 668 | /********************************************************************************** |
| 669 | Methods of class get_policy_type_call follow: |
| 670 | **********************************************************************************/ |
| 671 | |
| 672 | get_policy_type_call::get_policy_type_call (tf_fuzz_info *test_state, |
| 673 | long &call_ser_no, // (constructor) |
| 674 | asset_search how_asset_found) |
| 675 | : policy_call(test_state, call_ser_no, |
| 676 | how_asset_found) |
| 677 | { |
| 678 | // Copy the boilerplate text into local buffers: |
| 679 | prep_code.assign (""); |
| 680 | call_code.assign (test_state->bplate->bplate_string[get_policy_type]); |
| 681 | call_description = "policy type-get call"; |
| 682 | } |
| 683 | get_policy_type_call::~get_policy_type_call (void) |
| 684 | { |
| 685 | return; // just to have something to pin a breakpoint onto |
| 686 | } |
| 687 | |
| 688 | bool get_policy_type_call::copy_call_to_asset (void) |
| 689 | { |
| 690 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 691 | } |
| 692 | |
| 693 | void get_policy_type_call::fill_in_prep_code (void) |
| 694 | { |
| 695 | string var_name = asset_info.get_name() + "_type"; |
| 696 | vector<variable_info>::iterator assign_variable; |
| 697 | |
| 698 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 699 | assign_variable = test_state->find_var (var_name); |
| 700 | if (assign_variable == test_state->variable.end()) { |
| 701 | // No such variable exists, so: |
| 702 | test_state->make_var (var_name); |
| 703 | prep_code.append (test_state->bplate->bplate_string[declare_policy_type]); |
| 704 | find_replace_all ("$var", var_name, prep_code); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | void get_policy_type_call::fill_in_command (void) |
| 709 | { |
| 710 | // (call_code already loaded by constructor) |
| 711 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 712 | find_replace_1st ("$type", asset_info.get_name() + "_type", call_code); |
| 713 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 714 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /********************************************************************************** |
| 718 | End of methods of class get_policy_type_call. |
| 719 | **********************************************************************************/ |
| 720 | |
| 721 | |
| 722 | /********************************************************************************** |
| 723 | Methods of class get_policy_algorithm_call follow: |
| 724 | **********************************************************************************/ |
| 725 | |
| 726 | get_policy_algorithm_call::get_policy_algorithm_call (tf_fuzz_info *test_state, |
| 727 | long &call_ser_no, // (constructor) |
| 728 | asset_search how_asset_found) |
| 729 | : policy_call(test_state, call_ser_no, |
| 730 | how_asset_found) |
| 731 | { |
| 732 | // Copy the boilerplate text into local buffers: |
| 733 | prep_code.assign (""); |
| 734 | call_code.assign (test_state->bplate->bplate_string[get_policy_algorithm]); |
| 735 | call_description = "policy algorithm-get call"; |
| 736 | } |
| 737 | get_policy_algorithm_call::~get_policy_algorithm_call (void) |
| 738 | { |
| 739 | return; // just to have something to pin a breakpoint onto |
| 740 | } |
| 741 | |
| 742 | bool get_policy_algorithm_call::copy_call_to_asset (void) |
| 743 | { |
| 744 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 745 | } |
| 746 | |
| 747 | void get_policy_algorithm_call::fill_in_prep_code (void) |
| 748 | { |
| 749 | string var_name = asset_info.get_name() + "_algo"; |
| 750 | vector<variable_info>::iterator assign_variable; |
| 751 | |
| 752 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 753 | assign_variable = test_state->find_var (var_name); |
| 754 | if (assign_variable == test_state->variable.end()) { |
| 755 | // No such variable exists, so: |
| 756 | test_state->make_var (var_name); |
| 757 | prep_code.append (test_state->bplate->bplate_string[declare_policy_algorithm]); |
| 758 | find_replace_all ("$var", var_name, prep_code); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | void get_policy_algorithm_call::fill_in_command (void) |
| 763 | { |
| 764 | // (call_code already loaded by constructor) |
| 765 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 766 | find_replace_1st ("$algorithm", asset_info.get_name() + "_algo", call_code); |
| 767 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 768 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /********************************************************************************** |
| 772 | End of methods of class get_policy_algorithm_call. |
| 773 | **********************************************************************************/ |
| 774 | |
| 775 | |
| 776 | /********************************************************************************** |
| 777 | Methods of class get_policy_usage_call follow: |
| 778 | **********************************************************************************/ |
| 779 | |
| 780 | get_policy_usage_call::get_policy_usage_call (tf_fuzz_info *test_state, |
| 781 | long &call_ser_no, // (constructor) |
| 782 | asset_search how_asset_found) |
| 783 | : policy_call(test_state, call_ser_no, |
| 784 | how_asset_found) |
| 785 | { |
| 786 | // Copy the boilerplate text into local buffers: |
| 787 | prep_code.assign (""); |
| 788 | call_code.assign (test_state->bplate->bplate_string[get_policy_usage]); |
| 789 | call_description = "policy usage-get call"; |
| 790 | } |
| 791 | get_policy_usage_call::~get_policy_usage_call (void) |
| 792 | { |
| 793 | return; // just to have something to pin a breakpoint onto |
| 794 | } |
| 795 | |
| 796 | bool get_policy_usage_call::copy_call_to_asset (void) |
| 797 | { |
| 798 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 799 | } |
| 800 | |
| 801 | void get_policy_usage_call::fill_in_prep_code (void) |
| 802 | { |
| 803 | string var_name = asset_info.get_name() + "_usage"; |
| 804 | vector<variable_info>::iterator assign_variable; |
| 805 | |
| 806 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 807 | assign_variable = test_state->find_var (var_name); |
| 808 | if (assign_variable == test_state->variable.end()) { |
| 809 | // No such variable exists, so: |
| 810 | test_state->make_var (var_name); |
| 811 | prep_code.append (test_state->bplate->bplate_string[declare_policy_usage]); |
| 812 | find_replace_all ("$var", var_name, prep_code); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void get_policy_usage_call::fill_in_command (void) |
| 817 | { |
| 818 | // (call_code already loaded by constructor) |
| 819 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 820 | find_replace_1st ("$usage", asset_info.get_name() + "_usage", call_code); |
| 821 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 822 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /********************************************************************************** |
| 826 | End of methods of class get_policy_usage_call. |
| 827 | **********************************************************************************/ |
| 828 | |
| 829 | |
| 830 | /********************************************************************************** |
| 831 | Methods of class print_policy_usage_call follow: |
| 832 | **********************************************************************************/ |
| 833 | |
| 834 | print_policy_usage_call::print_policy_usage_call (tf_fuzz_info *test_state, |
| 835 | long &call_ser_no, // (constructor) |
| 836 | asset_search how_asset_found) |
| 837 | : policy_call(test_state, call_ser_no, |
| 838 | how_asset_found) |
| 839 | { |
| 840 | // Copy the boilerplate text into local buffers: |
| 841 | prep_code.assign (""); |
| 842 | call_code.assign (test_state->bplate->bplate_string[print_policy_usage]); |
| 843 | call_description = "policy usage-print call"; |
| 844 | } |
| 845 | print_policy_usage_call::~print_policy_usage_call (void) |
| 846 | { |
| 847 | return; // just to have something to pin a breakpoint onto |
| 848 | } |
| 849 | |
| 850 | bool print_policy_usage_call::copy_call_to_asset (void) |
| 851 | { |
| 852 | return copy_call_to_asset_t<policy_asset*> (this, dont_create_asset); |
| 853 | } |
| 854 | |
| 855 | void print_policy_usage_call::fill_in_prep_code (void) |
| 856 | { |
| 857 | string var_name = asset_info.get_name() + "_usage"; |
| 858 | vector<variable_info>::iterator assign_variable; |
| 859 | |
| 860 | policy_fill_in_prep_code(); // make sure the policy variable itself is defined |
| 861 | // Make sure policy-usage variable is defined: |
| 862 | assign_variable = test_state->find_var (var_name); |
| 863 | if (assign_variable == test_state->variable.end()) { |
| 864 | // No such variable exists, so: |
| 865 | test_state->make_var (var_name); |
| 866 | prep_code.append (test_state->bplate->bplate_string[declare_policy_usage]); |
| 867 | find_replace_all ("$var", var_name, prep_code); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | void print_policy_usage_call::fill_in_command (void) |
| 872 | { |
| 873 | string var_name = asset_info.get_name() + "_usage"; |
| 874 | |
| 875 | // (call_code already loaded by constructor) |
| 876 | find_replace_all ("$policy", asset_info.get_name(), call_code); |
| 877 | find_replace_1st ("$usage_string", policy.usage_string, call_code); |
| 878 | find_replace_1st ("$usage", var_name, call_code); |
| 879 | find_replace_1st ("$print_usage_true_string", policy.print_usage_true_string, |
| 880 | call_code); |
| 881 | find_replace_1st ("$print_usage_false_string", policy.print_usage_false_string, |
| 882 | call_code); |
| 883 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 884 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /********************************************************************************** |
| 888 | End of methods of class print_policy_usage_call. |
| 889 | **********************************************************************************/ |
| 890 | |
| 891 | |
| 892 | /********************************************************************************** |
| 893 | Methods of class get_key_policy_call follow: |
| 894 | **********************************************************************************/ |
| 895 | |
| 896 | get_key_policy_call::get_key_policy_call (tf_fuzz_info *test_state, // (constructor) |
| 897 | long &call_ser_no, |
| 898 | asset_search how_asset_found) |
| 899 | : policy_call(test_state, call_ser_no, |
| 900 | how_asset_found) |
| 901 | { |
| 902 | // Copy the boilerplate text into local buffers: |
| 903 | prep_code.assign (""); |
| 904 | call_code.assign (test_state->bplate->bplate_string[get_policy]); |
| 905 | check_code.assign (test_state->bplate->bplate_string[get_policy_check]); |
| 906 | call_description = "policy get call"; |
| 907 | } |
| 908 | get_key_policy_call::~get_key_policy_call (void) |
| 909 | { |
| 910 | return; // just to have something to pin a breakpoint onto |
| 911 | } |
| 912 | |
| 913 | bool get_key_policy_call::copy_call_to_asset (void) |
| 914 | { |
| 915 | return copy_call_to_asset_t<key_asset*> (this, dont_create_asset); |
| 916 | } |
| 917 | |
| 918 | void get_key_policy_call::fill_in_prep_code (void) |
| 919 | { |
| 920 | // No prep code required. |
| 921 | return; // just to have something to pin a breakpoint onto |
| 922 | } |
| 923 | |
| 924 | void get_key_policy_call::fill_in_command (void) |
| 925 | { |
| 926 | // (call_code already loaded by constructor) |
| 927 | find_replace_all ("key", asset_info.get_name(), call_code); |
| 928 | find_replace_all ("$policy", policy.asset_2_name, call_code); |
| 929 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 930 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /********************************************************************************** |
| 934 | End of methods of class get_key_policy_call. |
| 935 | **********************************************************************************/ |
| 936 | |
| 937 | |
| 938 | /********************************************************************************** |
| 939 | Methods of class generate_key_call follow: |
| 940 | **********************************************************************************/ |
| 941 | |
| 942 | generate_key_call::generate_key_call (tf_fuzz_info *test_state, // (constructor) |
| 943 | long &call_ser_no, |
| 944 | asset_search how_asset_found) |
| 945 | : key_call(test_state, call_ser_no, |
| 946 | how_asset_found) |
| 947 | { |
| 948 | // Copy the boilerplate text into local buffers: |
| 949 | prep_code.assign (""); |
| 950 | call_code.assign (test_state->bplate->bplate_string[generate_key]); |
| 951 | check_code.assign (test_state->bplate->bplate_string[generate_key_check]); |
| 952 | call_description = "key-generate call"; |
| 953 | } |
| 954 | generate_key_call::~generate_key_call (void) |
| 955 | { |
| 956 | return; // just to have something to pin a breakpoint onto |
| 957 | } |
| 958 | |
| 959 | bool generate_key_call::copy_call_to_asset (void) |
| 960 | { |
| 961 | return copy_call_to_asset_t<key_asset*> (this, yes_create_asset); |
| 962 | } |
| 963 | |
| 964 | void generate_key_call::fill_in_prep_code (void) |
| 965 | { |
| 966 | string var_name = asset_info.get_name(); |
| 967 | vector<variable_info>::iterator assign_variable; |
| 968 | |
| 969 | // Make sure key variable is defined: |
| 970 | assign_variable = test_state->find_var (var_name); |
| 971 | if (assign_variable == test_state->variable.end()) { |
| 972 | // No such variable exists, so: |
| 973 | test_state->make_var (var_name); |
| 974 | prep_code.append (test_state->bplate->bplate_string[declare_key]); |
| 975 | find_replace_all ("$var", var_name, prep_code); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | void generate_key_call::fill_in_command (void) |
| 980 | { |
| 981 | // (call_code already loaded by constructor) |
| 982 | find_replace_all ("$policy", policy.asset_2_name, call_code); |
| 983 | find_replace_all ("$key", asset_info.get_name(), call_code); |
| 984 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 985 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /********************************************************************************** |
| 989 | End of methods of class generate_key_call. |
| 990 | **********************************************************************************/ |
| 991 | |
| 992 | |
| 993 | /********************************************************************************** |
| 994 | Methods of class create_key_call follow: |
| 995 | **********************************************************************************/ |
| 996 | |
| 997 | create_key_call::create_key_call (tf_fuzz_info *test_state, // (constructor) |
| 998 | long &call_ser_no, |
| 999 | asset_search how_asset_found) |
| 1000 | : key_call(test_state, call_ser_no, |
| 1001 | how_asset_found) |
| 1002 | { |
| 1003 | // Copy the boilerplate text into local buffers: |
| 1004 | prep_code.assign (""); |
| 1005 | call_code.assign (test_state->bplate->bplate_string[create_key]); |
| 1006 | check_code.assign (test_state->bplate->bplate_string[create_key_check]); |
| 1007 | call_description = "key-create call"; |
| 1008 | } |
| 1009 | create_key_call::~create_key_call (void) |
| 1010 | { |
| 1011 | return; // just to have something to pin a breakpoint onto |
| 1012 | } |
| 1013 | |
| 1014 | bool create_key_call::copy_call_to_asset (void) |
| 1015 | { |
| 1016 | return copy_call_to_asset_t<key_asset*> (this, yes_create_asset); |
| 1017 | } |
| 1018 | |
| 1019 | void create_key_call::fill_in_prep_code (void) |
| 1020 | { |
| 1021 | string var_name = asset_info.get_name(); |
| 1022 | vector<variable_info>::iterator assign_variable; |
| 1023 | gibberish gib; |
| 1024 | char gib_buff[500]; |
| 1025 | string t_string; |
| 1026 | |
| 1027 | // Key variable: |
| 1028 | assign_variable = test_state->find_var (var_name); |
| 1029 | if (assign_variable == test_state->variable.end()) { |
| 1030 | // No such variable exists, so: |
| 1031 | test_state->make_var (var_name); |
| 1032 | prep_code.append (test_state->bplate->bplate_string[declare_key]); |
| 1033 | find_replace_all ("$var", var_name, prep_code); |
| 1034 | } |
| 1035 | // Key-data variable: |
| 1036 | var_name = asset_info.get_name() + "_set_data"; |
| 1037 | assign_variable = test_state->find_var (var_name); |
| 1038 | if (assign_variable == test_state->variable.end()) { |
| 1039 | // No such variable exists, so: |
| 1040 | test_state->make_var (var_name); |
| 1041 | prep_code.append (test_state->bplate->bplate_string[declare_big_string]); |
| 1042 | find_replace_all ("$var", var_name, prep_code); |
| 1043 | int rand_data_length = 12 + (rand() % 100); |
| 1044 | gib.sentence (gib_buff, gib_buff + rand_data_length - 1); |
| 1045 | t_string = gib_buff; |
| 1046 | find_replace_all ("$init", t_string, prep_code); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void create_key_call::fill_in_command (void) |
| 1051 | { |
| 1052 | // (call_code already loaded by constructor) |
| 1053 | find_replace_all ("$policy", policy.asset_2_name, call_code); |
| 1054 | find_replace_all ("$data", asset_info.get_name() + "_set_data", call_code); |
| 1055 | find_replace_all ("$length", to_string (policy.n_bits), call_code); |
| 1056 | find_replace_all ("$key", asset_info.get_name(), call_code); |
| 1057 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1058 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /********************************************************************************** |
| 1062 | End of methods of class create_key_call. |
| 1063 | **********************************************************************************/ |
| 1064 | |
| 1065 | |
| 1066 | /********************************************************************************** |
| 1067 | Methods of class copy_key_call follow: |
| 1068 | **********************************************************************************/ |
| 1069 | |
| 1070 | copy_key_call::copy_key_call (tf_fuzz_info *test_state, // (constructor) |
| 1071 | long &call_ser_no, |
| 1072 | asset_search how_asset_found) |
| 1073 | : key_call(test_state, call_ser_no, |
| 1074 | how_asset_found) |
| 1075 | { |
| 1076 | // Copy the boilerplate text into local buffers: |
| 1077 | prep_code.assign (""); |
| 1078 | call_code.assign (test_state->bplate->bplate_string[copy_key]); |
| 1079 | check_code.assign (test_state->bplate->bplate_string[copy_key_check]); |
| 1080 | call_description = "key-copy call"; |
| 1081 | } |
| 1082 | copy_key_call::~copy_key_call (void) |
| 1083 | { |
| 1084 | return; // just to have something to pin a breakpoint onto |
| 1085 | } |
| 1086 | |
| 1087 | bool copy_key_call::copy_call_to_asset (void) |
| 1088 | { |
| 1089 | return copy_call_to_asset_t<key_asset*> (this, yes_create_asset); |
| 1090 | } |
| 1091 | |
| 1092 | void copy_key_call::fill_in_prep_code (void) |
| 1093 | { |
| 1094 | string var_name = asset_info.get_name(); |
| 1095 | vector<variable_info>::iterator assign_variable; |
| 1096 | |
| 1097 | // Make sure key variable is defined: |
| 1098 | assign_variable = test_state->find_var (var_name); |
| 1099 | if (assign_variable == test_state->variable.end()) { |
| 1100 | // No such variable exists, so: |
| 1101 | test_state->make_var (var_name); |
| 1102 | prep_code.append (test_state->bplate->bplate_string[declare_key]); |
| 1103 | find_replace_all ("$var", var_name, prep_code); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | void copy_key_call::fill_in_command (void) |
| 1108 | { |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1109 | // (call_code already loaded by constructor) |
| 1110 | find_replace_all ("$master", policy.asset_3_name, call_code); |
| 1111 | find_replace_all ("$policy", policy.asset_2_name, call_code); |
| 1112 | find_replace_all ("$copy", asset_info.get_name(), call_code); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1113 | |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1114 | // TODO:: move error code modelling code to simulate(). |
| 1115 | |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1116 | // Calculate the expected results: |
| 1117 | asset_search find_result; |
| 1118 | vector<psa_asset*>::iterator asset; |
| 1119 | long dummy = 0L; |
| 1120 | // See if the source key does not exist: |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1121 | find_result = test_state-> |
| 1122 | find_or_create_key_asset (psa_asset_search::name, psa_asset_usage::active, |
| 1123 | policy.asset_3_name, (uint64_t) 0, dummy, |
| 1124 | dont_create_asset, asset); |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1125 | |
| 1126 | |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1127 | if (find_result != asset_search::found_active) { |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1128 | exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT"); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1129 | } else { |
| 1130 | // See if the new policy does not exist: |
| 1131 | find_result = test_state-> |
| 1132 | find_or_create_policy_asset (psa_asset_search::name, psa_asset_usage::active, |
| 1133 | policy.asset_2_name, (uint64_t) 0, dummy, |
| 1134 | dont_create_asset, asset); |
| 1135 | if (find_result != asset_search::found_active) { |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1136 | exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT"); |
| 1137 | |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1138 | } else if (!(*asset)->policy.copyable) { |
| 1139 | // See if the source key does not support export: |
| 1140 | // TODO: Or wait, it's the original policy for the key, right? |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1141 | exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED"); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1142 | } |
| 1143 | } |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1144 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /********************************************************************************** |
| 1148 | End of methods of class copy_key_call. |
| 1149 | **********************************************************************************/ |
| 1150 | |
| 1151 | |
| 1152 | /********************************************************************************** |
| 1153 | Methods of class read_key_data_call follow: |
| 1154 | **********************************************************************************/ |
| 1155 | |
| 1156 | read_key_data_call::read_key_data_call (tf_fuzz_info *test_state, // (constructor) |
| 1157 | long &call_ser_no, |
| 1158 | asset_search how_asset_found) |
| 1159 | : key_call(test_state, call_ser_no, |
| 1160 | how_asset_found) |
| 1161 | { |
| 1162 | // Copy the boilerplate text into local buffers: |
| 1163 | prep_code.assign (""); |
| 1164 | call_code.assign (test_state->bplate->bplate_string[read_key_data]); |
| 1165 | check_code.assign (test_state->bplate->bplate_string[read_key_data_check]); |
| 1166 | call_description = "key read-data call"; |
| 1167 | } |
| 1168 | read_key_data_call::~read_key_data_call (void) |
| 1169 | { |
| 1170 | return; // just to have something to pin a breakpoint onto |
| 1171 | } |
| 1172 | |
| 1173 | bool read_key_data_call::copy_call_to_asset (void) |
| 1174 | { |
| 1175 | return copy_call_to_asset_t<key_asset*> (this, dont_create_asset); |
| 1176 | } |
| 1177 | |
| 1178 | void read_key_data_call::fill_in_prep_code (void) |
| 1179 | { |
| 1180 | string var_name, length_var_name, actual_length_var_name, var_name_suffix, |
| 1181 | length_var_name_suffix, temp_string; |
| 1182 | vector<variable_info>::iterator expect_variable; |
| 1183 | vector<variable_info>::iterator assign_variable; |
| 1184 | |
| 1185 | if (exp_data.data_var_specified) { |
| 1186 | var_name.assign (exp_data.data_var + "_data"); |
| 1187 | length_var_name.assign (exp_data.data_var + "_length"); |
| 1188 | /* If actual-data variable doesn't already exist, create variable tracker, |
| 1189 | and write declaration for it: */ |
| 1190 | expect_variable = test_state->find_var (exp_data.data_var); |
| 1191 | if (expect_variable == test_state->variable.end()) { |
| 1192 | // No such variable exists, so: |
| 1193 | test_state->make_var (exp_data.data_var); |
| 1194 | expect_variable = test_state->find_var (exp_data.data_var); |
| 1195 | prep_code.append (test_state->bplate->bplate_string[declare_big_string]); |
| 1196 | find_replace_1st ("$var", var_name, prep_code); |
| 1197 | temp_string = (char *) expect_variable->value; |
| 1198 | find_replace_1st ("$init", temp_string, prep_code); |
| 1199 | // Input data length: |
| 1200 | prep_code.append (test_state->bplate->bplate_string[declare_size_t]); |
| 1201 | find_replace_1st ("$var", length_var_name, prep_code); |
| 1202 | find_replace_1st ("$init", to_string(temp_string.length()), prep_code); |
| 1203 | // TODO: Is these lengths in bits or bytes? |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1204 | // Actual (output) data length: |
| 1205 | actual_length_var_name.assign (exp_data.data_var + "_act_length"); |
| 1206 | prep_code.append (test_state->bplate->bplate_string[declare_size_t]); |
| 1207 | find_replace_1st ("$var", actual_length_var_name, prep_code); |
| 1208 | find_replace_1st ("$init", to_string(temp_string.length()), prep_code); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1209 | } |
| 1210 | } |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1211 | if (assign_data_var_specified) { |
| 1212 | var_name.assign (assign_data_var + "_data"); |
| 1213 | length_var_name.assign (assign_data_var + "_length"); |
| 1214 | actual_length_var_name.assign (assign_data_var + "_act_length"); |
| 1215 | /* If actual-data variable doesn't already exist, create variable tracker, |
| 1216 | and write declaration for it: */ |
| 1217 | assign_variable = test_state->find_var (assign_data_var); |
| 1218 | if (assign_variable == test_state->variable.end()) { |
| 1219 | // No such variable exists, so: |
| 1220 | test_state->make_var (assign_data_var); |
| 1221 | assign_variable = test_state->find_var (assign_data_var); |
| 1222 | prep_code.append (test_state->bplate->bplate_string[declare_big_string]); |
| 1223 | find_replace_1st ("$var", var_name, prep_code); |
| 1224 | temp_string = (char *) assign_variable->value; |
| 1225 | find_replace_1st ("$init", temp_string, prep_code); |
| 1226 | // Input data length: |
| 1227 | prep_code.append (test_state->bplate->bplate_string[declare_size_t]); |
| 1228 | find_replace_1st ("$var", length_var_name, prep_code); |
| 1229 | find_replace_1st ("$init", to_string(temp_string.length()), prep_code); |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1230 | // Actual (output) data length: |
| 1231 | prep_code.append (test_state->bplate->bplate_string[declare_size_t]); |
| 1232 | find_replace_1st ("$var", actual_length_var_name, prep_code); |
| 1233 | find_replace_1st ("$init", to_string(temp_string.length()), prep_code); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1234 | } |
| 1235 | } else { |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1236 | // Single string of two lines declaring string data and its length: |
| 1237 | var_name_suffix = "_set_data"; |
| 1238 | length_var_name_suffix = "_set_length"; |
| 1239 | if (set_data.n_set_vars > 0) { |
| 1240 | var_name_suffix += "_" + to_string(set_data.n_set_vars); |
| 1241 | length_var_name_suffix += "_" + to_string(set_data.n_set_vars); |
| 1242 | } |
| 1243 | var_name.assign (asset_info.get_name() + var_name_suffix); |
| 1244 | length_var_name.assign (asset_info.get_name() + length_var_name_suffix); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1245 | prep_code.append (test_state->bplate->bplate_string[declare_string]); |
| 1246 | find_replace_1st ("$var", var_name, prep_code); |
| 1247 | find_replace_1st ("$init", set_data.get(), prep_code); |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1248 | temp_string.assign (test_state->bplate->bplate_string[declare_int]); |
| 1249 | find_replace_1st ("static int", "static uint32_t", temp_string); |
| 1250 | prep_code.append (temp_string); |
| 1251 | find_replace_1st ("$var", length_var_name, prep_code); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1252 | find_replace_1st ("$init", to_string(set_data.get().length()), prep_code); |
| 1253 | } |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | void read_key_data_call::fill_in_command (void) |
| 1257 | { |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1258 | string var_name, length_var_name, actual_length_var_name, var_name_suffix, |
| 1259 | length_var_name_suffix, temp_string; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1260 | |
| 1261 | // Fill in the PSA command itself: |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1262 | if (exp_data.data_var_specified) { |
| 1263 | var_name.assign (exp_data.data_var + "_data"); |
| 1264 | actual_length_var_name.assign (exp_data.data_var + "_act_length"); |
| 1265 | } else { |
| 1266 | actual_length_var_name.assign (assign_data_var + "_act_length"); |
| 1267 | } |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1268 | if (assign_data_var_specified) { |
| 1269 | var_name.assign (assign_data_var + "_data"); |
| 1270 | length_var_name.assign (assign_data_var + "_length"); |
| 1271 | } else { |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1272 | var_name_suffix = "_set_data"; |
| 1273 | if (set_data.n_set_vars > 0) { |
| 1274 | var_name_suffix += "_" + to_string(set_data.n_set_vars); |
| 1275 | } |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1276 | var_name.assign (asset_info.get_name() + var_name_suffix); |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1277 | length_var_name_suffix = "_set_length"; |
| 1278 | if (set_data.n_set_vars > 0) { |
| 1279 | length_var_name_suffix += "_" + to_string(set_data.n_set_vars); |
| 1280 | } |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1281 | length_var_name.assign (asset_info.get_name() + length_var_name_suffix); |
| 1282 | } |
| 1283 | find_replace_1st ("$data", var_name, call_code); |
| 1284 | find_replace_1st ("$key", asset_info.get_name(), call_code); |
| 1285 | string id_string = to_string((long) asset_info.id_n++); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1286 | find_replace_1st ("$act_size", actual_length_var_name, call_code); |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1287 | find_replace_1st ("$length", length_var_name, call_code); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1288 | |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1289 | // TODO: move error checking code to simulate(). |
| 1290 | |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 1291 | // TODO: check data? |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1292 | |
| 1293 | // See if the source key did not exist: |
| 1294 | if (!policy.exportable) { |
| 1295 | // See if the source key does not support export: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1296 | exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED"); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1297 | } |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1298 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /********************************************************************************** |
| 1302 | End of methods of class read_key_data_call. |
| 1303 | **********************************************************************************/ |
| 1304 | |
| 1305 | |
| 1306 | /********************************************************************************** |
| 1307 | Methods of class remove_key_call follow: |
| 1308 | **********************************************************************************/ |
| 1309 | |
| 1310 | remove_key_call::remove_key_call (tf_fuzz_info *test_state, // (constructor) |
| 1311 | long &call_ser_no, |
| 1312 | asset_search how_asset_found) |
| 1313 | : key_call(test_state, call_ser_no, |
| 1314 | how_asset_found) |
| 1315 | { |
| 1316 | // Copy the boilerplate text into local buffers: |
| 1317 | prep_code.assign (""); |
| 1318 | call_code.assign (test_state->bplate->bplate_string[remove_key]); |
| 1319 | check_code.assign (test_state->bplate->bplate_string[remove_key_check]); |
| 1320 | call_description = "key-remove call"; |
| 1321 | } |
| 1322 | remove_key_call::~remove_key_call (void) |
| 1323 | { |
| 1324 | return; // just to have something to pin a breakpoint onto |
| 1325 | } |
| 1326 | |
| 1327 | bool remove_key_call::copy_call_to_asset (void) |
| 1328 | { |
| 1329 | return copy_call_to_asset_t<key_asset*> (this, dont_create_asset); |
| 1330 | } |
| 1331 | |
| 1332 | void remove_key_call::fill_in_prep_code (void) |
| 1333 | { |
| 1334 | // No prep code required. |
| 1335 | return; // just to have something to pin a breakpoint onto |
| 1336 | } |
| 1337 | |
| 1338 | void remove_key_call::fill_in_command (void) |
| 1339 | { |
| 1340 | // (call_code already loaded by constructor) |
| 1341 | find_replace_all ("$key", asset_info.get_name(), call_code); |
| 1342 | // Calculate the expected results: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 1343 | fill_in_result_code(); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /********************************************************************************** |
| 1347 | End of methods of class remove_key_call. |
| 1348 | **********************************************************************************/ |