BSL v1.1.1 - 19.g31939de
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
TestUtils.c File Reference
#include <assert.h>
#include <m-string.h>
#include <BPSecLib_Private.h>
#include <CryptoInterface.h>
#include <mock_bpa/MockBPA.h>
#include <backend/IdValPair.h>
#include <backend/SecurityActionSet.h>
#include <backend/UtilDefs_SeqReadWrite.h>
#include <policy_provider/SamplePolicyProvider.h>
#include "TestUtils.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 *b16_string, BSL_Data_t encoded_val)
 
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)
 
BSL_HostEIDPattern_t BSL_TestUtils_GetEidPatternFromText (const char *text)
 
int BSL_TestUtils_EncodeBase16 (string_t out, const BSL_Data_t *in, bool uppercase)
 Encode to base16 text form.
 
static int BSL_TestUtils_DecodeBase16_char (uint8_t chr)
 Decode a single character.
 
int BSL_TestUtils_DecodeBase16 (BSL_Data_t *out, const string_t in)
 Decode base16 text form.
 
int BSL_TestUtils_DecodeBase16_cstr (BSL_Data_t *output, const char *input)
 
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)
 
BSL_SeqWriter_t * BSL_TestUtils_FlatWriter (void **buf, size_t *bufsize)
 Initialize a flat-buffer reader object.
 

Variables

static const size_t BSL_TestUtils_DecodeBase16_lim = 0x80
 Size of the BSL_TestUtils_DecodeBase16_table.
 
static const int BSL_TestUtils_DecodeBase16_table [0x80]
 Decode table for base16.
 

Function Documentation

◆ BSL_TestContext_Deinit()

int BSL_TestContext_Deinit ( BSL_TestContext_t ctx)

◆ BSL_TestContext_Init()

int BSL_TestContext_Init ( BSL_TestContext_t ctx)

References BSL_API_InitLib(), BSL_SUCCESS, ctx, and mock_bpa_ctr_init().

Referenced by _setUp(), and setUp().

◆ BSL_TestUtils_DecodeBase16()

int BSL_TestUtils_DecodeBase16 ( BSL_Data_t output,
const string_t  input 
)

Decode base16 text form.

This is defined in Section 8 of RFC 4648 [15].

Note
This function uses heap allocation for its output.
Parameters
[out]outputThe output buffer, which will be sized to its data.
[in]inputThe input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space().
Returns
Zero upon success.

References BSL_CHKERR1, BSL_Data_Resize(), BSL_TestUtils_DecodeBase16_char(), and BSL_Data_t::ptr.

Referenced by BSL_TestUtils_DecodeBase16_cstr(), BSL_TestUtils_IsB16StrEqualTo(), BSL_TestUtils_LoadBundleFromCBOR(), test_bsl_loopback_eid(), test_bsl_mock_encode_canonical(), test_bsl_mock_encode_primary(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_DecodeBase16(), test_mock_bpa_crc_crc16(), test_mock_bpa_crc_crc32c(), test_mock_bpa_ctr_decode_invalid(), test_qcbor_decode_array_nested(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_accept_keyunwrap(), and test_sec_source_keywrap().

◆ BSL_TestUtils_DecodeBase16_char()

static int BSL_TestUtils_DecodeBase16_char ( uint8_t  chr)
static

Decode a single character.

Parameters
chrThe character to decode.
Returns
If positive, the decoded value. -1 to indicate error. -2 to indicate whitespace.

References BSL_TestUtils_DecodeBase16_lim, and BSL_TestUtils_DecodeBase16_table.

Referenced by BSL_TestUtils_DecodeBase16().

◆ BSL_TestUtils_DecodeBase16_cstr()

int BSL_TestUtils_DecodeBase16_cstr ( BSL_Data_t output,
const char *  input 
)

◆ BSL_TestUtils_EncodeBase16()

int BSL_TestUtils_EncodeBase16 ( string_t  output,
const BSL_Data_t input,
bool  uppercase 
)

Encode to base16 text form.

This is defined in Section 8 of RFC 4648 [15].

Note
This function uses heap allocation for its output.
Parameters
[out]outputThe output buffer, which will be appended to.
[in]inputThe input buffer to read.
uppercaseTrue to use upper-case letters, false to use lower-case.
Returns
Zero upon success.

References BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by printencoded().

◆ BSL_TestUtils_FlatReader()

◆ BSL_TestUtils_FlatWriter()

◆ BSL_TestUtils_GetEidPatternFromText()

BSL_HostEIDPattern_t BSL_TestUtils_GetEidPatternFromText ( const char *  text)

◆ BSL_TestUtils_IsB16StrEqualTo()

◆ BSL_TestUtils_LoadBundleFromCBOR()

◆ BSL_TestUtils_ModifyEIDs()

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.

Parameters
[in,out]input_bundlebundle to modify
[in]src_eidEID to set bundle source EID to. Set to NULL if bundle source EID should remain unchanged.
[in]dest_eidEID to set bundle destination EID to. Set to NULL if bundle destination EID should remain unchanged.
[in]report_to_eidEID 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_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().

◆ BSL_TestUtils_PrintHexToBuffer()

void BSL_TestUtils_PrintHexToBuffer ( const char *  message,
uint8_t *  buff,
size_t  bufflen 
)

◆ BSL_TestUtils_ReadBTSD_Deinit()

static void BSL_TestUtils_ReadBTSD_Deinit ( void *  user_data)
static

◆ BSL_TestUtils_ReadBTSD_Read()

static int BSL_TestUtils_ReadBTSD_Read ( void *  user_data,
void *  buf,
size_t *  bufsize 
)
static

◆ BSL_TestUtils_WriteBTSD_Deinit()

◆ BSL_TestUtils_WriteBTSD_Write()

static int BSL_TestUtils_WriteBTSD_Write ( void *  user_data,
const void *  buf,
size_t  size 
)
static

Variable Documentation

◆ BSL_TestUtils_DecodeBase16_lim

const size_t BSL_TestUtils_DecodeBase16_lim = 0x80
static

Size of the BSL_TestUtils_DecodeBase16_table.

Referenced by BSL_TestUtils_DecodeBase16_char().

◆ BSL_TestUtils_DecodeBase16_table

const int BSL_TestUtils_DecodeBase16_table[0x80]
static
Initial value:
=
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -1, -1, -2, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
}

Decode table for base16.

Referenced by BSL_TestUtils_DecodeBase16_char().