blob: b800baae92e7b034b7ea7379de0b0015aaab6b4c [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
Nik Dewallybacae6c2024-07-30 16:58:14 +01002 * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
Karl Zhang3de5ab12021-05-31 11:45:48 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Nik Dewallybacae6c2024-07-30 16:58:14 +01008#include <stdint.h>
Karl Zhang3de5ab12021-05-31 11:45:48 +08009#include <cstdlib>
Nik Dewallybacae6c2024-07-30 16:58:14 +010010#include <iostream>
Karl Zhang3de5ab12021-05-31 11:45:48 +080011
12#include "boilerplate.hpp"
13#include "variables.hpp"
14#include "gibberish.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080015#include "string_ops.hpp"
16#include "data_blocks.hpp"
17#include "psa_asset.hpp"
18#include "find_or_create_asset.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080019#include "tf_fuzz.hpp"
20#include "crypto_asset.hpp"
21#include "psa_call.hpp"
22#include "crypto_call.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080023
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: */
32void 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
47policy_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}
54policy_call::~policy_call (void)
55{
56 // Nothing further to delete.
57 return; // just to have something to pin a breakpoint onto
58}
59
60vector<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
128key_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}
135key_call::~key_call (void)
136{
137 // Nothing further to delete.
138 return; // just to have something to pin a breakpoint onto
139}
140
141vector<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
209init_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}
220init_policy_call::~init_policy_call (void)
221{
222 return; // just to have something to pin a breakpoint onto
223}
224
225bool init_policy_call::copy_call_to_asset (void)
226{
227 return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset);
228}
229
230void init_policy_call::fill_in_prep_code (void)
231{
232 policy_fill_in_prep_code();
233}
234
235void 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 Dewally6663dde2024-08-09 16:12:27 +0100240 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800241}
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
252reset_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}
263reset_policy_call::~reset_policy_call (void)
264{
265 return; // just to have something to pin a breakpoint onto
266}
267
268bool reset_policy_call::copy_call_to_asset (void)
269{
270 return copy_call_to_asset_t<policy_asset*> (this, yes_create_asset);
271}
272
273void reset_policy_call::fill_in_prep_code (void)
274{
275 policy_fill_in_prep_code();
276}
277
278void 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 Dewally6663dde2024-08-09 16:12:27 +0100283 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800284}
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
295add_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}
306add_policy_usage_call::~add_policy_usage_call (void)
307{
308 return; // just to have something to pin a breakpoint onto
309}
310
311bool 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
316void 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
323void 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 Dewally6663dde2024-08-09 16:12:27 +0100329 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800330}
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
341set_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}
352set_policy_lifetime_call::~set_policy_lifetime_call (void)
353{
354 return; // just to have something to pin a breakpoint onto
355}
356
357bool 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
362void set_policy_lifetime_call::fill_in_prep_code (void)
363{
364 policy_fill_in_prep_code();
365}
366
367void 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 Dewally6663dde2024-08-09 16:12:27 +0100376 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800377}
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
388set_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}
399set_policy_size_call::~set_policy_size_call (void)
400{
401 return; // just to have something to pin a breakpoint onto
402}
403
404bool 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
409void set_policy_size_call::fill_in_prep_code (void)
410{
411 policy_fill_in_prep_code();
412}
413
414void 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 Dewally6663dde2024-08-09 16:12:27 +0100420 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800421}
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
432set_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}
443set_policy_type_call::~set_policy_type_call (void)
444{
445 return; // just to have something to pin a breakpoint onto
446}
447
448bool 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
453void set_policy_type_call::fill_in_prep_code (void)
454{
455 policy_fill_in_prep_code();
456}
457
458void 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 Dewally6663dde2024-08-09 16:12:27 +0100464 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800465}
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
476set_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}
487set_policy_algorithm_call::~set_policy_algorithm_call (void)
488{
489 return; // just to have something to pin a breakpoint onto
490}
491
492bool 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
497void set_policy_algorithm_call::fill_in_prep_code (void)
498{
499 policy_fill_in_prep_code();
500}
501
502void 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 Dewally6663dde2024-08-09 16:12:27 +0100508 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800509}
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
520set_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}
531set_policy_usage_call::~set_policy_usage_call (void)
532{
533 return; // just to have something to pin a breakpoint onto
534}
535
536bool 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
541void set_policy_usage_call::fill_in_prep_code (void)
542{
543 policy_fill_in_prep_code();
544}
545
546void 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 Dewally6663dde2024-08-09 16:12:27 +0100551 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800552}
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
563get_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}
574get_policy_lifetime_call::~get_policy_lifetime_call (void)
575{
576 return; // just to have something to pin a breakpoint onto
577}
578
579bool 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
584void 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
599void 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 Dewally6663dde2024-08-09 16:12:27 +0100605 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800606}
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
617get_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}
628get_policy_size_call::~get_policy_size_call (void)
629{
630 return; // just to have something to pin a breakpoint onto
631}
632
633bool 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
638void 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
654void 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 Dewally6663dde2024-08-09 16:12:27 +0100660 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800661}
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
672get_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}
683get_policy_type_call::~get_policy_type_call (void)
684{
685 return; // just to have something to pin a breakpoint onto
686}
687
688bool 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
693void 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
708void 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 Dewally6663dde2024-08-09 16:12:27 +0100714 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800715}
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
726get_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}
737get_policy_algorithm_call::~get_policy_algorithm_call (void)
738{
739 return; // just to have something to pin a breakpoint onto
740}
741
742bool 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
747void 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
762void 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 Dewally6663dde2024-08-09 16:12:27 +0100768 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800769}
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
780get_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}
791get_policy_usage_call::~get_policy_usage_call (void)
792{
793 return; // just to have something to pin a breakpoint onto
794}
795
796bool 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
801void 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
816void 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 Dewally6663dde2024-08-09 16:12:27 +0100822 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800823}
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
834print_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}
845print_policy_usage_call::~print_policy_usage_call (void)
846{
847 return; // just to have something to pin a breakpoint onto
848}
849
850bool 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
855void 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
871void 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 Dewally6663dde2024-08-09 16:12:27 +0100884 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800885}
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
896get_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}
908get_key_policy_call::~get_key_policy_call (void)
909{
910 return; // just to have something to pin a breakpoint onto
911}
912
913bool 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
918void 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
924void 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 Dewally6663dde2024-08-09 16:12:27 +0100930 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800931}
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
942generate_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}
954generate_key_call::~generate_key_call (void)
955{
956 return; // just to have something to pin a breakpoint onto
957}
958
959bool generate_key_call::copy_call_to_asset (void)
960{
961 return copy_call_to_asset_t<key_asset*> (this, yes_create_asset);
962}
963
964void 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
979void 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 Dewally6663dde2024-08-09 16:12:27 +0100985 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +0800986}
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
997create_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}
1009create_key_call::~create_key_call (void)
1010{
1011 return; // just to have something to pin a breakpoint onto
1012}
1013
1014bool create_key_call::copy_call_to_asset (void)
1015{
1016 return copy_call_to_asset_t<key_asset*> (this, yes_create_asset);
1017}
1018
1019void 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
1050void 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 Dewally6663dde2024-08-09 16:12:27 +01001058 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +08001059}
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
1070copy_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}
1082copy_key_call::~copy_key_call (void)
1083{
1084 return; // just to have something to pin a breakpoint onto
1085}
1086
1087bool copy_key_call::copy_call_to_asset (void)
1088{
1089 return copy_call_to_asset_t<key_asset*> (this, yes_create_asset);
1090}
1091
1092void 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
1107void copy_key_call::fill_in_command (void)
1108{
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001109 // (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 Zhang3de5ab12021-05-31 11:45:48 +08001113
Nik Dewally6663dde2024-08-09 16:12:27 +01001114 // TODO:: move error code modelling code to simulate().
1115
Karl Zhang3de5ab12021-05-31 11:45:48 +08001116 // 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-Palffba10e2021-09-22 21:38:03 +02001121 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 Dewally6663dde2024-08-09 16:12:27 +01001125
1126
Karl Zhang3de5ab12021-05-31 11:45:48 +08001127 if (find_result != asset_search::found_active) {
Nik Dewally6663dde2024-08-09 16:12:27 +01001128 exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
Karl Zhang3de5ab12021-05-31 11:45:48 +08001129 } 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 Dewally6663dde2024-08-09 16:12:27 +01001136 exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
1137
Karl Zhang3de5ab12021-05-31 11:45:48 +08001138 } 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 Dewally6663dde2024-08-09 16:12:27 +01001141 exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
Karl Zhang3de5ab12021-05-31 11:45:48 +08001142 }
1143 }
Nik Dewally6663dde2024-08-09 16:12:27 +01001144 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +08001145}
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
1156read_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}
1168read_key_data_call::~read_key_data_call (void)
1169{
1170 return; // just to have something to pin a breakpoint onto
1171}
1172
1173bool 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
1178void 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-Palffba10e2021-09-22 21:38:03 +02001204 // 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 Zhang3de5ab12021-05-31 11:45:48 +08001209 }
1210 }
Karl Zhang3de5ab12021-05-31 11:45:48 +08001211 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-Palffba10e2021-09-22 21:38:03 +02001230 // 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 Zhang3de5ab12021-05-31 11:45:48 +08001234 }
1235 } else {
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001236 // 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 Zhang3de5ab12021-05-31 11:45:48 +08001245 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-Palffba10e2021-09-22 21:38:03 +02001248 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 Zhang3de5ab12021-05-31 11:45:48 +08001252 find_replace_1st ("$init", to_string(set_data.get().length()), prep_code);
1253 }
Karl Zhang3de5ab12021-05-31 11:45:48 +08001254}
1255
1256void read_key_data_call::fill_in_command (void)
1257{
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001258 string var_name, length_var_name, actual_length_var_name, var_name_suffix,
1259 length_var_name_suffix, temp_string;
Karl Zhang3de5ab12021-05-31 11:45:48 +08001260
1261 // Fill in the PSA command itself:
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001262 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 Zhang3de5ab12021-05-31 11:45:48 +08001268 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-Palffba10e2021-09-22 21:38:03 +02001272 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 Zhang3de5ab12021-05-31 11:45:48 +08001276 var_name.assign (asset_info.get_name() + var_name_suffix);
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001277 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 Zhang3de5ab12021-05-31 11:45:48 +08001281 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 Zhang3de5ab12021-05-31 11:45:48 +08001286 find_replace_1st ("$act_size", actual_length_var_name, call_code);
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001287 find_replace_1st ("$length", length_var_name, call_code);
Karl Zhang3de5ab12021-05-31 11:45:48 +08001288
Nik Dewally6663dde2024-08-09 16:12:27 +01001289 // TODO: move error checking code to simulate().
1290
Mate Toth-Palffba10e2021-09-22 21:38:03 +02001291 // TODO: check data?
Karl Zhang3de5ab12021-05-31 11:45:48 +08001292
1293 // See if the source key did not exist:
1294 if (!policy.exportable) {
1295 // See if the source key does not support export:
Nik Dewally6663dde2024-08-09 16:12:27 +01001296 exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
Karl Zhang3de5ab12021-05-31 11:45:48 +08001297 }
Nik Dewally6663dde2024-08-09 16:12:27 +01001298 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +08001299}
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
1310remove_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}
1322remove_key_call::~remove_key_call (void)
1323{
1324 return; // just to have something to pin a breakpoint onto
1325}
1326
1327bool remove_key_call::copy_call_to_asset (void)
1328{
1329 return copy_call_to_asset_t<key_asset*> (this, dont_create_asset);
1330}
1331
1332void 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
1338void 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 Dewally6663dde2024-08-09 16:12:27 +01001343 fill_in_result_code();
Karl Zhang3de5ab12021-05-31 11:45:48 +08001344}
1345
1346/**********************************************************************************
1347 End of methods of class remove_key_call.
1348**********************************************************************************/