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

Managed memory interface using only C99 types and functions. More...

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
+ Include dependency graph for Data.h:
+ This graph shows which files directly or indirectly include this file:

Data Structures

struct  BSL_Data_t
 Optional heap data storage and views. More...
 

Macros

#define BSL_DATA_INIT_NULL
 Static initializer for a data store.
 

Typedefs

typedef uint8_t * BSL_DataPtr_t
 Data pointer for BSL_Data_t.
 
typedef const uint8_t * BSL_DataConstPtr_t
 Pointer to constant data for BSL_Data_t.
 

Functions

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, 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_Resize (BSL_Data_t *data, size_t len)
 Resize the data, copying 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_AppendFrom (BSL_Data_t *data, size_t len, BSL_DataConstPtr_t src)
 Append an initialized data struct with a given size.
 

Detailed Description

Managed memory interface using only C99 types and functions.

Macro Definition Documentation

◆ BSL_DATA_INIT_NULL

#define BSL_DATA_INIT_NULL
Value:
{ \
.owned = false, .ptr = NULL, .len = 0 \
}

Static initializer for a data store.

See also
BSL_Data_Init()

Typedef Documentation

◆ BSL_DataConstPtr_t

typedef const uint8_t* BSL_DataConstPtr_t

Pointer to constant data for BSL_Data_t.

◆ BSL_DataPtr_t

typedef uint8_t* BSL_DataPtr_t

Data pointer for BSL_Data_t.

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_Resize()