tf_fuzz: refactor expected value storage and simulation flow

Refactor the storage of expected values (expected_info), and add a
simulate function to psa_call, allowing expected value modelling and
call simulation code to be eventually combined into a single method.

* expected_info currently uses a set of mutually-exclusive boolean flags
  to model the different possible return codes. As the flags are checked
  in different orders across the code-base, failing to unset the right
  flags could cause different areas of the code to use different
  expected values.

  In this commit, an enum is used instead. This allows expected result
  checking to be performed by a single switch statement. This also makes
  checking to see if the value needs to be simulated much clearer --
  currently, this is denoted by both pf_nothing and pf_pass being false.

* Remove expected_info fields with no use.

* There is no one place where call simulation and expected error code
  modelling occurs. Expected return code modelling currently occur in
  fill_in_command and calc_result_code, and call simulation in
  copy_call_to_asset.

  The new psa_call::simulate() method is intended as the singular home
  for all call simulation code. Combining the simulation of a call's
  actions and its expected result should make modelling easier. This
  also makes expected value modelling happen in the simulation step
  only instead of in both the simulation and code-generation steps
  (fill_in_command and calc_result_code are code generation methods).

  Due to upcoming changes to the crypto simulation, moving call
  simulation code to simulate() has been left for future commits.

Change-Id: I1173164f07a3615c157845ed3abfebefde675c89
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-cpp/calls/crypto_call.cpp b/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
index 4ff2ce3..b800baa 100644
--- a/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
+++ b/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
@@ -237,7 +237,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -280,7 +280,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -326,7 +326,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$flag", policy.usage_string, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -373,7 +373,7 @@
                                          : "PSA_KEY_LIFETIME_VOLATILE",
                       call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -417,7 +417,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$size", to_string (policy.n_bits), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -461,7 +461,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$type", policy.key_type, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -505,7 +505,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$algorithm", policy.key_algorithm, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -548,7 +548,7 @@
     find_replace_1st ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$usage", "0", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -602,7 +602,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$life", asset_info.get_name() + "_life", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -657,7 +657,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$size", asset_info.get_name() + "_size", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -711,7 +711,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$type", asset_info.get_name() + "_type", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -765,7 +765,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$algorithm", asset_info.get_name() + "_algo", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -819,7 +819,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$usage", asset_info.get_name() + "_usage", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -881,7 +881,7 @@
     find_replace_1st ("$print_usage_false_string", policy.print_usage_false_string,
                       call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -927,7 +927,7 @@
     find_replace_all ("key", asset_info.get_name(), call_code);
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -982,7 +982,7 @@
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1055,7 +1055,7 @@
     find_replace_all ("$length", to_string (policy.n_bits), call_code);
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1111,6 +1111,8 @@
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     find_replace_all ("$copy", asset_info.get_name(), call_code);
 
+    // TODO:: move error code modelling code to simulate().
+
     // Calculate the expected results:
     asset_search find_result;
     vector<psa_asset*>::iterator asset;
@@ -1120,10 +1122,10 @@
         find_or_create_key_asset (psa_asset_search::name, psa_asset_usage::active,
                                   policy.asset_3_name, (uint64_t) 0, dummy,
                                   dont_create_asset, asset);
+
+
     if (find_result != asset_search::found_active) {
-        exp_data.pf_specified = true;
-        exp_data.pf_result_string = "PSA_ERROR_INVALID_ARGUMENT";
-            // TODO:  Pull this in from boilerplate file
+        exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
     } else {
         // See if the new policy does not exist:
         find_result = test_state->
@@ -1131,17 +1133,15 @@
                                          policy.asset_2_name, (uint64_t) 0, dummy,
                                          dont_create_asset, asset);
         if (find_result != asset_search::found_active) {
-            exp_data.pf_specified = true;
-            exp_data.pf_result_string = "PSA_ERROR_INVALID_ARGUMENT";
-                // TODO:  Pull this in from boilerplate file
+            exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
+
         } else if (!(*asset)->policy.copyable) {
             // See if the source key does not support export:
             // TODO:  Or wait, it's the original policy for the key, right?
-            exp_data.pf_specified = true;
-            exp_data.pf_result_string = "PSA_ERROR_NOT_PERMITTED";
+            exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
         }
     }
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1286,15 +1286,16 @@
     find_replace_1st ("$act_size", actual_length_var_name, call_code);
     find_replace_1st ("$length", length_var_name, call_code);
 
+    // TODO: move error checking code to simulate().
+
     // TODO:  check data?
 
     // See if the source key did not exist:
     if (!policy.exportable) {
         // See if the source key does not support export:
-        exp_data.pf_specified = true;
-        exp_data.pf_result_string = "PSA_ERROR_NOT_PERMITTED";
+        exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
     }
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1339,7 +1340,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
diff --git a/tf_fuzz/tfz-cpp/calls/crypto_call.hpp b/tf_fuzz/tfz-cpp/calls/crypto_call.hpp
index 782bb1b..ff43b45 100644
--- a/tf_fuzz/tfz-cpp/calls/crypto_call.hpp
+++ b/tf_fuzz/tfz-cpp/calls/crypto_call.hpp
@@ -534,9 +534,9 @@
 public:
     // Data members:
     // Methods:
-        bool copy_call_to_asset (void);
-        void fill_in_prep_code (void);
-        void fill_in_command (void);
+        bool copy_call_to_asset (void) override;
+        void fill_in_prep_code (void) override;
+        void fill_in_command (void) override;
         read_key_data_call (tf_fuzz_info *test_state, long &asset_ser_no,
                             asset_search how_asset_found);  // (constructor)
         ~read_key_data_call (void);
@@ -557,9 +557,9 @@
 public:
     // Data members:
     // Methods:
-        bool copy_call_to_asset (void);
-        void fill_in_prep_code (void);
-        void fill_in_command (void);
+        bool copy_call_to_asset (void) override;
+        void fill_in_prep_code (void) override;
+        void fill_in_command (void) override;
         remove_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
                          asset_search how_asset_found);  // (constructor)
         ~remove_key_call (void);
diff --git a/tf_fuzz/tfz-cpp/calls/psa_call.cpp b/tf_fuzz/tfz-cpp/calls/psa_call.cpp
index 1bb8c46..7ca407e 100644
--- a/tf_fuzz/tfz-cpp/calls/psa_call.cpp
+++ b/tf_fuzz/tfz-cpp/calls/psa_call.cpp
@@ -60,13 +60,17 @@
 
 void psa_call::write_out_check_code (ofstream &test_file)
 {
-    if (!exp_data.pf_nothing) {
+    if (exp_data.result_code_checking_enabled()) {
         test_file << check_code;
     } else {
         test_file << "    /* (No checks for this PSA call.) */" << endl;
     }
 }
 
+bool psa_call::simulate(void) {
+    return false;
+}
+
 /**********************************************************************************
    End of methods of class psa_call.
 **********************************************************************************/
@@ -81,15 +85,15 @@
 
    This is a big part of where the target modeling -- error modeling -- occurs,
    so lots of room for further refinement here. */
-void sst_call::calc_result_code (void)
+void sst_call::fill_in_result_code (void)
 {
-    string formalized;  // "proper" result string
 
-    if (exp_data.pf_nothing) { // do not generate result checks
+    string formalized;  // "proper" result string
+    switch (exp_data.get_expected_return_code()) {
+    case expected_return_code_t::DontCare: // Do not generate checks
         return;
 
-    }
-    if (exp_data.pf_pass) { // expect pass
+    case expected_return_code_t::Pass:
         find_replace_all ("$expect",
                           test_state->bplate->bplate_string[sst_pass_string],
                           check_code);
@@ -99,37 +103,38 @@
                           "0",
                           check_code);
 
-    } else if (exp_data.pf_fail) { // expect fail
+        break;
 
-      // If the command is `... check "foo" expect fail;`, the fail
-      // binds to the check, not the command itself.
-      if (exp_data.data_specified) {
-        // expect a pass for the sst call itself.
-        find_replace_all ("$expect",
-                          test_state->bplate->bplate_string[sst_pass_string],
-                          check_code);
+    case expected_return_code_t::Fail:
+        // If the command is `... check "foo" expect fail;`, the fail
+        // binds to the check, not the command itself.
+        if (exp_data.data_specified) {
+          // expect a pass for the sst call itself.
+          find_replace_all ("$expect",
+                            test_state->bplate->bplate_string[sst_pass_string],
+                            check_code);
 
-        // expect a failure for the check.
-        find_replace_all ("!= $check_expect",
-                          "== 0",
-                          check_code);
+          // expect a failure for the check.
+          find_replace_all ("!= $check_expect",
+                            "== 0",
+                            check_code);
 
-        find_replace_1st ("should be equal", "should not be equal",
-                          check_code);
-        } else {
-        // Check for not-success:
-        find_replace_1st ("!=", "==",
-                          check_code);
-        find_replace_all ("$expect",
-                          test_state->bplate->bplate_string[sst_pass_string],
-                          check_code);
-        find_replace_1st ("expected ", "expected not ",
-                          check_code);
+          find_replace_1st ("should be equal", "should not be equal",
+                            check_code);
+          } else {
+          // Check for not-success:
+          find_replace_1st ("!=", "==",
+                            check_code);
+          find_replace_all ("$expect",
+                            test_state->bplate->bplate_string[sst_pass_string],
+                            check_code);
+          find_replace_1st ("expected ", "expected not ",
+                            check_code);
         }
-    }
+        break;
 
-    else if (exp_data.pf_specified) { // expect <PSA_ERROR_CODE>
-        formalized = formalize (exp_data.pf_result_string, "PSA_ERROR_");
+    case expected_return_code_t::SpecificFail:
+        formalized = formalize (exp_data.get_expected_return_code_string(), "PSA_ERROR_");
         find_replace_all ("$expect", formalized, check_code);
 
         // NOTE: Assumes that the variable used to store the actual
@@ -138,10 +143,10 @@
         find_replace_all ("!= $check_expect","== 0",check_code);
         find_replace_1st ("should be equal", "should not be equal",
                           check_code);
-    }
+        break;
 
-    else { // no explicit expect -- simulate
-
+    // TODO: move error code simulation into simulate().
+    case expected_return_code_t::DontKnow: // Simulate
         // Figure out what the message should read:
         switch (asset_info.how_asset_found) {
             case asset_search::found_active:
@@ -183,8 +188,9 @@
                 find_replace_1st ("should be equal", "should not be equal",
                                   check_code);
                 break;
+            }
+            break;
         }
-    }
 }
 
 vector<psa_asset*>::iterator sst_call::resolve_asset (bool create_asset_bool,
@@ -272,54 +278,63 @@
    improved and expanded upon *massively* more or less mirroring what is seen in
    .../test/suites/crypto/crypto_tests_common.c in the psa_key_interface_test()
    method, (starting around line 20ish). */
-void crypto_call::calc_result_code (void)
+void crypto_call::fill_in_result_code (void)
 {
     string formalized;  // "proper" result string
 
-    if (!exp_data.pf_nothing) {
-        if (exp_data.pf_pass) {
-            find_replace_all ("$expect",
-                              test_state->bplate->bplate_string[sst_pass_string],
-                              check_code);
-        } else if (exp_data.pf_fail) {
-            // Check for not-success:
-            find_replace_1st ("!=", "==",
-                              check_code);
-            find_replace_all ("$expect",
-                              test_state->bplate->bplate_string[sst_pass_string],
-                              check_code);
-            find_replace_1st ("expected ", "expected not ",
-                              check_code);
-        } else {
-            if (exp_data.pf_specified) {
-                formalized = formalize (exp_data.pf_result_string, "PSA_ERROR_");
-                find_replace_all ("$expect", formalized, check_code);
-            } else {
-                // Figure out what the message should read:
-                switch (asset_info.how_asset_found) {
-                    case asset_search::found_active:
-                    case asset_search::created_new:
-                        find_replace_all ("$expect",
-                                          test_state->bplate->
-                                              bplate_string[sst_pass_string],
-                                          check_code);
-                        break;
-                    case asset_search::not_found:
-                    case asset_search::found_deleted:
-                        find_replace_all ("$expect", "PSA_ERROR_INVALID_HANDLE",
-                                          check_code);  // TODO:  take from boilerplate
-                        break;
-                    default:
-                        find_replace_1st ("!=", "==",
-                                          check_code);  // like "fail", just make sure...
-                        find_replace_all ("$expect",
-                                          test_state->bplate->
-                                              bplate_string[sst_pass_string],
-                                          check_code);  // ... it's *not* PSA_SUCCESS
-                        break;
-                }
-            }
+    switch (exp_data.get_expected_return_code()) {
+
+    case expected_return_code_t::DontCare:
+        return;
+
+    case expected_return_code_t::Pass:
+        find_replace_all ("$expect",
+                          test_state->bplate->bplate_string[sst_pass_string],
+                          check_code);
+        break;
+
+    case expected_return_code_t::Fail:
+        // Check for not-success:
+        find_replace_1st ("!=", "==",
+                          check_code);
+        find_replace_all ("$expect",
+                          test_state->bplate->bplate_string[sst_pass_string],
+                          check_code);
+        find_replace_1st ("expected ", "expected not ",
+                          check_code);
+        break;
+
+    case expected_return_code_t::SpecificFail:
+        formalized = formalize (exp_data.get_expected_return_code_string(), "PSA_ERROR_");
+        find_replace_all ("$expect", formalized, check_code);
+        break;
+
+    // TODO: move error code simulation to simulate()
+    case expected_return_code_t::DontKnow: // Simulate
+        // Figure out what the message should read:
+        switch (asset_info.how_asset_found) {
+            case asset_search::found_active:
+            case asset_search::created_new:
+                find_replace_all ("$expect",
+                                  test_state->bplate->
+                                      bplate_string[sst_pass_string],
+                                  check_code);
+                break;
+            case asset_search::not_found:
+            case asset_search::found_deleted:
+                find_replace_all ("$expect", "PSA_ERROR_INVALID_HANDLE",
+                                  check_code);  // TODO:  take from boilerplate
+                break;
+            default:
+                find_replace_1st ("!=", "==",
+                                  check_code);  // like "fail", just make sure...
+                find_replace_all ("$expect",
+                                  test_state->bplate->
+                                      bplate_string[sst_pass_string],
+                                  check_code);  // ... it's *not* PSA_SUCCESS
+                break;
         }
+        break;
     }
 }
 
@@ -386,7 +401,7 @@
 
    Since there are no actual PSA calls associated with security calls (so far at least),
    this should never be invoked. */
-void security_call::calc_result_code (void)
+void security_call::fill_in_result_code (void)
 {
     // Currently should not be invoked.
     cerr << "\nError:  Internal:  Please report error #205 to TF-Fuzz developers." << endl;
diff --git a/tf_fuzz/tfz-cpp/calls/psa_call.hpp b/tf_fuzz/tfz-cpp/calls/psa_call.hpp
index 4aa8bda..08d7316 100644
--- a/tf_fuzz/tfz-cpp/calls/psa_call.hpp
+++ b/tf_fuzz/tfz-cpp/calls/psa_call.hpp
@@ -23,65 +23,110 @@
 class psa_call
 {
 public:
-    /* Data members -- not all PSA calls have/need these, but they need to be acces-
-       sible polymorphically via a psa_call iterator: */
-        string call_description;  // description of the call, just for tracing
-        expect_info exp_data;  // everything about expected results
-        set_data_info set_data;  // everything about setting PSA-asset-data values
-        asset_name_id_info asset_info;  // everything about the asset(s) for this line
-        key_policy_info policy;  // (specific to crypto, but have to put this here)
-        string asset_2_name;  // if there's a 2nd asset, then this is its name
-        string asset_3_name;  // if there's a 3rd asset, then this is its name
-        psa_asset_usage random_asset;
-            /* if asked to use some random asset from active or deleted, this says
-               which.  psa_asset_usage::all if not using this feature. */
-        bool assign_data_var_specified;  // asset data to/from named variable
-        string assign_data_var;  // name of variable to dump (assign) data into
-        // Expected-result info:
-        bool print_data;  // true to print asset data to test log
-        bool hash_data;  // true to hash data for later comparison
-        string id_string;  // not all PSA calls involve an ID, but a diverse set do
-        long call_ser_no;  // unique serial# for this psa_call (see note in tf_fuzz.hpp)
-        tf_fuzz_info *test_state;  // the big blob with pointers to everything going on
-        string barrier;
-            /* "barrier" is used for template-line operations that resolve a series of
-               PSA calls.  In particular, with respect to the fact that TF-Fuzz strives
-               to randomize these multiple calls where possible, meaning interspersing
-               them among other, earlier commands.  However, for example, calls to set
-               the aspects of a policy can't be pushed too far back, such as in among
-               calls setting that same policy for a previous operation!  "barrier" is
-               either "", in which case this call does not care whether you place calls
-               before it, or it contains the name of an asset that, calls related to
-               which must be placed *after* this call. */
-        string target_barrier;
-            /* asset to tell the psa_call objects to set and search barrier to when
-               re-ordering PSA calls.  For key policies, this is not necessarily the
-               nominal asset of that call.  For a policy call, it is that policy asset,
-               so that later re-settings of the same policy don't pollute the current
-               setting of that policy.  However, for key sets and reads, it is not the
-               key asset, but its policy. */
-    // Methods:
-        virtual vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
-                                                            psa_asset_usage where) = 0;
-        virtual bool copy_call_to_asset (void) = 0;
-        virtual bool copy_asset_to_call (void) = 0;
-        virtual void fill_in_prep_code (void) = 0;
-        virtual void fill_in_command (void) = 0;
-        void write_out_prep_code (ofstream &test_file);
-        void write_out_command (ofstream &test_file);
-        void write_out_check_code (ofstream &test_file);
-        psa_call (tf_fuzz_info *test_state, long &asset_ser_no,
-                  asset_search how_asset_found);  // (constructor)
-        ~psa_call (void);
+    string call_description;  // description of the call, just for tracing
+    expect_info exp_data;  // everything about expected results
+    set_data_info set_data;  // everything about setting PSA-asset-data values
+    asset_name_id_info asset_info;  // everything about the asset(s) for this line
+    key_policy_info policy;  // (specific to crypto, but have to put this here)
+    string asset_2_name;  // if there's a 2nd asset, then this is its name
+    string asset_3_name;  // if there's a 3rd asset, then this is its name
+    psa_asset_usage random_asset;
+        /* if asked to use some random asset from active or deleted, this says
+           which.  psa_asset_usage::all if not using this feature. */
+    bool assign_data_var_specified;  // asset data to/from named variable
+    string assign_data_var;  // name of variable to dump (assign) data into
+    // Expected-result info:
+    bool print_data;  // true to print asset data to test log
+    bool hash_data;  // true to hash data for later comparison
+    string id_string;  // not all PSA calls involve an ID, but a diverse set do
+    long call_ser_no;  // unique serial# for this psa_call (see note in tf_fuzz.hpp)
+    tf_fuzz_info *test_state;  // the big blob with pointers to everything going on
+    string barrier;
+        /* "barrier" is used for template-line operations that resolve a series of
+           PSA calls.  In particular, with respect to the fact that TF-Fuzz strives
+           to randomize these multiple calls where possible, meaning interspersing
+           them among other, earlier commands.  However, for example, calls to set
+           the aspects of a policy can't be pushed too far back, such as in among
+           calls setting that same policy for a previous operation!  "barrier" is
+           either "", in which case this call does not care whether you place calls
+           before it, or it contains the name of an asset that, calls related to
+           which must be placed *after* this call. */
+    string target_barrier;
+        /* asset to tell the psa_call objects to set and search barrier to when
+           re-ordering PSA calls.  For key policies, this is not necessarily the
+           nominal asset of that call.  For a policy call, it is that policy asset,
+           so that later re-settings of the same policy don't pollute the current
+           setting of that policy.  However, for key sets and reads, it is not the
+           key asset, but its policy. */
+
+    virtual vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+                                                        psa_asset_usage where) = 0;
+
+    /// Updates asset based on call information.
+    ///
+    /// WARNING: previously, this used to be the place to do call simulation
+    /// logic such as modifiying assets. Code that does simulation or in any
+    /// way mutates the state should now instead go in simulate().
+    virtual bool copy_call_to_asset (void) = 0;
+
+    /// Updates call based on asset information.
+    virtual bool copy_asset_to_call (void) = 0;
+
+    /// Simulates the effect of the call, returning true if a change has been
+    /// made.
+    ///
+    /// This is called before asset simulatio takes place. For more details on
+    /// control flow, see simulate_calls().
+    ///
+    /// If no return code for the call was given in the template, this should be
+    /// updated here. However, if a return code is already present, it should
+    /// never be overwritten.
+    virtual bool simulate (void);
+
+    // TODO: move simulation and error modelling code code into simulate().
+    // once this is done, remove default impl so that simulate is mandatory for
+    // calls.
+    // ..
+    // In particular, need to move code from:
+    // ..
+    // - copy_call_to_asset
+    // ..
+    // - fill_in_command
+    // ..
+    // - fill_in_result_code
+
+    virtual void fill_in_prep_code (void) = 0;
+
+    /// WARNING: Previously, this used to also contain expected value
+    /// modelling code (alongside fill_in_command), and some error code
+    /// modelling may still be left over here. New expected value modelling code
+    /// should be put in simulate() where possible. Doing this gives a much
+    /// nicer split between the simulation step (simulate()), and the code
+    /// generation step (which this method is part of).
+    virtual void fill_in_command (void) = 0;
+
+    void write_out_prep_code (ofstream &test_file);
+    void write_out_command (ofstream &test_file);
+    void write_out_check_code (ofstream &test_file);
+    psa_call (tf_fuzz_info *test_state, long &asset_ser_no,
+              asset_search how_asset_found);  // (constructor)
+    ~psa_call (void);
 
 protected:
-    // Data members:
-        string prep_code;  // declarations and such prior to all of the calls
-        string call_code;  // for the call itself
-        string check_code;  // for the code to check success of the call
-        static long unique_id_counter;  // counts off unique IDs for assets
-    // Methods:
-        virtual void calc_result_code (void) = 0;
+    string prep_code;  // declarations and such prior to all of the calls
+    string call_code;  // for the call itself
+    string check_code;  // for the code to check success of the call
+    static long unique_id_counter;  // counts off unique IDs for assets
+
+    /// Fill in expected result checks.
+    ///
+    /// WARNING: Previously, this used to also contain expected value
+    /// modelling code (alongside fill_in_command), and some error code
+    /// modelling may still be left over here. New expected value modelling code
+    /// should be put in simulate() where possible. Doing this gives a much
+    /// nicer split between the simulation step (simulate()), and the code
+    /// generation step (which this method is part of).
+    virtual void fill_in_result_code (void) = 0;
 
 private:
     // Data members:
@@ -102,8 +147,7 @@
 
 protected:
     // Data members:
-    // Methods:
-        void calc_result_code (void);
+        void fill_in_result_code (void);
 
 private:
     // Data members:
@@ -123,7 +167,7 @@
 protected:
     // Data members:
     // Methods:
-        void calc_result_code (void);
+        void fill_in_result_code (void);
            // for now, the method-overide buck stops here, but that'll probably change
 
 private:
@@ -148,7 +192,7 @@
 protected:
     // Data members:
     // Methods:
-        void calc_result_code (void);
+        void fill_in_result_code (void);
            // Should never be invoked, since security calls generate no PSA calls.
 
 private:
diff --git a/tf_fuzz/tfz-cpp/calls/sst_call.cpp b/tf_fuzz/tfz-cpp/calls/sst_call.cpp
index 2c49d95..7cf1b62 100644
--- a/tf_fuzz/tfz-cpp/calls/sst_call.cpp
+++ b/tf_fuzz/tfz-cpp/calls/sst_call.cpp
@@ -171,13 +171,15 @@
     string id_string = to_string((long) asset_info.id_n);
     find_replace_1st ("$uid", id_string, call_code);
     find_replace_1st ("$length", length_var_name, call_code);
+
+    // TODO: move error code modelling to simulate().
+
     // Figure out what expected results:
-    if (   set_data.flags_string == "PSA_STORAGE_FLAG_WRITE_ONCE"
+    if (set_data.flags_string == "PSA_STORAGE_FLAG_WRITE_ONCE"
         && set_data.n_set_vars > 0) {
-        exp_data.pf_specified = true;
-        exp_data.pf_result_string = "PSA_ERROR_NOT_PERMITTED";
+        exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
     }
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -412,7 +414,7 @@
         find_replace_all ("$hash_var", hash_var_name, check_code);
     }
     // Figure out what expected results:
-    calc_result_code();  // this only fills $expect check_code
+    fill_in_result_code();  // this only fills $expect check_code
     // Fill in expected data, actual data, and length:
 }
 
@@ -482,7 +484,7 @@
     string id_string = to_string((long) asset_info.id_n);
     find_replace_1st ("$uid", id_string, call_code);
     // Fill in expected results:
-    calc_result_code();  // this only fills $expect check_code
+    fill_in_result_code();  // this only fills $expect check_code
 }
 
 /**********************************************************************************
diff --git a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
index 17c31b4..4782d0c 100644
--- a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
+++ b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -518,22 +518,22 @@
 expect:
         EXPECT PASS  {
             IVM(cout << "Expect pass clause:  \"" << flush;)
-            templateLin->expect.set_pf_pass();
+            templateLin->expect.expect_pass();
             IVM(cout << yytext << "\"" << endl;)
         }
       | EXPECT FAIL {
             IVM(cout << "Expect fail clause:  \"" << flush;)
-            templateLin->expect.set_pf_fail();
+            templateLin->expect.expect_failure();
             IVM(cout << yytext << "\"" << endl;)
         }
       | EXPECT NOTHING {
             IVM(cout << "Expect nothing clause:  \"" << flush;)
-            templateLin->expect.set_pf_nothing();
+            templateLin->expect.disable_result_code_checking();
             IVM(cout << yytext << "\"" << endl;)
         }
       | EXPECT IDENTIFIER {
             IVM(cout << "Expect error clause:  \"" << flush;)
-            templateLin->expect.set_pf_error (identifier);
+            templateLin->expect.expect_error_code (identifier);
             IVM(cout << yytext << "\"" << endl;)
         }
       ;
@@ -1420,4 +1420,3 @@
 
 
 %%
-
diff --git a/tf_fuzz/tfz-cpp/template/secure_template_line.cpp b/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
index e8a255e..5891be6 100644
--- a/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
@@ -40,7 +40,6 @@
     call->set_data.file_path.assign("");
     call->set_data.set("");
     call->set_data.flags_string.assign ("");
-    call->exp_data.pf_info_incomplete = true;
     return true;
 }
 
diff --git a/tf_fuzz/tfz-cpp/template/template_line.cpp b/tf_fuzz/tfz-cpp/template/template_line.cpp
index d5f3df3..10e88a7 100644
--- a/tf_fuzz/tfz-cpp/template/template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/template_line.cpp
@@ -86,7 +86,6 @@
     }
     call->set_data.flags_string.assign (set_data.flags_string);
     call->exp_data = expect;
-    call->exp_data.pf_info_incomplete = true;
     call->id_string = asset_name;  // data = expected
     call->print_data = print_data;
     call->hash_data = hash_data;
@@ -147,7 +146,6 @@
     }
     call->set_data.flags_string.assign (set_data.flags_string);
     call->exp_data = expect;
-    call->exp_data.pf_info_incomplete = true;
     call->id_string = asset_name;  // data = expected
     call->print_data = print_data;
     call->hash_data = hash_data;
@@ -210,7 +208,6 @@
     }
     call->set_data.flags_string.assign (set_data.flags_string);
     call->exp_data = expect;
-    call->exp_data.pf_info_incomplete = true;
     call->id_string = asset_name;  // data = expected
     call->print_data = print_data;
     call->hash_data = hash_data;
diff --git a/tf_fuzz/tfz-cpp/tf_fuzz.cpp b/tf_fuzz/tfz-cpp/tf_fuzz.cpp
index 1dc95ae..4be4a1d 100644
--- a/tf_fuzz/tfz-cpp/tf_fuzz.cpp
+++ b/tf_fuzz/tfz-cpp/tf_fuzz.cpp
@@ -236,38 +236,42 @@
 
 /* simulate_calls() goes through the vector of generated calls calculating expected
    results for each. */
-void tf_fuzz_info::simulate_calls (void)
-{
+void tf_fuzz_info::simulate_calls (void){
     bool asset_state_changed = false;
 
-    IV(cout << "Call sequence:" << endl;)
-    /* For now, much of the simulation "thinking" infrastructure is here for future
-       elaboration.  The algorithm is to through each call one by one, copying
-       information to the asset in question.  Then each currently-active asset is
-       allowed to react to that information until they all agree that they're
-       "quiescent."  Finally, result information is copied from the asset back to
-       the call. */
+    IV(cout << "Call sequence:" << endl;);
+
+    /* The thinking logic will probably need elaborating in the future.
+     *
+     * The current algorithm goes through the calls, simuating their expected
+     * return codes. After call simulation, assets are updated, which are then
+     * allowed to react to the new information. Asset simulation loops until they
+     * all agree that they're "quiescent". Finally, result information is copied
+     * from the asset back to the call.
+     */
     for (auto this_call : calls) {
         IV(cout << "    " << this_call->call_description << " for asset "
                 << this_call->asset_info.get_name() << endl;)
+
+        this_call->simulate();
         this_call->copy_call_to_asset();
            /* Note:  this_call->the_asset will now point to the asset
                      associated with this_call, if any such asset exists. */
-        if (this_call->asset_info.the_asset != nullptr) {
-            /* If the asset exists, allow changes to it to affect other active
-               assets. */
-            asset_state_changed = false;
-            do {
-               for (auto this_asset : active_sst_asset) {
-                   asset_state_changed |= this_asset->simulate();
-               }
-               for (auto this_asset : active_policy_asset) {
-                   asset_state_changed |= this_asset->simulate();
-               }
-               for (auto this_asset : active_key_asset) {
-                   asset_state_changed |= this_asset->simulate();
-               }
-            } while (asset_state_changed);
+    if (this_call->asset_info.the_asset != nullptr) {
+      /* If the asset exists, allow changes to it to affect other active
+         assets. */
+      asset_state_changed = false;
+      do {
+        for (auto this_asset : active_sst_asset) {
+          asset_state_changed |= this_asset->simulate();
+        }
+        for (auto this_asset : active_policy_asset) {
+          asset_state_changed |= this_asset->simulate();
+        }
+        for (auto this_asset : active_key_asset) {
+          asset_state_changed |= this_asset->simulate();
+        }
+      } while (asset_state_changed);
         }
         this_call->copy_asset_to_call();
     }
diff --git a/tf_fuzz/tfz-cpp/utility/data_blocks.cpp b/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
index 21b7f50..5683b06 100644
--- a/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
+++ b/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
@@ -9,6 +9,7 @@
    associated methods (most importantly their constructors) used in template_
    line, psa_call, psa_asset (etc.). */
 
+#include <stdexcept>
 #include <stdlib.h>
 #include <string>
 #include <vector>
@@ -28,62 +29,97 @@
 
 expect_info::expect_info (void)  // (default constructor)
 {
-    pf_nothing = false;  // by default, TF-Fuzz provides expected results
-    pf_pass = pf_fail = pf_specified = false;
-    pf_result_string.assign ("");  data.assign ("");
-    data_var_specified = false;
+    result_code_checking_enabled_f = true;
+    return_code_result_string.assign ("");
+
+    expected_return_code = expected_return_code_t::DontKnow;
+
+    data.assign ("");
     data_var.assign ("");  // name of expected-data variable
+
+    data_var_specified = false;
     data_specified = false;
     data_matches_asset = false;
-    data.assign ("");
-    pf_info_incomplete = true;
     n_exp_vars = -1;  // so the first reference is 0 (no suffix), then _1, _2, ...
-    expected_results_saved = false;
 }
+
 expect_info::~expect_info (void)  // (destructor)
 {}
 
-void expect_info::set_pf_pass (void)
-{
-    pf_pass = true;
-    pf_fail = pf_nothing = pf_specified = false;
-    pf_result_string = "";
+bool expect_info::simulation_needed(void) {
+  if (result_code_checking_enabled_f &&
+      expected_return_code == expected_return_code_t::DontKnow) {
+    return true;
+  }
+
+    return false;
 }
 
-void expect_info::set_pf_fail (void)
+void expect_info::expect_pass (void)
 {
-    pf_fail = true;
-    pf_pass = pf_nothing = pf_specified = false;
-    pf_result_string = "";
+    expected_return_code  = expected_return_code_t::Pass;
+    return_code_result_string = "";
 }
 
-void expect_info::set_pf_nothing (void)
+void expect_info::expect_failure(void)
 {
-    pf_nothing = true;
-    pf_fail = pf_pass = pf_specified = false;
-    pf_result_string = "";
+    expected_return_code  = expected_return_code_t::Fail;
+    return_code_result_string = "";
 }
 
-void expect_info::set_pf_error (string error)
+void expect_info::expect_error_code (string error)
 {
-    pf_specified = true;
-    pf_result_string.assign (error);  // just default "guess," to be filled in
-    pf_pass = pf_fail = pf_nothing = false;
+    expected_return_code = expected_return_code_t::SpecificFail;
+    return_code_result_string = error;
 }
 
-/* The expected pass/fail results are not available from the parser until the call has
-   already been created.  The flag, pf_info_incomplete, that indicates whether or not
-   the "expects" information has been filled in.  If not, fill it in from the template,
-   once that info has been parsed. */
+
+void expect_info::clear_expected_code (void)
+{
+    expected_return_code = expected_return_code_t::DontKnow;
+}
+
+expected_return_code_t expect_info::get_expected_return_code(void) {
+
+    // NOTE: we do not store DontCare in expected_return_code, as this would erase
+    // the value stored prior to checks being disabled. This way, when
+    // enable_result_code_checking is called, it can use the value given by the
+    // user previously.
+    // ..
+    // Despite this, having DontCare as a value is still useful: it allows user
+    // code that uses expected return codes to just be a switch statement.
+
+    if (result_code_checking_enabled_f) {
+        return expected_return_code;
+    }
+
+    return expected_return_code_t::DontCare;
+}
+
+string expect_info::get_expected_return_code_string(void) {
+    if (result_code_checking_enabled_f && expected_return_code == expected_return_code_t::SpecificFail) {
+        return return_code_result_string;
+    }
+    throw std::logic_error("get_expected_return_code_string called when return code is not SpecificFail");
+}
+
+void expect_info::disable_result_code_checking (void)
+{
+    result_code_checking_enabled_f = false;
+}
+
+void expect_info::enable_result_code_checking (void)
+{
+    result_code_checking_enabled_f = true;
+}
+
+bool expect_info::result_code_checking_enabled (void) {
+    return result_code_checking_enabled_f;
+}
+
 void expect_info::copy_expect_to_call (psa_call *the_call)
 {
-    the_call->exp_data.pf_nothing = pf_nothing;
-    the_call->exp_data.pf_pass = pf_pass;
-    the_call->exp_data.pf_fail = pf_fail;
-    the_call->exp_data.pf_specified = pf_specified;
-    the_call->exp_data.pf_result_string = pf_result_string;
-    the_call->exp_data.expected_results_saved = true;
-    the_call->exp_data.pf_info_incomplete = false;
+    the_call->exp_data = *this;
 }
 
 /**********************************************************************************
@@ -181,7 +217,7 @@
     random_data = true;
     literal_data_not_file = true;
     rand_data_length = 40 + (rand() % 256);
-        /* Note:  Multiple assets do get different random data */
+    /* Note:  Multiple assets do get different random data */
     gib.sentence (gib_buff, gib_buff + rand_data_length - 1);
     data = gib_buff;
 }
@@ -303,7 +339,7 @@
             break;
         default:
             cerr << "\nError:  Tool-internal:  Please report error "
-                 << "#1223 to the TF-Fuzz developers." << endl;
+                << "#1223 to the TF-Fuzz developers." << endl;
             exit(1223);
     }
     result.append(to_string(id_n));
diff --git a/tf_fuzz/tfz-cpp/utility/data_blocks.hpp b/tf_fuzz/tfz-cpp/utility/data_blocks.hpp
index 1e56836..9f6cfc2 100644
--- a/tf_fuzz/tfz-cpp/utility/data_blocks.hpp
+++ b/tf_fuzz/tfz-cpp/utility/data_blocks.hpp
@@ -8,7 +8,6 @@
 #include <stdint.h>
 #include <string>
 #include <vector>
-#include <iosfwd>
 
 class psa_asset;
 
@@ -26,62 +25,99 @@
 
 using namespace std;
 
+/// Possible values of return codes.
+///
+/// Intended to be used primarily through [expect_info]
+enum class expected_return_code_t {
+    /// This call should pass.
+    Pass,
+    /// This call should fail.
+    Fail,
+    /// This call should return a specific error code.
+    SpecificFail,
 
-/**********************************************************************************
-  Class expect_info is all about expected data and expected pass/fail information.
-  The members are therefore broken down with prefixes pf_ (for pass/fail) or
-  data_.  Pass/fail, is broadly:
-  *  "Pass" == the test passes
-  *  "Specified" == some specified failure (e.g., no such asset)
-  *  "Nothing" == no expectation
-  Expected data refers to psa-asset data values, generally after reading them.
-  Currently, they are limited to character strings, but that will probably be
-  generalized in the future.
-**********************************************************************************/
+    /// The outcome of this call is unknown and should be simulated.
+    DontKnow,
 
+    /// the return code does not matter, and checks for this should not take
+    /// place.
+    DontCare,
+};
+
+/**
+ * expect_info is all about expected data and expected pass / fail information.
+ *
+ * The possible types of expected values returned from a PSA call are modelled
+ * in [expected_return_codes].
+ *
+ * Expected data refers to psa-asset data values, generally after reading
+ * them. Currently, they are limited to character strings, but that will
+ * probably be generalized in the future.
+ */
 class expect_info
 {
 public:
-    // Data members:
-        // Expected-result info:
-        bool pf_nothing;  // true to not generate results-check(s)
-        bool pf_pass;  // if !expect.pf_nothing, then pass is expected
-        bool pf_fail;  // if "expect fail" was specified
-        bool pf_specified; // if "expect <ERROR_CODE>" was specified
-            /* if !pf_nothing && !pf_pass, then
-               true == expected result was specified
-               false == tf_fuzz must model expected result, and
-               pf_result_string is the expected result */
-        string pf_result_string;
-        bool data_specified;  // (literal expected data specified)
-        string data;  // what test template expects data from reading an asset to be
-        int n_exp_vars;  // how many check-value variables have been created
-        bool data_var_specified;  // check against a variable
-        string data_var;  // name of variable containing expected data
-        bool pf_info_incomplete;
-            /* In parsing the template, the expect information comes later than the
-               rest of the call info.  This flag tells us to fill in the pass/fail
-               expect info when it comes available. */
-        bool expected_results_saved;
-            /* This indicates whether expected results have or have not already been
-               copied to this call.  It's a "one-shot," so to speak, to copy only
-               once when results are known good.  Since calls can be inserted into
-               earlier points in the call sequence (not always appended), the call
-               sequence has to be gone over for this process multiple times. */
-    // Methods:
-        expect_info (void);  // (default constructor)
-        ~expect_info (void);  // (destructor)
-        void set_pf_pass (void);
-        void set_pf_fail (void);
-        void set_pf_nothing (void);
-        void set_pf_error (string error);
-        void copy_expect_to_call (psa_call *the_call);
 
-protected:
-    // Data members:
-        bool data_matches_asset;
-            /* true if template specifies expected data, and that expected data
-               agrees with that in the asset */
+    // (literal expected data specified)
+    bool data_specified;
+
+    string data;     // what test template expects data from reading an asset to be
+    string data_var; // name of variable containing expected data
+    int n_exp_vars;  // how many check-value variables have been created
+    bool data_var_specified;  // check against a variable
+
+    /* This indicates whether expected results have or have not already been
+       copied to this call.  It's a "one-shot," so to speak, to copy only
+       once when results are known good.  Since calls can be inserted into
+       earlier points in the call sequence (not always appended), the call
+       sequence has to be gone over for this process multiple times. */
+    bool expected_results_saved;
+
+    expect_info (void);  // (default constructor)
+    ~expect_info (void);  // (destructor)
+
+    /// Is simulation of the return code needed?
+    bool simulation_needed(void);
+
+    /// Sets the expected return code of the call to a pass.
+    void expect_pass (void);
+
+    /// Sets the expected return code of the call to a failure.
+    void expect_failure (void);
+
+    /// Sets the expected return code of the call to a specific error code.
+    void expect_error_code (string error);
+
+    /// Sets the expected return code of the call to "don't know".
+    ///
+    /// This will cause TF_Fuzz to later simulate this value.
+    void clear_expected_code(void);
+
+    /// Gets the expected return code.
+    expected_return_code_t get_expected_return_code(void);
+
+    /// When a specified error code is given, get that error code as a string.
+    /// When any other return code is expected, std::logic_error is thrown.
+    string get_expected_return_code_string(void);
+
+    void disable_result_code_checking (void);
+    void enable_result_code_checking (void);
+    bool result_code_checking_enabled(void);
+
+    void copy_expect_to_call (psa_call *the_call);
+
+private:
+    /* true if template specifies expected data, and that expected data
+       agrees with that in the asset */
+    bool data_matches_asset;
+    string return_code_result_string;
+
+    // The type of return code expected.
+    expected_return_code_t expected_return_code;
+
+    // if false, the return code does not matter, and checks for this should not
+    // take place.
+    bool result_code_checking_enabled_f;
 };
 
 
@@ -96,31 +132,31 @@
 {
 public:
     // Data members:
-        bool string_specified;
-            // true if a string of data is specified in template file
-        bool random_data;  // true to generate random data for the asset
-        bool file_specified;  // true if a file of expected data was specified
-        bool literal_data_not_file;
-            // true to use data strings rather than files as data source
-        int n_set_vars;  // how many implicit set variables have been created
-        string file_path;  // path to file, if specified
-        string flags_string;
-            // creation flags, nominally for SST but have to be in a vector of base-class
-        uint32_t data_offset;  // offset into asset data
+    bool string_specified;
+    // true if a string of data is specified in template file
+    bool random_data;  // true to generate random data for the asset
+    bool file_specified;  // true if a file of expected data was specified
+    bool literal_data_not_file;
+    // true to use data strings rather than files as data source
+    int n_set_vars;  // how many implicit set variables have been created
+    string file_path;  // path to file, if specified
+    string flags_string;
+    // creation flags, nominally for SST but have to be in a vector of base-class
+    uint32_t data_offset;  // offset into asset data
     // Methods:
-        set_data_info (void);  // (default constructor)
-        ~set_data_info (void);  // (destructor)
-        void set (string set_val);
-        void set_calculated (string set_val);
-        void randomize (void);
-        string get (void);
-        bool set_file (string file_name);
+    set_data_info (void);  // (default constructor)
+    ~set_data_info (void);  // (destructor)
+    void set (string set_val);
+    void set_calculated (string set_val);
+    void randomize (void);
+    string get (void);
+    bool set_file (string file_name);
 
 protected:
     // Data members:
-        string data;  // String describing asset data.
+    string data;  // String describing asset data.
     // Methods:
-        string rand_creation_flags (void);
+    string rand_creation_flags (void);
 };
 
 
@@ -133,37 +169,37 @@
 {
 public:
     // Data members (not much value in "hiding" these behind getters)
-        psa_asset *the_asset;
-        psa_asset_type asset_type;  // SST vs. key vs. policy (etc.)
-        bool id_n_not_name;  // true to create a PSA asset by ID
-        bool name_specified;  // true iff template supplied human name
-        bool id_n_specified;  // true iff template supplied ID #
-        vector<string> asset_name_vector;
-        vector<int> asset_id_n_vector;
-        long asset_ser_no;  // unique ID for psa asset needed to find data string
-            /* Note:  The original theory is that we can't save away iterators to
+    psa_asset *the_asset;
+    psa_asset_type asset_type;  // SST vs. key vs. policy (etc.)
+    bool id_n_not_name;  // true to create a PSA asset by ID
+    bool name_specified;  // true iff template supplied human name
+    bool id_n_specified;  // true iff template supplied ID #
+    vector<string> asset_name_vector;
+    vector<int> asset_id_n_vector;
+    long asset_ser_no;  // unique ID for psa asset needed to find data string
+    /* Note:  The original theory is that we can't save away iterators to
                       assets, because STL vectors could get relocated.  However,
                       we've switched over to lists, which don't get moved around, so
                       we should be safe now. */
-        asset_search how_asset_found;
-        uint64_t id_n;  // asset ID# (e.g., SST UID).
-            /* Note:  This is just a holder to pass ID from template-line to call.  The
+    asset_search how_asset_found;
+    uint64_t id_n;  // asset ID# (e.g., SST UID).
+    /* Note:  This is just a holder to pass ID from template-line to call.  The
                IDs for a given template line are in asset_info.asset_id_n_vector. */
     // Methods:
-        asset_name_id_info (void);  // (default constructor)
-        ~asset_name_id_info (void);  // (destructor)
-        void set_name (string set_val);
-        void set_calc_name (string set_val);
-        void set_just_name (string set_val);
-        string get_name (void);
-        void set_id_n (string set_val);
-        void set_id_n (uint64_t set_val);
-        string make_id_n_based_name (uint64_t id_n);
-            // create UID-based asset name
+    asset_name_id_info (void);  // (default constructor)
+    ~asset_name_id_info (void);  // (destructor)
+    void set_name (string set_val);
+    void set_calc_name (string set_val);
+    void set_just_name (string set_val);
+    string get_name (void);
+    void set_id_n (string set_val);
+    void set_id_n (uint64_t set_val);
+    string make_id_n_based_name (uint64_t id_n);
+    // create UID-based asset name
 
 protected:
     // Data members:
-        string asset_name;  // parsed from template, assigned to psa_asset object
+    string asset_name;  // parsed from template, assigned to psa_asset object
 };
 
 
@@ -176,56 +212,56 @@
 {
 public:
     // Data members:
-        // Digested info:
-        bool get_policy_from_key;
-            /* if true, then we must get policy info from a stated key;  the asset
+    // Digested info:
+    bool get_policy_from_key;
+    /* if true, then we must get policy info from a stated key;  the asset
                here is a key that uses the policy, and not the policy itself. */
-        bool implicit_policy;
-            /* if true, then the key was defined with policy specifications, but not
+    bool implicit_policy;
+    /* if true, then the key was defined with policy specifications, but not
                a named policy, meaning that we have to create an implicit policy. */
-        bool copy_key;  // true to indicate copying one key to another
-        bool exportable;   // key data can be exported (viewed - fail exports if not).
-        bool copyable;     // can be copied (fail key-copies if not).
-        bool can_encrypt;  // OK for encryption (fail other uses).
-        bool can_decrypt;  // OK for decryption (fail other uses).
-        bool can_sign;     // OK for signing (fail other operations).
-        bool can_verify;   // OK for verifying a message signature (fail other uses).
-        bool derivable;    // OK for derive other keys (fail other uses).
-        bool persistent;   // must be deleted at the end of test.
-        string usage_string;
-            /* This string is set to a PSA_KEY_USAGE_* value in the template
+    bool copy_key;  // true to indicate copying one key to another
+    bool exportable;   // key data can be exported (viewed - fail exports if not).
+    bool copyable;     // can be copied (fail key-copies if not).
+    bool can_encrypt;  // OK for encryption (fail other uses).
+    bool can_decrypt;  // OK for decryption (fail other uses).
+    bool can_sign;     // OK for signing (fail other operations).
+    bool can_verify;   // OK for verifying a message signature (fail other uses).
+    bool derivable;    // OK for derive other keys (fail other uses).
+    bool persistent;   // must be deleted at the end of test.
+    string usage_string;
+    /* This string is set to a PSA_KEY_USAGE_* value in the template
                immediately prior to making define_call<add_policy_usage_call>.
                The copy_template_to_call() therein sets the corresponding string
                in the call, and that is copied into the code in the fill_in_command()
                invocation. */
-        string print_usage_true_string;
-            /* For printing out policy usage, this states how to describe the usage
+    string print_usage_true_string;
+    /* For printing out policy usage, this states how to describe the usage
                if it can be used this way.  This is managed similarly with, and used
                in conjunction with usage_string above.  NOTE:  THIS ALSO SERVES AS AN
                INDICATOR WHETHER OR NOT TO PRINT ON A GET-USAGE CALL.  "" means not
                to print. */
-        string print_usage_false_string;
-            /* Also for printing out policy usage, this is how to describe usage if
+    string print_usage_false_string;
+    /* Also for printing out policy usage, this is how to describe usage if
                it cannot be used this way. */
-        string key_type;   // AES, DES, RSA pair, DS public, etc.
-        string key_algorithm;
-        int n_bits;
-           // for get_key_info call (possibly others) exected key size in bits
-        string handle_str; // the text name of the key's "handle"
-        string key_data;   // the key data as best we can know it.
-        string asset_2_name;
-            // if there's a 2nd asset, such as policy on key call, this is its name
-        string asset_3_name;  // if there's a 3rd asset, then this is its name
+    string key_type;   // AES, DES, RSA pair, DS public, etc.
+    string key_algorithm;
+    int n_bits;
+    // for get_key_info call (possibly others) exected key size in bits
+    string handle_str; // the text name of the key's "handle"
+    string key_data;   // the key data as best we can know it.
+    string asset_2_name;
+    // if there's a 2nd asset, such as policy on key call, this is its name
+    string asset_3_name;  // if there's a 3rd asset, then this is its name
 
     // Methods:
-        key_policy_info (void);  // (default constructor)
-        ~key_policy_info (void);  // (destructor)
+    key_policy_info (void);  // (default constructor)
+    ~key_policy_info (void);  // (destructor)
 
 
 protected:
     // Data members:
-        bool data_matches_asset;
-            /* true if template specifies expected data, and that expected data
+    bool data_matches_asset;
+    /* true if template specifies expected data, and that expected data
                agrees with that in the asset */
 };