BSL v0.0.0 - 0.geda3e66
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
UtilDefs_Data.c File Reference

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

#include <string.h>
#include <BPSecLib_Private.h>
+ Include dependency graph for UtilDefs_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, BSL_Data_t::len, and BSL_Data_t::ptr.

◆ 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_Resize(), BSL_LOG_ERR, BSL_SUCCESS, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_Crypto_AddRegistryKey(), and bsl_mock_decode_eid().

◆ BSL_Data_Deinit()

int BSL_Data_Deinit ( BSL_Data_t data)

De-initialize a data struct, freeing if necessary.

Parameters
[in,out]dataThe data to de-initialize, which must not be NULL.
Returns
Zero upon success.
Postcondition
The struct must be initialized before using again.

References BSL_SUCCESS.

Referenced by bsl_mock_eid_deinit(), and BSL_SecOutcome_Deinit().

◆ BSL_Data_Init()

int BSL_Data_Init ( BSL_Data_t data)

Initialize an empty data struct.

Parameters
[in,out]dataThe data to initialize, which must not be NULL.
Returns
Zero upon success.
See also
BSL_DATA_INIT_NULL

References BSL_SUCCESS.

Referenced by BSL_Crypto_AddRegistryKey(), and bsl_mock_decode_eid().

◆ BSL_Data_InitBuffer()

int BSL_Data_InitBuffer ( BSL_Data_t data,
size_t  bytelen 
)

Initialize with an owned buffer of size bytelen.

Todo:
Clarify to indicate this calls MALLOC.
Parameters
[in,out]dataThe data to initialize.
[in]bytelenLength of buffer to allocate.
Returns
Zero upon success.

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

Referenced by BSL_SecOutcome_Init().

◆ 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, BSL_Data_t::len, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR(), BSL_API_QuerySecurity(), and BSL_SecParam_GetAsBytestr().

◆ BSL_Data_Resize()

int BSL_Data_Resize ( BSL_Data_t data,
size_t  len 
)

Resize the data, copying if necessary.

Parameters
[in,out]dataThe data to resize, which must not be NULL.
[in]lenThe new total size.
Returns
Zero upon success.

References BSL_ERR_INSUFFICIENT_SPACE, BSL_LOG_ERR, BSL_REALLOC, BSL_SUCCESS, BSL_Data_t::len, BSL_Data_t::owned, BSL_Data_t::ptr, and UNLIKELY.

Referenced by BSL_Data_AppendFrom(), and BSL_Data_CopyFrom().