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

Concrete implementation of the Abstract Security Block defined in RFC 9172. More...

#include <qcbor/qcbor_encode.h>
#include <qcbor/qcbor_spiffy_decode.h>
#include <BPSecLib_Private.h>
#include "AbsSecBlock.h"
+ Include dependency graph for AbsSecBlock.c:

Functions

size_t BSL_AbsSecBlock_Sizeof (void)
 Returns the size of the ::BSL_AbsSecBlock_t struct in bytes.
 
bool BSL_AbsSecBlock_IsConsistent (const BSL_AbsSecBlock_t *self)
 Checks internal consistency and sanity of this structure.
 
void BSL_AbsSecBlock_Print (const BSL_AbsSecBlock_t *self)
 Prints to LOG INFO.
 
void BSL_AbsSecBlock_InitEmpty (BSL_AbsSecBlock_t *self)
 Initialize a pre-allocated ASB with no contents.
 
void BSL_AbsSecBlock_Init (BSL_AbsSecBlock_t *self, int64_t sec_context_id, BSL_HostEID_t source_eid)
 Populate a pre-allocated Abstract Security Block.
 
void BSL_AbsSecBlock_Deinit (BSL_AbsSecBlock_t *self)
 Deinitializes and clears this ASB, clearing and releasing any owned memory.
 
bool BSL_AbsSecBlock_IsEmpty (const BSL_AbsSecBlock_t *self)
 Returns true if this ASB contains nothing (i.e., no targets, params and results)
 
bool BSL_AbsSecBlock_ContainsTarget (const BSL_AbsSecBlock_t *self, uint64_t target_block_num)
 Returns true if a given ASB contains the given block number as a security target.
 
void BSL_AbsSecBlock_AddTarget (BSL_AbsSecBlock_t *self, uint64_t target_block_id)
 Adds a given block ID as a security target covered by this ASB.
 
void BSL_AbsSecBlock_AddParam (BSL_AbsSecBlock_t *self, const BSL_SecParam_t *param)
 Add a security parameter to this security block (does NOT copy)
 
void BSL_AbsSecBlock_AddResult (BSL_AbsSecBlock_t *self, const BSL_SecResult_t *result)
 Add a security result to this security block (does NOT copy)
 
static size_t BSL_AbsSecBlock_GetResultCnt (const BSL_AbsSecBlock_t *self, uint64_t target_block_id)
 
int BSL_AbsSecBlock_StripResults (BSL_AbsSecBlock_t *self, uint64_t target_block_num)
 Remove security parameters and results found in outcome from this ASB.
 
ssize_t BSL_AbsSecBlock_EncodeToCBOR (const BSL_AbsSecBlock_t *self, UsefulBuf buf)
 Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.
 
int BSL_AbsSecBlock_DecodeFromCBOR (BSL_AbsSecBlock_t *self, const BSL_Data_t *encoded_cbor)
 Decodes and populates this ASB from a CBOR string.
 

Detailed Description

Concrete implementation of the Abstract Security Block defined in RFC 9172.

Function Documentation

◆ BSL_AbsSecBlock_AddParam()

void BSL_AbsSecBlock_AddParam ( BSL_AbsSecBlock_t *  self,
const BSL_SecParam_t *  param 
)

Add a security parameter to this security block (does NOT copy)

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis security block
[in]paramNon-Null Security parameter pointer to add to list

References BSL_AbsSecBlock_IsConsistent().

◆ BSL_AbsSecBlock_AddResult()

void BSL_AbsSecBlock_AddResult ( BSL_AbsSecBlock_t *  self,
const BSL_SecResult_t *  result 
)

Add a security result to this security block (does NOT copy)

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis security block
[in]resultNon-Null Security result pointer to add to list

References BSL_AbsSecBlock_IsConsistent().

◆ BSL_AbsSecBlock_AddTarget()

void BSL_AbsSecBlock_AddTarget ( BSL_AbsSecBlock_t *  self,
uint64_t  target_block_id 
)

Adds a given block ID as a security target covered by this ASB.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB.
[in]target_block_idID of a block, 0 indicates primary block as usual.

References BSL_AbsSecBlock_IsConsistent().

◆ BSL_AbsSecBlock_ContainsTarget()

bool BSL_AbsSecBlock_ContainsTarget ( const BSL_AbsSecBlock_t *  self,
uint64_t  target_block_num 
)

Returns true if a given ASB contains the given block number as a security target.

Parameters
[in,out]selfThis ASB.
[in]target_block_numID of a block, 0 indicates primary block
Returns
true if ASB contains target

References BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_API_QuerySecurity().

◆ BSL_AbsSecBlock_DecodeFromCBOR()

int BSL_AbsSecBlock_DecodeFromCBOR ( BSL_AbsSecBlock_t *  self,
const BSL_Data_t encoded_cbor 
)

Decodes and populates this ASB from a CBOR string.

Parameters
[in,out]selfThis allocated, but uninitialized ASB to populate.
[in]encoded_cborA buffer containing a CBOR string representing the ASB
Returns
Negative on error

References BSL_AbsSecBlock_InitEmpty(), BSL_AbsSecBlock_IsConsistent(), BSL_Data_InitView(), BSL_ERR_DECODING, BSL_HostEID_DecodeFromCBOR(), BSL_HostEID_Init(), BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_LOG_WARNING, BSL_SecParam_InitBytestr(), BSL_SecParam_InitInt64(), BSL_SecResult_Init(), BSL_SUCCESS, BSL_Data_t::len, BSL_Data_t::owned, and BSL_Data_t::ptr.

Referenced by BSL_API_QuerySecurity().

◆ BSL_AbsSecBlock_Deinit()

void BSL_AbsSecBlock_Deinit ( BSL_AbsSecBlock_t *  self)

Deinitializes and clears this ASB, clearing and releasing any owned memory.

Parameters
[in,out]selfThis ASB

References BSL_AbsSecBlock_IsConsistent(), and BSL_HostEID_Deinit().

Referenced by BSL_API_QuerySecurity().

◆ BSL_AbsSecBlock_EncodeToCBOR()

ssize_t BSL_AbsSecBlock_EncodeToCBOR ( const BSL_AbsSecBlock_t *  self,
UsefulBuf  buf 
)

Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.

Parameters
[in]selfThis ASB.
[in]bufA buffer with allocated space for the encoded CBOR or the SizeCalculateUsefulBuf value to get the real size.
Returns
Integer contains number of bytes written to buffer, negative indicates error.

References BSL_AbsSecBlock_IsConsistent(), BSL_ERR_ENCODING, BSL_HostEID_EncodeToCBOR(), BSL_LOG_ERR, BSL_LOG_INFO, BSL_SecParam_GetAsBytestr(), BSL_SecParam_GetAsUInt64(), BSL_SecParam_IsInt64(), BSL_Data_t::len, and BSL_Data_t::ptr.

◆ BSL_AbsSecBlock_Init()

void BSL_AbsSecBlock_Init ( BSL_AbsSecBlock_t *  self,
int64_t  sec_context_id,
BSL_HostEID_t  source_eid 
)

Populate a pre-allocated Abstract Security Block.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB
[in]sec_context_idSecurity Context ID
[in]source_eidSource EID in format native to host BPA.

References BSL_AbsSecBlock_IsConsistent().

◆ BSL_AbsSecBlock_InitEmpty()

void BSL_AbsSecBlock_InitEmpty ( BSL_AbsSecBlock_t *  self)

Initialize a pre-allocated ASB with no contents.

Parameters
[in,out]selfThis ASB

Referenced by BSL_AbsSecBlock_DecodeFromCBOR().

◆ BSL_AbsSecBlock_IsConsistent()

bool BSL_AbsSecBlock_IsConsistent ( const BSL_AbsSecBlock_t *  self)

◆ BSL_AbsSecBlock_IsEmpty()

bool BSL_AbsSecBlock_IsEmpty ( const BSL_AbsSecBlock_t *  self)

Returns true if this ASB contains nothing (i.e., no targets, params and results)

Parameters
[in]selfThis ASB.
Returns
true if ASB is empty

◆ BSL_AbsSecBlock_Print()

void BSL_AbsSecBlock_Print ( const BSL_AbsSecBlock_t *  self)

Prints to LOG INFO.

Todo:
  • Can be backend-only.
Parameters
[in]selfThis ASB
Todo:
Refactor to dump this to a pre-allocated string.

References BSL_Log_DumpAsHexString(), and BSL_LOG_INFO.

◆ BSL_AbsSecBlock_Sizeof()

size_t BSL_AbsSecBlock_Sizeof ( void  )

Returns the size of the ::BSL_AbsSecBlock_t struct in bytes.

Returns
size of the struct

Referenced by BSL_API_QuerySecurity().

◆ BSL_AbsSecBlock_StripResults()

int BSL_AbsSecBlock_StripResults ( BSL_AbsSecBlock_t *  self,
uint64_t  target_block_num 
)

Remove security parameters and results found in outcome from this ASB.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB
[in]outcomeSecurity Operation outcome containing params and results
Returns
Negative on error, otherwise count of things removed.

References BSL_AbsSecBlock_IsConsistent(), BSL_ERR_PROPERTY_CHECK_FAILED, and BSL_LOG_ERR.