BSL v1.1.1 - 19.g31939de
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
Data.c File Reference

Implementation of the data containers for handling variable-sized buffers and ownership. More...

#include "Data.h"
#include "BPSecLib_Private.h"
#include <string.h>
+ Include dependency graph for Data.c:

Functions

static void bsl_data_int_reset (BSL_Data_t *data)
 
static void bsl_data_int_free (BSL_Data_t *data)
 
int BSL_Data_Init (BSL_Data_t *data)
 Initialize an empty data struct.
 
int BSL_Data_InitBuffer (BSL_Data_t *data, size_t bytelen)
 Initialize with a dynamically-allocated owned buffer of size bytelen *.
 
int BSL_Data_InitView (BSL_Data_t *data, size_t len, const BSL_DataPtr_t src)
 Initialize a data struct as an overlay on optional external data.
 
void BSL_Data_InitMove (BSL_Data_t *data, BSL_Data_t *src)
 Initialize a data struct with move semantics from an existing struct.
 
int BSL_Data_Deinit (BSL_Data_t *data)
 De-initialize a data struct, freeing if necessary.
 
int BSL_Data_CopyFrom (BSL_Data_t *data, size_t len, BSL_DataConstPtr_t src)
 Set an initialized data struct to a given size.
 
int BSL_Data_Resize (BSL_Data_t *data, size_t len)
 Resize the data, copying if necessary.
 
int BSL_Data_AppendFrom (BSL_Data_t *data, size_t len, BSL_DataConstPtr_t src)
 Append an initialized data struct with a given size.
 

Detailed Description

Implementation of the data containers for handling variable-sized buffers and ownership.

Function Documentation

◆ BSL_Data_AppendFrom()

int BSL_Data_AppendFrom ( BSL_Data_t data,
size_t  len,
BSL_DataConstPtr_t  src 
)

Append an initialized data struct with a given size.

Parameters
[in,out]dataThe data to copy into, which must not be NULL.
[in]lenThe total length to allocate, which may be non-zero.
[in]srcAn optional source buffer to copy from, from which len bytes will be copied.
Returns
Zero upon success.

References BSL_Data_Resize(), BSL_SUCCESS, CHK_ARG_EXPR, CHK_ARG_NONNULL, BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by BSL_Crypto_UnwrapKey(), BSL_Crypto_WrapKey(), and MockBPA_Agent_Exec().

◆ BSL_Data_CopyFrom()

int BSL_Data_CopyFrom ( BSL_Data_t data,
size_t  len,
BSL_DataConstPtr_t  src 
)

Set an initialized data struct to a given size.

Parameters
[in,out]dataThe data to copy into, which must not be NULL.
[in]lenThe total length to allocate, which may be non-zero.
[in]srcAn optional source buffer to copy from, from which len bytes will be copied.
Returns
Zero upon success.

References bsl_data_int_reset(), BSL_Data_Resize(), BSL_LOG_ERR, BSL_SUCCESS, CHK_ARG_NONNULL, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_Crypto_AddRegistryKey(), BSL_Crypto_WrapKey(), bsl_mock_decode_eid(), TEST_CASE(), and test_mock_bpa_ctr_decode_invalid().

◆ BSL_Data_Deinit()

◆ BSL_Data_Init()

◆ BSL_Data_InitBuffer()

int BSL_Data_InitBuffer ( BSL_Data_t data,
size_t  bytelen 
)

Initialize with a dynamically-allocated owned buffer of size bytelen *.

Parameters
[in,out]dataThe data to initialize.
[in]bytelenLength of buffer to dynamically allocate.
Returns
Zero upon success.

References bsl_data_int_reset(), BSL_malloc(), BSL_SUCCESS, CHK_ARG_EXPR, CHK_ARG_NONNULL, CHK_POSTCONDITION, BSL_Data_t::len, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), BSL_API_QuerySecurity(), BSL_AuthCtx_Init(), BSL_Cipher_Init(), BSL_ExecAnyVerifierAcceptor_Pre(), bsl_mock_encode_eid_from_ctx(), BSLX_BCB_Encrypt(), BSLX_BIB_Execute(), BSLX_BIB_GenHMAC(), BSLX_BIB_GenIPPT(), Encode_ASB(), TEST_CASE(), and TestASBDecodeEncodeClosure().

◆ BSL_Data_InitMove()

void BSL_Data_InitMove ( BSL_Data_t data,
BSL_Data_t src 
)

Initialize a data struct with move semantics from an existing struct.

References ASSERT_ARG_NONNULL, and bsl_data_int_reset().

◆ BSL_Data_InitView()

int BSL_Data_InitView ( BSL_Data_t data,
size_t  len,
BSL_DataPtr_t  src 
)

Initialize a data struct as an overlay on optional external data.

Parameters
[in,out]dataThe data to initialize, which must not be NULL.
[in]lenThe total length to allocate, which may be zero.
[in]srcAn optional source buffer to point to.
Returns
Zero upon success.

References BSL_SUCCESS, CHK_ARG_NONNULL, BSL_Data_t::len, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR(), BSL_IdValPair_Decode(), BSL_IdValPair_GetAsBytestr(), bsl_mock_decode_eid_from_ctx(), BSLX_BCB_Execute(), BSLX_BCB_GetOptions(), LLVMFuzzerTestOneInput(), MockBPA_GetBundleMetadata(), printencoded(), test_BSL_TestUtils_DecodeBase16_valid(), and TestASBDecodeEncodeClosure().

◆ bsl_data_int_free()

static void bsl_data_int_free ( BSL_Data_t data)
static

◆ bsl_data_int_reset()

◆ BSL_Data_Resize()