BSL v1.1.1 - 50.g42e5d9b
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
Variant.c File Reference

Definition of a variant-type container. More...

#include "Variant.h"
+ Include dependency graph for Variant.c:

Functions

size_t BSL_Variant_Sizeof (void)
 Return size of BSL_Variant_s struct type.
 
void BSL_Variant_Init (BSL_Variant_t *self)
 Initialize to a default empty state.
 
void BSL_Variant_InitSet (BSL_Variant_t *self, const BSL_Variant_t *src)
 Initialize to a copy of another value.
 
void BSL_Variant_Deinit (BSL_Variant_t *self)
 De-initialize a parameter.
 
void BSL_Variant_Set (BSL_Variant_t *self, const BSL_Variant_t *src)
 Overwrite with a copy of another value.
 
void BSL_Variant_Move (BSL_Variant_t *self, BSL_Variant_t *src)
 Move from another value.
 
void BSL_Variant_SetTextstr (BSL_Variant_t *self, const char *value)
 Initialize as a parameter containing a byte string with a null-terminated text value.
 
bool BSL_Variant_IsTextstr (const BSL_Variant_t *self)
 Returns true when the value type is a text string.
 
void BSL_Variant_SetBytestr (BSL_Variant_t *self, BSL_Data_t value)
 Initialize as a parameter containing a bytestring.
 
void BSL_Variant_SetInt64 (BSL_Variant_t *self, int64_t value)
 Set to an signed integer value.
 
bool BSL_Variant_IsInt64 (const BSL_Variant_t *self)
 Returns true when the value type is an integer.
 
int BSL_Variant_GetAsInt64 (const BSL_Variant_t *self, int64_t *out)
 Retrieve integer value of result when this result type is integer.
 
bool BSL_Variant_IsBytestr (const BSL_Variant_t *self)
 Returns true when the value type is a byte string.
 
int BSL_Variant_GetAsBytestr (const BSL_Variant_t *self, BSL_Data_t *out)
 Retrieve byte string value of a parameter.
 
int BSL_Variant_GetAsTextstr (const BSL_Variant_t *self, const char **out)
 Retrieve bytestring value of result when security parameter type is bytestring.
 
void BSL_Variant_SetRaw (BSL_Variant_t *self, const void *ptr, size_t len)
 Initialize as a parameter containing raw encoded content.
 
bool BSL_Variant_IsRaw (const BSL_Variant_t *self)
 Returns true when the value type is raw encoded CBOR.
 
int BSL_Variant_GetAsRaw (const BSL_Variant_t *self, BSL_Data_t *out)
 Retrieve bytestring value of result when security parameter type is bytestring.
 
bool BSL_Variant_IsConsistent (const BSL_Variant_t *self)
 Return true if invariant conditions pass.
 
int BSL_Variant_Decode (QCBORDecodeContext *dec, BSL_Variant_t *var)
 Decode from CBOR, as a pair of items either in an array or from a map key-value.
 
void BSL_Variant_Encode (QCBOREncodeContext *enc, const BSL_Variant_t *pair)
 Encode to CBOR, as a pair of items either in an array or a map key-value.
 

Detailed Description

Definition of a variant-type container.

Function Documentation

◆ BSL_Variant_Decode()

int BSL_Variant_Decode ( QCBORDecodeContext *  dec,
BSL_Variant_t *  pair 
)

Decode from CBOR, as a pair of items either in an array or from a map key-value.

Matches the BSL_CBOR_Decode_f signature.

References ASSERT_ARG_NONNULL, BSL_Data_InitView(), BSL_ERR_DECODING, BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_SUCCESS, BSL_Variant_SetBytestr(), BSL_Variant_SetInt64(), BSL_Variant_SetRaw(), and BSL_Data_t::len.

Referenced by BSL_AbsSecBlock_Decode(), and BSLX_CoseMsg_Headers_Decode_Map().

◆ BSL_Variant_Deinit()

void BSL_Variant_Deinit ( BSL_Variant_t *  self)

◆ BSL_Variant_Encode()

void BSL_Variant_Encode ( QCBOREncodeContext *  enc,
const BSL_Variant_t *  pair 
)

◆ BSL_Variant_GetAsBytestr()

◆ BSL_Variant_GetAsInt64()

int BSL_Variant_GetAsInt64 ( const BSL_Variant_t *  self,
int64_t *  out 
)

Retrieve integer value of result when this result type is integer.

Parameters
[in]selfThis Security Parameter
[out]outThe optional value
Returns
Zero if the value is an integer.

References BSL_CHKRET, BSL_ERR_NOT_FOUND, BSL_SUCCESS, BSL_Variant_IsConsistent(), BSLB_VARIANT_TYPE_INT64, and CHK_PRECONDITION.

Referenced by BSL_Variant_Encode(), BSLX_BCB_Execute(), BSLX_BCB_GetOptions(), BSLX_BIB_Execute(), BSLX_BIB_InitFromSecOper(), BSLX_CoseSc_GetAndValidateKey(), BSLX_CoseSc_GetAndValidateTarget(), and BSLX_CoseSc_GetOptions().

◆ BSL_Variant_GetAsRaw()

int BSL_Variant_GetAsRaw ( const BSL_Variant_t *  self,
BSL_Data_t out 
)

Retrieve bytestring value of result when security parameter type is bytestring.

Parameters
[in]selfThis Security Parameter
[out]outPointer to optional struct which will be made a view onto this parameter value. That view must not outlive this pair instance.
Returns
Negative on error.

References BSL_CHKRET, BSL_Data_InitView(), BSL_ERR_NOT_FOUND, BSL_SUCCESS, BSL_Variant_IsConsistent(), BSLB_VARIANT_TYPE_RAW, and CHK_PRECONDITION.

Referenced by BSL_Variant_Encode(), BSLX_CoseMsg_Headers_CheckCrit(), BSLX_CoseSc_GetAndValidateAadScope(), and BSLX_CoseSc_GetOptions().

◆ BSL_Variant_GetAsTextstr()

int BSL_Variant_GetAsTextstr ( const BSL_Variant_t *  self,
const char **  out 
)

Retrieve bytestring value of result when security parameter type is bytestring.

Parameters
[in]selfThis Security Parameter
[in,out]outPointer to optional string pointer for view onto this parameter value. That view must not outlive this pair instance.
Returns
Negative on error.

References BSL_CHKRET, BSL_ERR_NOT_FOUND, BSL_SUCCESS, BSL_Variant_IsConsistent(), BSLB_VARIANT_TYPE_TEXTSTR, and CHK_PRECONDITION.

Referenced by BSL_Variant_Print(), BSLX_BCB_GetOptions(), and BSLX_BIB_InitFromSecOper().

◆ BSL_Variant_Init()

void BSL_Variant_Init ( BSL_Variant_t *  self)

Initialize to a default empty state.

Parameters
[out]selfThe object to initialize.

References ASSERT_ARG_NONNULL, and BSLB_VARIANT_TYPE_UNKNOWN.

Referenced by BSL_Variant_InitSet(), and test_CCSDS_Example_Mac_VerifyAccept().

◆ BSL_Variant_InitSet()

void BSL_Variant_InitSet ( BSL_Variant_t *  self,
const BSL_Variant_t *  src 
)

Initialize to a copy of another value.

Parameters
[out]selfThe object to initialize.
[in]srcThe source of the copy.

References BSL_Variant_Init(), and BSL_Variant_Set().

◆ BSL_Variant_IsBytestr()

bool BSL_Variant_IsBytestr ( const BSL_Variant_t *  self)

Returns true when the value type is a byte string.

Parameters
[in]selfThis Security Parameter
Returns
True when value type is byte string.

References BSLB_VARIANT_TYPE_BYTESTR, and CHK_AS_BOOL.

Referenced by BSL_Variant_Encode(), BSL_Variant_Print(), BSLX_BIB_Execute(), test_AppendixA_Example1_BIB_Source(), test_AppendixA_Example4_BCB_Source(), test_AppendixA_Example5_BCB_Source(), test_AppendixA_Example6_BCB_Source(), and test_CCSDS_Example_Mac_Source().

◆ BSL_Variant_IsConsistent()

bool BSL_Variant_IsConsistent ( const BSL_Variant_t *  self)

Return true if invariant conditions pass.

Parameters
[in]selfThis security parameter
Returns
true if valid, false otherwise.

References BSLB_VARIANT_TYPE_RAW, BSLB_VARIANT_TYPE_UNKNOWN, and CHK_AS_BOOL.

Referenced by BSL_Variant_GetAsBytestr(), BSL_Variant_GetAsInt64(), BSL_Variant_GetAsRaw(), and BSL_Variant_GetAsTextstr().

◆ BSL_Variant_IsInt64()

bool BSL_Variant_IsInt64 ( const BSL_Variant_t *  self)

Returns true when the value type is an integer.

Parameters
[in]selfThis Security Parameter
Returns
True when value type is integer.

References BSLB_VARIANT_TYPE_INT64, and CHK_AS_BOOL.

Referenced by BSL_Variant_Encode(), and BSL_Variant_Print().

◆ BSL_Variant_IsRaw()

bool BSL_Variant_IsRaw ( const BSL_Variant_t *  self)

Returns true when the value type is raw encoded CBOR.

Parameters
[in]selfThis Security Parameter
Returns
True when value type is raw.

References BSLB_VARIANT_TYPE_RAW, and CHK_AS_BOOL.

Referenced by BSL_Variant_Encode().

◆ BSL_Variant_IsTextstr()

bool BSL_Variant_IsTextstr ( const BSL_Variant_t *  self)

Returns true when the value type is a text string.

Parameters
[in]selfThis Security Parameter
Returns
True when value type is text string.

References BSLB_VARIANT_TYPE_TEXTSTR, and CHK_AS_BOOL.

Referenced by BSL_Variant_Print().

◆ BSL_Variant_Move()

void BSL_Variant_Move ( BSL_Variant_t *  self,
BSL_Variant_t *  src 
)

Move from another value.

The other value is left deinitialized.

Parameters
[in,out]selfThe object to overwrite.
[in]srcThe source of the copy.

References ASSERT_ARG_NONNULL, BSL_Variant_Deinit(), BSLB_VARIANT_TYPE_BYTESTR, BSLB_VARIANT_TYPE_INT64, BSLB_VARIANT_TYPE_RAW, BSLB_VARIANT_TYPE_TEXTSTR, and BSLB_VARIANT_TYPE_UNKNOWN.

◆ BSL_Variant_Set()

void BSL_Variant_Set ( BSL_Variant_t *  self,
const BSL_Variant_t *  src 
)

◆ BSL_Variant_SetBytestr()

◆ BSL_Variant_SetInt64()

◆ BSL_Variant_SetRaw()

void BSL_Variant_SetRaw ( BSL_Variant_t *  self,
const void *  ptr,
size_t  len 
)

Initialize as a parameter containing raw encoded content.

Parameters
[in,out]selfThis Security Parameter
[in]ptrThe stat of the data.
lenThe length to copy.

References ASSERT_ARG_NONNULL, BSL_Variant_Deinit(), and BSLB_VARIANT_TYPE_RAW.

Referenced by BSL_Variant_Decode(), BSLX_CoseSc_AddAadScope(), BSLX_CoseSc_SetAadScope(), and test_CoseSc_InvalidOptions_Verifier().

◆ BSL_Variant_SetTextstr()

◆ BSL_Variant_Sizeof()

size_t BSL_Variant_Sizeof ( void  )

Return size of BSL_Variant_s struct type.