|
BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
|
#include "TestUtils.h"#include <bsl/BPSecLib_Private.h>#include <bsl/crypto/CryptoInterface.h>#include <bsl/front/TextUtil.h>#include <bsl/dynamic/IdValPair.h>#include <bsl/dynamic/SecurityActionSet.h>#include <bsl/dynamic/SeqReadWrite.h>#include <bsl/sample_pp/SamplePolicyProvider.h>#include <bsl/mock_bpa/MockBPA.h>#include <m-string.h>#include <assert.h>
Include dependency graph for TestUtils.c:Data Structures | |
| struct | BSL_TestUtils_Flat_Data_s |
| Internal state for reader and writer. More... | |
Functions | |
| int | BSL_TestContext_Init (BSL_TestContext_t *ctx) |
| int | BSL_TestContext_Deinit (BSL_TestContext_t *ctx) |
| bool | BSL_TestUtils_IsB16StrEqualTo (const char *expected_hex, BSL_Data_t encoded_val) |
| Compare an expected base-16 encoded byte string with an actual value. | |
| void | BSL_TestUtils_PrintHexToBuffer (const char *message, uint8_t *buff, size_t bufflen) |
| int | BSL_TestUtils_LoadBundleFromCBOR (BSL_TestContext_t *test_ctx, const char *cborhex) |
| Load a full bundle state into a test context. | |
| int | BSL_TestUtils_EncodeBundleToCBOR (BSL_TestContext_t *test_ctx) |
| Encode a bundle state to CBOR. | |
| BSL_HostEIDPattern_t | BSL_TestUtils_GetEidPatternFromText (const char *text) |
| int | BSL_TestUtils_DecodeBase16_cstr (BSL_Data_t *output, const char *input) |
| Decode base16 text form. | |
| int | BSL_TestUtils_ModifyEIDs (BSL_BundleRef_t *input_bundle, const char *src_eid, const char *dest_eid, const char *report_to_eid) |
| Modify bundle's source eid, destination eid, and report-to eid. | |
| static int | BSL_TestUtils_ReadBTSD_Read (void *user_data, void *buf, size_t *bufsize) |
| static void | BSL_TestUtils_ReadBTSD_Deinit (void *user_data) |
| BSL_SeqReader_t * | BSL_TestUtils_FlatReader (const void *buf, size_t bufsize) |
| Initialize a flat-buffer reader object. | |
| static int | BSL_TestUtils_WriteBTSD_Write (void *user_data, const void *buf, size_t size) |
| static void | BSL_TestUtils_WriteBTSD_Deinit (void *user_data, bool success) |
| BSL_SeqWriter_t * | BSL_TestUtils_FlatWriter (void **buf, size_t *bufsize) |
| Initialize a flat-buffer reader object. | |
| int BSL_TestContext_Deinit | ( | BSL_TestContext_t * | ctx | ) |
References BSL_API_DeinitLib(), BSL_SUCCESS, ctx, and mock_bpa_ctr_deinit().
Referenced by _tearDown(), and tearDown().
| int BSL_TestContext_Init | ( | BSL_TestContext_t * | ctx | ) |
References BSL_API_InitLib(), BSL_SUCCESS, ctx, and mock_bpa_ctr_init().
| int BSL_TestUtils_DecodeBase16_cstr | ( | BSL_Data_t * | output, |
| const char * | input | ||
| ) |
Decode base16 text form.
| [out] | output | The output buffer, which will be sized to its data. |
| [in] | input | The input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space(). |
References BSL_TextUtil_Base16_Decode().
Referenced by BSL_TestUtils_IsB16StrEqualTo(), BSL_TestUtils_LoadBundleFromCBOR(), ccsds_mac_rng(), cose_exA_5_rng(), cose_exA_6_rng(), setUp(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_bsl_loopback_eid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_CoseSc_InvalidOptions_Verifier(), test_mock_bpa_crc_crc16(), test_mock_bpa_crc_crc32c(), test_mock_bpa_ctr_decode_invalid(), test_qcbor_decode_array_nested(), test_qcbor_decode_map_sequential(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_accept_keyunwrap(), and test_sec_source_keywrap().
| int BSL_TestUtils_EncodeBundleToCBOR | ( | BSL_TestContext_t * | test_ctx | ) |
Encode a bundle state to CBOR.
| [in,out] | test_ctx | The context to encode. |
References BSL_TestContext_t::mock_bpa_ctr, mock_bpa_ctr_encode(), and mock_bpa_ctr_sort_blocks().
Referenced by test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_CCSDS_Example_Mac_Source(), and test_CCSDS_Example_Mac_VerifyAccept().
| BSL_SeqReader_t * BSL_TestUtils_FlatReader | ( | const void * | buf, |
| size_t | bufsize | ||
| ) |
Initialize a flat-buffer reader object.
References ASSERT_PROPERTY, BSL_calloc(), BSL_malloc(), BSL_TestUtils_ReadBTSD_Deinit(), BSL_TestUtils_ReadBTSD_Read(), BSL_TestUtils_Flat_Data_s::file, BSL_TestUtils_Flat_Data_s::origbuf, BSL_TestUtils_Flat_Data_s::origsize, BSL_TestUtils_Flat_Data_s::ptr, and BSL_TestUtils_Flat_Data_s::size.
Referenced by switch(), test_decrypt(), test_encrypt(), and test_SeqReader_flat().
| BSL_SeqWriter_t * BSL_TestUtils_FlatWriter | ( | void ** | buf, |
| size_t * | bufsize | ||
| ) |
Initialize a flat-buffer reader object.
References ASSERT_PROPERTY, BSL_calloc(), BSL_malloc(), BSL_TestUtils_WriteBTSD_Deinit(), BSL_TestUtils_WriteBTSD_Write(), BSL_TestUtils_Flat_Data_s::file, BSL_TestUtils_Flat_Data_s::origbuf, BSL_TestUtils_Flat_Data_s::origsize, BSL_TestUtils_Flat_Data_s::ptr, and BSL_TestUtils_Flat_Data_s::size.
Referenced by test_decrypt(), test_encrypt(), and test_SeqWriter_flat().
| BSL_HostEIDPattern_t BSL_TestUtils_GetEidPatternFromText | ( | const char * | text | ) |
References BSL_HostEIDPattern_DecodeFromText(), and BSL_HostEIDPattern_Init().
| bool BSL_TestUtils_IsB16StrEqualTo | ( | const char * | expected_hex, |
| BSL_Data_t | encoded_val | ||
| ) |
Compare an expected base-16 encoded byte string with an actual value.
| expected_hex | The expected value in base-16 as a null-terminated string. |
| encoded_val | The value to check. |
References BSL_Data_Cmp(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_LOG_CRIT, BSL_TestUtils_DecodeBase16_cstr(), BSL_TestUtils_PrintHexToBuffer(), BSL_Data_t::len, BSL_Data_t::owned, and BSL_Data_t::ptr.
Referenced by test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_bsl_mock_encode_bundle(), test_bsl_mock_encode_canonical(), test_bsl_mock_encode_primary(), TEST_CASE(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_RFC9173_AppendixA_Example1_BIB_Source(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), test_RFC9173_AppendixA_Example2_BCB_Source(), test_RFC9173_AppendixA_Example4_Acceptor(), test_sec_accept_keyunwrap(), test_sec_source_keywrap(), test_SecurityContext_BIB_Acceptor(), test_SecurityContext_BIB_Source(), and test_SecurityContext_BIB_Verifier().
| int BSL_TestUtils_LoadBundleFromCBOR | ( | BSL_TestContext_t * | test_ctx, |
| const char * | cborhex | ||
| ) |
Load a full bundle state into a test context.
| [in,out] | test_ctx | The context to copy and decode into. |
| [in] | cborhex | The input bundle in base16. |
References MockBPA_Bundle_t::blocks, MockBPA_Bundle_t::blocks_num, BSL_LOG_ERR, BSL_TestUtils_DecodeBase16_cstr(), mock_bpa_ctr_t::bundle_ref, MockBPA_PrimaryBlock_t::crc_type, BSL_BundleRef_t::data, mock_bpa_ctr_t::encoded, MockBPA_PrimaryBlock_t::flags, MockBPA_PrimaryBlock_t::lifetime, BSL_TestContext_t::mock_bpa_ctr, mock_bpa_ctr_decode(), MockBPA_Bundle_t::primary_block, and MockBPA_PrimaryBlock_t::version.
Referenced by n_test_BSL_6(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example1_BIB_VerifyAccept(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example4_BCB_VerifyAccept(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example5_BCB_VerifyAccept(), test_AppendixA_Example6_BCB_Source(), test_BSL_32(), TEST_CASE(), test_CCSDS_Example_Mac_Source(), test_CCSDS_Example_Mac_VerifyAccept(), test_CoseSc_InvalidOptions_Source(), test_CoseSc_InvalidOptions_Verifier(), test_dyn_mem_cbs_BSL_32(), test_MultiplePolicyProviders(), test_PolicyProvider_Inspect_RFC9173_BIB(), test_PolicyProvider_InspectEmptyRuleset(), test_PolicyProvider_InspectSingleBIBRuleset(), test_RFC9173_AppendixA_Example1_BIB_Source(), test_RFC9173_AppendixA_Example2_BCB_Acceptor(), test_RFC9173_AppendixA_Example2_BCB_Source(), test_RFC9173_AppendixA_Example3_Acceptor(), test_RFC9173_AppendixA_Example3_Source(), test_RFC9173_AppendixA_Example4_Acceptor(), test_RFC9173_AppendixA_Example4_Source(), test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB(), test_sec_accept_keyunwrap(), test_sec_source_keywrap(), test_SecurityContext_BIB_Acceptor(), test_SecurityContext_BIB_Source(), test_SecurityContext_BIB_Verifier(), and test_SecurityContext_BIB_Verifier_Failure().
| int BSL_TestUtils_ModifyEIDs | ( | BSL_BundleRef_t * | input_bundle, |
| const char * | src_eid, | ||
| const char * | dest_eid, | ||
| const char * | report_to_eid | ||
| ) |
Modify bundle's source eid, destination eid, and report-to eid.
| [in,out] | input_bundle | bundle to modify |
| [in] | src_eid | EID to set bundle source EID to. Set to NULL if bundle source EID should remain unchanged. |
| [in] | dest_eid | EID to set bundle destination EID to. Set to NULL if bundle destination EID should remain unchanged. |
| [in] | report_to_eid | EID to set bundle report-to EID to. Set to NULL if bundle report-to EID should remain unchanged. |
References BSL_BundleCtx_GetBundleMetadata(), BSL_PrimaryBlock_deinit(), BSL_PrimaryBlock_Init(), BSL_PrimaryBlock_t::field_dest_eid, BSL_PrimaryBlock_t::field_report_to_eid, BSL_PrimaryBlock_t::field_src_node_id, and mock_bpa_eid_from_text().
Referenced by n_test_BSL_6(), test_BSL_32(), TEST_CASE(), and test_dyn_mem_cbs_BSL_32().
| void BSL_TestUtils_PrintHexToBuffer | ( | const char * | message, |
| uint8_t * | buff, | ||
| size_t | bufflen | ||
| ) |
References BSL_Data_Deinit(), BSL_DATA_INIT_NULL, BSL_DATA_INIT_VIEW, BSL_LOG_INFO, BSL_TextUtil_Base16_Encode(), and BSL_Data_t::ptr.
Referenced by BSL_TestUtils_IsB16StrEqualTo().
|
static |
References BSL_free(), and BSL_TestUtils_Flat_Data_s::file.
Referenced by BSL_TestUtils_FlatReader().
|
static |
References BSL_TestUtils_Flat_Data_s::file.
Referenced by BSL_TestUtils_FlatReader().
|
static |
|
static |
References BSL_ERR_FAILURE, BSL_SUCCESS, BSL_TestUtils_Flat_Data_s::file, and BSL_TestUtils_Flat_Data_s::size.
Referenced by BSL_TestUtils_FlatWriter().