BSL v0.0.0
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:

Go to the source code of this file.

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.

Definition in file UtilDefs_Data.c.

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.
lenThe total length to allocate, which may be non-zero.
srcAn optional source buffer to copy from, from which len bytes will be copied.
Returns
Zero upon success.

Definition at line 164 of file UtilDefs_Data.c.

References BSL_Data_Resize(), BSL_LOG_ERR, BSL_SUCCESS, BSL_Data_s::len, and BSL_Data_s::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.
lenThe total length to allocate, which may be non-zero.
srcAn optional source buffer to copy from, from which len bytes will be copied.
Returns
Zero upon success.

Definition at line 100 of file UtilDefs_Data.c.

References BSL_Data_Resize(), BSL_LOG_ERR, BSL_SUCCESS, BSL_Data_s::owned, and BSL_Data_s::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.

Definition at line 92 of file UtilDefs_Data.c.

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

Definition at line 50 of file UtilDefs_Data.c.

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.
bytelenLength of buffer to allocate.
Returns
Zero upon success.

Definition at line 57 of file UtilDefs_Data.c.

References BSL_SUCCESS, BSL_Data_s::len, BSL_Data_s::owned, and BSL_Data_s::ptr.

Referenced by BSL_SecOutcome_Init().

◆ 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.

Definition at line 84 of file UtilDefs_Data.c.

◆ 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.
lenThe total length to allocate, which may be zero.
srcAn optional source buffer to point to.
Returns
Zero upon success.

Definition at line 72 of file UtilDefs_Data.c.

References BSL_SUCCESS, BSL_Data_s::len, BSL_Data_s::owned, and BSL_Data_s::ptr.

Referenced by BSL_API_QuerySecurity(), and BSL_SecParam_GetAsBytestr().

◆ bsl_data_int_free()

static void bsl_data_int_free ( BSL_Data_t data)
static

Definition at line 40 of file UtilDefs_Data.c.

◆ bsl_data_int_reset()

static void bsl_data_int_reset ( BSL_Data_t data)
static

Definition at line 30 of file UtilDefs_Data.c.

◆ 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.
lenThe new total size.
Returns
Zero upon success.

Definition at line 131 of file UtilDefs_Data.c.

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

Referenced by BSL_Data_AppendFrom(), and BSL_Data_CopyFrom().