blob: 69376866d0cca62799f0ab6cb1c12f15f9f32bc1 [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
Mate Toth-Palffba10e2021-09-22 21:38:03 +02002 * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Karl Zhang3de5ab12021-05-31 11:45:48 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef CRYPTO_CALL_HPP
9#define CRYPTO_CALL_HPP
10
11#include <string>
12#include <vector>
13
14/* This project's header files #including other project headers quickly becomes
15 unrealistically complicated. The only solution is for each .cpp to include
16 the headers it needs.
17#include "psa_call.hpp"
18#include "crypto_asset.hpp"
19*/
20
21template<class T> bool copy_call_to_asset_t (psa_call *call, bool create_asset_bool)
22{
23 vector<psa_asset*>::iterator found_asset;
24
25 found_asset = call->resolve_asset (create_asset_bool, psa_asset_usage::all);
26 // Copy over everything relevant:
27 if (call->asset_info.how_asset_found != asset_search::not_found) {
28 call->asset_info.the_asset = reinterpret_cast<T>(*found_asset);
29 /* Note: The vector is base-class, but the assets in this list
30 themselves *really are* policy_asset-type objects. */
31 int i = call->asset_info.the_asset->set_data.n_set_vars; // save this
Karl Zhang3de5ab12021-05-31 11:45:48 +080032 call->asset_info.the_asset->set_data = call->set_data;
33 call->asset_info.the_asset->set_data.n_set_vars = call->set_data.n_set_vars = ++i;
34 call->asset_info.the_asset->policy = call->policy;
35 call->asset_info.the_asset->handle_str = call->asset_info.get_name();
36 if (call->asset_info.how_asset_found == asset_search::created_new) {
37 call->asset_info.the_asset->asset_info.name_specified
38 = call->asset_info.name_specified;
39 call->asset_info.the_asset->asset_info.set_name (call->asset_info.get_name());
40 call->asset_info.the_asset->asset_info.asset_ser_no
41 = call->asset_info.asset_ser_no;
42 call->asset_info.the_asset->asset_info.id_n = call->asset_info.id_n;
43 }
44 }
45 return true;
46}
47
48
49using namespace std;
50
51class policy_call : public crypto_call
52{
53public:
54 // Data members: // (low value in hiding these behind setters and getters)
55 // Methods:
56 vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
57 psa_asset_usage where);
58 void policy_fill_in_prep_code (void);
59 policy_call (tf_fuzz_info *test_state, long &asset_ser_no,
60 asset_search how_asset_found); // (constructor)
61 ~policy_call (void);
62
63protected:
64 // Data members:
65 // Methods:
66// void calc_result_code (void); for *now* keep this in crypto_call::
67
68private:
69 // Data members:
70 // Methods:
71};
72
73
74class key_call : public crypto_call
75{
76public:
77 // Data members: // (low value in hiding these behind setters and getters)
78 // Methods:
79 vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
80 psa_asset_usage where);
81 key_call (tf_fuzz_info *test_state, long &asset_ser_no,
82 asset_search how_asset_found); // (constructor)
83 ~key_call (void);
84
85protected:
86 // Data members:
87 // Methods:
88// void calc_result_code (void); for *now* keep this in crypto_call::
89
90private:
91 // Data members:
92 // Methods:
93};
94
95
96/**********************************************************************************
97 Derived classes of class policy_call follow:
98**********************************************************************************/
99
100
101class init_policy_call : public policy_call
102{
103public:
104 // Data members:
105 // Methods:
106 bool copy_call_to_asset (void);
107 void fill_in_prep_code (void);
108 void fill_in_command (void);
109 init_policy_call (tf_fuzz_info *test_state, long &asset_ser_no,
110 asset_search how_asset_found); // (constructor)
111 ~init_policy_call (void);
112
113
114protected:
115 // Data members:
116 // Methods:
117
118private:
119 // Data members:
120 // Methods:
121};
122
123
124class reset_policy_call : public policy_call
125{
126public:
127 // Data members:
128 // Methods:
129 bool copy_call_to_asset (void);
130 void fill_in_prep_code (void);
131 void fill_in_command (void);
132 reset_policy_call (tf_fuzz_info *test_state, long &asset_ser_no,
133 asset_search how_asset_found); // (constructor)
134 ~reset_policy_call (void);
135
136
137protected:
138 // Data members:
139 // Methods:
140
141private:
142 // Data members:
143 // Methods:
144};
145
146
147class set_policy_usage_call : public policy_call
148{
149public:
150 // Data members:
151 // Methods:
152 bool copy_call_to_asset (void);
153 void fill_in_prep_code (void);
154 void fill_in_command (void);
155 set_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no,
156 asset_search how_asset_found); // (constructor)
157 ~set_policy_usage_call (void);
158
159
160protected:
161 // Data members:
162 // Methods:
163
164private:
165 // Data members:
166 // Methods:
167};
168
169
170/* set_policy_usage_call(), above, gives a policy particular attribute, and resets
171 all others. add_policy_usage_call(), below, ORs in an additional usage
172 attribute, to whatever is already in there. */
173
174class add_policy_usage_call : public policy_call
175{
176public:
177 // Data members:
178 // Methods:
179 bool copy_call_to_asset (void);
180 void fill_in_prep_code (void);
181 void fill_in_command (void);
182 add_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no,
183 asset_search how_asset_found); // (constructor)
184 ~add_policy_usage_call (void);
185
186
187protected:
188 // Data members:
189 // Methods:
190
191private:
192 // Data members:
193 // Methods:
194};
195
196
197class set_policy_lifetime_call : public policy_call
198{
199public:
200 // Data members:
201 // Methods:
202 bool copy_call_to_asset (void);
203 void fill_in_prep_code (void);
204 void fill_in_command (void);
205 set_policy_lifetime_call (tf_fuzz_info *test_state, long &asset_ser_no,
206 asset_search how_asset_found); // (constructor)
207 ~set_policy_lifetime_call (void);
208
209
210protected:
211 // Data members:
212 // Methods:
213
214private:
215 // Data members:
216 // Methods:
217};
218
219
220class set_policy_algorithm_call : public policy_call
221{
222public:
223 // Data members:
224 // Methods:
225 bool copy_call_to_asset (void);
226 void fill_in_prep_code (void);
227 void fill_in_command (void);
228 set_policy_algorithm_call (tf_fuzz_info *test_state, long &asset_ser_no,
229 asset_search how_asset_found); // (constructor)
230 ~set_policy_algorithm_call (void);
231
232
233protected:
234 // Data members:
235 // Methods:
236
237private:
238 // Data members:
239 // Methods:
240};
241
242
243class set_policy_size_call : public policy_call
244{
245public:
246 // Data members:
247 // Methods:
248 bool copy_call_to_asset (void);
249 void fill_in_prep_code (void);
250 void fill_in_command (void);
251 set_policy_size_call (tf_fuzz_info *test_state, long &asset_ser_no,
252 asset_search how_asset_found); // (constructor)
253 ~set_policy_size_call (void);
254
255
256protected:
257 // Data members:
258 // Methods:
259
260private:
261 // Data members:
262 // Methods:
263};
264
265
266class set_policy_type_call : public policy_call
267{
268public:
269 // Data members:
270 // Methods:
271 bool copy_call_to_asset (void);
272 void fill_in_prep_code (void);
273 void fill_in_command (void);
274 set_policy_type_call (tf_fuzz_info *test_state, long &asset_ser_no,
275 asset_search how_asset_found); // (constructor)
276 ~set_policy_type_call (void);
277
278
279protected:
280 // Data members:
281 // Methods:
282
283private:
284 // Data members:
285 // Methods:
286};
287
288
289class get_policy_lifetime_call : public policy_call
290{
291public:
292 // Data members:
293 // Methods:
294 bool copy_call_to_asset (void);
295 void fill_in_prep_code (void);
296 void fill_in_command (void);
297 get_policy_lifetime_call (tf_fuzz_info *test_state, long &asset_ser_no,
298 asset_search how_asset_found); // (constructor)
299 ~get_policy_lifetime_call (void);
300
301
302protected:
303 // Data members:
304 // Methods:
305
306private:
307 // Data members:
308 // Methods:
309};
310
311
312class get_policy_size_call : public policy_call
313{
314public:
315 // Data members:
316 // Methods:
317 bool copy_call_to_asset (void);
318 void fill_in_prep_code (void);
319 void fill_in_command (void);
320 get_policy_size_call (tf_fuzz_info *test_state, long &asset_ser_no,
321 asset_search how_asset_found); // (constructor)
322 ~get_policy_size_call (void);
323
324
325protected:
326 // Data members:
327 // Methods:
328
329private:
330 // Data members:
331 // Methods:
332};
333
334
335class get_policy_type_call : public policy_call
336{
337public:
338 // Data members:
339 // Methods:
340 bool copy_call_to_asset (void);
341 void fill_in_prep_code (void);
342 void fill_in_command (void);
343 get_policy_type_call (tf_fuzz_info *test_state, long &asset_ser_no,
344 asset_search how_asset_found); // (constructor)
345 ~get_policy_type_call (void);
346
347
348protected:
349 // Data members:
350 // Methods:
351
352private:
353 // Data members:
354 // Methods:
355};
356
357
358class get_policy_algorithm_call : public policy_call
359{
360public:
361 // Data members:
362 // Methods:
363 bool copy_call_to_asset (void);
364 void fill_in_prep_code (void);
365 void fill_in_command (void);
366 get_policy_algorithm_call (tf_fuzz_info *test_state, long &asset_ser_no,
367 asset_search how_asset_found); // (constructor)
368 ~get_policy_algorithm_call (void);
369
370
371protected:
372 // Data members:
373 // Methods:
374
375private:
376 // Data members:
377 // Methods:
378};
379
380
381class get_policy_usage_call : public policy_call
382{
383public:
384 // Data members:
385 // Methods:
386 bool copy_call_to_asset (void);
387 void fill_in_prep_code (void);
388 void fill_in_command (void);
389 get_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no,
390 asset_search how_asset_found); // (constructor)
391 ~get_policy_usage_call (void);
392
393
394protected:
395 // Data members:
396 // Methods:
397
398private:
399 // Data members:
400 // Methods:
401};
402
403
404/* This is not actually a PSA call; it just emits code to print out, to the log,
405 information about the usage info retrieved in a get_policy_usage_call above. */
406class print_policy_usage_call : public policy_call
407{
408public:
409 // Data members:
410 // Methods:
411 bool copy_call_to_asset (void);
412 void fill_in_prep_code (void);
413 void fill_in_command (void);
414 print_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no,
415 asset_search how_asset_found); // (constructor)
416 ~print_policy_usage_call (void);
417
418
419protected:
420 // Data members:
421 // Methods:
422
423private:
424 // Data members:
425 // Methods:
426};
427
428
429class get_key_policy_call : public policy_call
430{
431public:
432 // Data members:
433 // Methods:
434 bool copy_call_to_asset (void);
435 void fill_in_prep_code (void);
436 void fill_in_command (void);
437 get_key_policy_call (tf_fuzz_info *test_state, long &asset_ser_no,
438 asset_search how_asset_found); // (constructor)
439 ~get_key_policy_call (void);
440
441
442protected:
443 // Data members:
444 // Methods:
445
446private:
447 // Data members:
448 // Methods:
449};
450
451
452/**********************************************************************************
453 End of derived classes of class policy_call.
454**********************************************************************************/
455
456
457/**********************************************************************************
458 Derived classes of class key_call follow:
459**********************************************************************************/
460
461
462class generate_key_call : public key_call
463{
464public:
465 // Data members:
466 // Methods:
467 bool copy_call_to_asset (void);
468 void fill_in_prep_code (void);
469 void fill_in_command (void);
470 generate_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
471 asset_search how_asset_found); // (constructor)
472 ~generate_key_call (void);
473
474
475protected:
476 // Data members:
477 // Methods:
478
479private:
480 // Data members:
481 // Methods:
482};
483
484
485class create_key_call : public key_call
486{
487public:
488 // Data members:
489 // Methods:
490 bool copy_call_to_asset (void);
491 void fill_in_prep_code (void);
492 void fill_in_command (void);
493 create_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
494 asset_search how_asset_found); // (constructor)
495 ~create_key_call (void);
496
497
498protected:
499 // Data members:
500 // Methods:
501
502private:
503 // Data members:
504 // Methods:
505};
506
507
508class copy_key_call : public key_call
509{
510public:
511 // Data members:
512 // Methods:
513 bool copy_call_to_asset (void);
514 void fill_in_prep_code (void);
515 void fill_in_command (void);
516 copy_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
517 asset_search how_asset_found); // (constructor)
518 ~copy_key_call (void);
519
520
521protected:
522 // Data members:
523 // Methods:
524
525private:
526 // Data members:
527 // Methods:
528};
529
530
531class read_key_data_call : public key_call
532{
533public:
534 // Data members:
535 // Methods:
536 bool copy_call_to_asset (void);
537 void fill_in_prep_code (void);
538 void fill_in_command (void);
539 read_key_data_call (tf_fuzz_info *test_state, long &asset_ser_no,
540 asset_search how_asset_found); // (constructor)
541 ~read_key_data_call (void);
542
543
544protected:
545 // Data members:
546 // Methods:
547
548private:
549 // Data members:
550 // Methods:
551};
552
553
554class remove_key_call : public key_call
555{
556public:
557 // Data members:
558 // Methods:
559 bool copy_call_to_asset (void);
560 void fill_in_prep_code (void);
561 void fill_in_command (void);
562 remove_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
563 asset_search how_asset_found); // (constructor)
564 ~remove_key_call (void);
565
566
567protected:
568 // Data members:
569 // Methods:
570
571private:
572 // Data members:
573 // Methods:
574};
575
576
577/**********************************************************************************
578 End of derived classes of class key_call.
579**********************************************************************************/
580
581#endif // CRYPTO_CALL_HPP