BSL v1.0.0 - 16.g9d98179
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 an 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)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
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_LOG_ERR, 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(), and TEST_CASE().

◆ BSL_Data_Deinit()

◆ BSL_Data_Init()

◆ BSL_Data_InitBuffer()

int BSL_Data_InitBuffer ( BSL_Data_t data,
size_t  bytelen 
)

◆ BSL_Data_InitMove()

void BSL_Data_InitMove ( BSL_Data_t data,
BSL_Data_t src 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References ASSERT_ARG_NONNULL, and bsl_data_int_reset().

Referenced by mock_bpa_ctr_init_move().

◆ 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_mock_decode_eid_from_ctx(), BSL_SecParam_GetAsBytestr(), BSL_SecResult_GetAsBytestr(), BSLX_BCB_Decrypt(), BSLX_BCB_GetParams(), BSLX_BIB_InitFromSecOper(), 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()

int BSL_Data_Resize ( BSL_Data_t data,
size_t  len 
)