BSL v1.1.1 - 19.g31939de
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

void BSL_AbsSecBlock_Target_Init (BSL_AbsSecBlock_Target_t *self)
 Initialize a new target structure.
 
void BSL_AbsSecBlock_Target_Deinit (BSL_AbsSecBlock_Target_t *self)
 Deinitialize a target structure.
 
size_t BSL_AbsSecBlock_Sizeof (void)
 Returns the size of the BSL_AbsSecBlock_s struct in bytes.
 
bool BSL_AbsSecBlock_IsConsistent (const BSL_AbsSecBlock_t *self)
 Checks internal consistency and sanity of this structure.
 
static void BSL_IdValPair_Print (const BSL_IdValPair_t *pair, const char *label, size_t index)
 
void BSL_AbsSecBlock_Print (const BSL_AbsSecBlock_t *self)
 Logs events exposing the ASB content at LOG DEBUG severity.
 
void BSL_AbsSecBlock_Init (BSL_AbsSecBlock_t *self)
 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 no operations (i.e., no targets and results)
 
int64_t BSL_AbsSecBlock_GetContextID (const BSL_AbsSecBlock_t *self)
 Get the security context ID from a security block.
 
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.
 
BSL_AbsSecBlock_Target_tBSL_AbsSecBlock_AddTarget (BSL_AbsSecBlock_t *self, uint64_t target_block_num)
 Adds a given block ID as a security target covered by this ASB.
 
int BSL_AbsSecBlock_StripResults (BSL_AbsSecBlock_t *self, uint64_t target_block_num)
 Remove security parameters and results found in outcome from this ASB.
 
static void BSL_IdValPair_Encode (QCBOREncodeContext *enc, const BSL_IdValPair_t *pair)
 
ssize_t BSL_AbsSecBlock_EncodeToCBOR (const BSL_AbsSecBlock_t *self, BSL_Data_t *buf)
 Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.
 
static int BSL_IdValPair_Decode (QCBORDecodeContext *dec, BSL_IdValPair_t *pair)
 
int BSL_AbsSecBlock_DecodeFromCBOR (BSL_AbsSecBlock_t *self, const BSL_Data_t *buf)
 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_AddTarget()

BSL_AbsSecBlock_Target_t * BSL_AbsSecBlock_AddTarget ( BSL_AbsSecBlock_t *  self,
uint64_t  target_block_num 
)

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

Parameters
[in,out]selfThis ASB.
[in]target_block_numID of a block, 0 indicates primary block as usual.
Returns
The new target and its results.

References ASSERT_PRECONDITION, BSL_AbsSecBlock_IsConsistent(), and BSL_AbsSecBlock_Target_t::target_block_num.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR(), and BSL_ExecAnySource_Post().

◆ 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]selfThis ASB.
[in]target_block_numID of a block, 0 indicates primary block
Returns
true if ASB contains target

References ASSERT_PRECONDITION, BSL_AbsSecBlock_IsConsistent(), and BSL_AbsSecBlock_Target_t::target_block_num.

Referenced by BSL_API_QuerySecurity(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_DecodeFromCBOR()

int BSL_AbsSecBlock_DecodeFromCBOR ( BSL_AbsSecBlock_t *  self,
const BSL_Data_t buf 
)

◆ BSL_AbsSecBlock_Deinit()

void BSL_AbsSecBlock_Deinit ( BSL_AbsSecBlock_t *  self)

◆ BSL_AbsSecBlock_EncodeToCBOR()

ssize_t BSL_AbsSecBlock_EncodeToCBOR ( const BSL_AbsSecBlock_t *  self,
BSL_Data_t 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 a zero-length buffer to calculate the needed size.
Returns
Integer contains number of bytes written to buffer, negative indicates error.

References BSL_AbsSecBlock_IsConsistent(), BSL_Data_Deinit(), BSL_Data_InitBuffer(), BSL_ERR_ENCODING, BSL_HostEID_EncodeToCBOR(), BSL_IdValPair_Encode(), BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_LOG_PLAINTEXT_PTR, BSL_SUCCESS, buf, CHK_PRECONDITION, encoder, BSL_Data_t::len, BSL_Data_t::ptr, BSL_AbsSecBlock_Target_t::results, and BSL_AbsSecBlock_Target_t::target_block_num.

Referenced by Encode_ASB(), LLVMFuzzerTestOneInput(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_GetContextID()

int64_t BSL_AbsSecBlock_GetContextID ( const BSL_AbsSecBlock_t *  self)

Get the security context ID from a security block.

Parameters
[in]selfThis ASB.
Returns
The context ID integer.

References ASSERT_ARG_NONNULL.

Referenced by TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_Init()

void BSL_AbsSecBlock_Init ( BSL_AbsSecBlock_t *  self)

◆ 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 no operations (i.e., no targets and results)

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

References ASSERT_ARG_NONNULL.

Referenced by BSL_ExecBCBVerifierAcceptor(), and BSL_ExecBIBVerifierAcceptor().

◆ BSL_AbsSecBlock_Print()

void BSL_AbsSecBlock_Print ( const BSL_AbsSecBlock_t *  self)

Logs events exposing the ASB content at LOG DEBUG severity.

Parameters
[in]selfThis ASB

References BSL_IdValPair_Print(), BSL_LOG_DEBUG, BSL_AbsSecBlock_Target_t::results, and BSL_AbsSecBlock_Target_t::target_block_num.

◆ BSL_AbsSecBlock_Sizeof()

size_t BSL_AbsSecBlock_Sizeof ( void  )

Returns the size of the BSL_AbsSecBlock_s struct in bytes.

Returns
size of the struct

Referenced by BSL_API_QuerySecurity(), LLVMFuzzerTestOneInput(), TEST_CASE(), and TestASBDecodeEncodeClosure().

◆ 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(), CHK_POSTCONDITION, CHK_PRECONDITION, BSL_AbsSecBlock_Target_t::results, and BSL_AbsSecBlock_Target_t::target_block_num.

Referenced by BSL_ExecBCBVerifierAcceptor(), and BSL_ExecBIBVerifierAcceptor().

◆ BSL_AbsSecBlock_Target_Deinit()

void BSL_AbsSecBlock_Target_Deinit ( BSL_AbsSecBlock_Target_t self)

Deinitialize a target structure.

References BSL_AbsSecBlock_Target_t::results, and BSL_AbsSecBlock_Target_t::target_block_num.

◆ BSL_AbsSecBlock_Target_Init()

void BSL_AbsSecBlock_Target_Init ( BSL_AbsSecBlock_Target_t self)

Initialize a new target structure.

References BSL_AbsSecBlock_Target_t::results, and BSL_AbsSecBlock_Target_t::target_block_num.

◆ BSL_IdValPair_Decode()

static int BSL_IdValPair_Decode ( QCBORDecodeContext *  dec,
BSL_IdValPair_t *  pair 
)
static

◆ BSL_IdValPair_Encode()

static void BSL_IdValPair_Encode ( QCBOREncodeContext *  enc,
const BSL_IdValPair_t *  pair 
)
static

◆ BSL_IdValPair_Print()

static void BSL_IdValPair_Print ( const BSL_IdValPair_t *  pair,
const char *  label,
size_t  index 
)
static