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

Implementation of a RFC9172 Parameter. More...

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

Functions

size_t BSL_SecParam_Sizeof (void)
 Return size of BSL_SecParam_s struct type.
 
void BSL_SecParam_Init (BSL_SecParam_t *self)
 Initialize to a default empty state.
 
void BSL_SecParam_InitSet (BSL_SecParam_t *self, const BSL_SecParam_t *src)
 Initialize to a copy of another value.
 
void BSL_SecParam_Deinit (BSL_SecParam_t *self)
 De-initialize a parameter.
 
void BSL_SecParam_Set (BSL_SecParam_t *self, const BSL_SecParam_t *src)
 Overwrite with a copy of another value.
 
int BSL_SecParam_InitTextstr (BSL_SecParam_t *self, uint64_t param_id, const char *value)
 Initialize as a parameter containing a byte string with a null-terminated text value.
 
int BSL_SecParam_InitBytestr (BSL_SecParam_t *self, uint64_t param_id, BSL_Data_t value)
 Initialize as a parameter containing a bytestring.
 
int BSL_SecParam_InitInt64 (BSL_SecParam_t *self, uint64_t param_id, uint64_t value)
 Initialize as a parameter containing an integer as a value.
 
bool BSL_SecParam_IsInt64 (const BSL_SecParam_t *self)
 Returns true when the value type is an integer.
 
uint64_t BSL_SecParam_GetAsUInt64 (const BSL_SecParam_t *self)
 Retrieve integer value of result when this result type is integer.
 
bool BSL_SecParam_IsBytestr (const BSL_SecParam_t *self)
 Returns true when the value type is a byte string.
 
int BSL_SecParam_GetAsBytestr (const BSL_SecParam_t *self, BSL_Data_t *out)
 Retrieve byte string value of a parameter.
 
int BSL_SecParam_GetAsTextstr (const BSL_SecParam_t *self, const char **out)
 Retrieve bytestring value of result when security parameter type is bytestring.
 
uint64_t BSL_SecParam_GetId (const BSL_SecParam_t *self)
 Get parameter ID of this param.
 
bool BSL_SecParam_IsConsistent (const BSL_SecParam_t *self)
 Return true if invariant conditions pass.
 
bool BSL_SecParam_IsParamIDOutput (uint64_t param_id)
 Indicates true when this parameter is NOT an implementation-specific security parameter.
 

Detailed Description

Implementation of a RFC9172 Parameter.

Function Documentation

◆ BSL_SecParam_Deinit()

void BSL_SecParam_Deinit ( BSL_SecParam_t *  self)

De-initialize a parameter.

Parameters
[in,out]selfThe object to deinitialize.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR(), and test_SecurityContext_BIB_Verifier_Failure().

◆ BSL_SecParam_GetAsBytestr()

int BSL_SecParam_GetAsBytestr ( const BSL_SecParam_t *  self,
BSL_Data_t out 
)

Retrieve byte string value of a parameter.

Warning
Always check BSL_SecParam_IsBytestr() before using this.
Todo:
Clarify whether result contains copy or view of content
Parameters
[in]selfThis Security Parameter
[out]outPointer to data struct which will be made a view onto this parameter value.
Returns
Negative on error.

References BSL_Data_InitView(), BSL_SecParam_IsConsistent(), and BSL_SECPARAM_TYPE_BYTESTR.

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), and BSLX_BIB_InitFromSecOper().

◆ BSL_SecParam_GetAsTextstr()

int BSL_SecParam_GetAsTextstr ( const BSL_SecParam_t *  self,
const char **  out 
)

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

Warning
Always check type before using this.
Todo:
Clarify whether result contains copy or view of content
Parameters
[in]selfThis Security Parameter
[in,out]outPointer to data struct which will be made a view onto this parameter value.
Returns
Negative on error.

References BSL_SecParam_IsConsistent(), BSL_SECPARAM_TYPE_TEXTSTR, and BSL_SUCCESS.

Referenced by BSLX_BIB_InitFromSecOper().

◆ BSL_SecParam_GetAsUInt64()

uint64_t BSL_SecParam_GetAsUInt64 ( const BSL_SecParam_t *  self)

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

Warning
Always check using BSL_SecParam_IsInt64() first.
Parameters
[in]selfThis Security Parameter
Returns
Integer value of parameter if present, panics/aborts otherwise.

References BSL_SECPARAM_TYPE_INT64.

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), and BSLX_BIB_InitFromSecOper().

◆ BSL_SecParam_GetId()

uint64_t BSL_SecParam_GetId ( const BSL_SecParam_t *  self)

Get parameter ID of this param.

Parameters
[in]selfThis BPSec Param type
Returns
The parameter ID value

References BSL_SecParam_IsConsistent().

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), BSLX_BIB_InitFromSecOper(), and test_SecurityContext_BIB_Verifier_Failure().

◆ BSL_SecParam_Init()

void BSL_SecParam_Init ( BSL_SecParam_t *  self)

Initialize to a default empty state.

Parameters
[out]selfThe object to initialize.

Referenced by BSL_SecParam_InitSet().

◆ BSL_SecParam_InitBytestr()

int BSL_SecParam_InitBytestr ( BSL_SecParam_t *  self,
uint64_t  param_id,
BSL_Data_t  value 
)

Initialize as a parameter containing a bytestring.

Parameters
[in,out]selfThis Security Parameter
[in]param_idID of the parameter
[in]valueView of bytes, which get copied into this Security Parameter.
Returns
Negative on an error.

References BSL_SECPARAM_TYPE_BYTESTR, BSL_SUCCESS, BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR().

◆ BSL_SecParam_InitInt64()

int BSL_SecParam_InitInt64 ( BSL_SecParam_t *  self,
uint64_t  param_id,
uint64_t  value 
)

Initialize as a parameter containing an integer as a value.

Parameters
[in,out]selfThis Security Parameter
[in]param_idID of the parameter
[in]valueView of bytes, which get copied into this Security Parameter.
Returns
Negative on an error.

References BSL_SECPARAM_TYPE_INT64, and BSL_SUCCESS.

Referenced by BSL_AbsSecBlock_DecodeFromCBOR(), and mock_bpa_register_policy_from_json().

◆ BSL_SecParam_InitSet()

void BSL_SecParam_InitSet ( BSL_SecParam_t *  self,
const BSL_SecParam_t *  src 
)

Initialize to a copy of another value.

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

References BSL_SecParam_Init(), and BSL_SecParam_Set().

◆ BSL_SecParam_InitTextstr()

int BSL_SecParam_InitTextstr ( BSL_SecParam_t *  self,
uint64_t  param_id,
const char *  value 
)

Initialize as a parameter containing a byte string with a null-terminated text value.

Parameters
[in,out]selfThis Security Parameter
[in]param_idID of the parameter
[in]valuetext string of the parameter, copied into self
Returns
Negative on an error.

References BSL_SECPARAM_TYPE_TEXTSTR, and BSL_SUCCESS.

Referenced by mock_bpa_register_policy_from_json(), and test_SecurityContext_BIB_Verifier_Failure().

◆ BSL_SecParam_IsBytestr()

bool BSL_SecParam_IsBytestr ( const BSL_SecParam_t *  self)

Returns true when the value type is a byte string.

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

References BSL_SECPARAM_TYPE_BYTESTR.

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), and BSL_AbsSecBlock_Print().

◆ BSL_SecParam_IsConsistent()

bool BSL_SecParam_IsConsistent ( const BSL_SecParam_t *  self)

Return true if invariant conditions pass.

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

References BSL_SECPARAM_TYPE_INT64, BSL_SECPARAM_TYPE_TEXTSTR, and BSL_SECPARAM_TYPE_UNKNOWN.

Referenced by BSL_SecOper_AppendParam(), BSL_SecOutcome_AppendParam(), BSL_SecParam_GetAsBytestr(), BSL_SecParam_GetAsTextstr(), BSL_SecParam_GetId(), BSLP_PolicyRule_CopyParam(), and BSLP_PolicyRule_MoveParam().

◆ BSL_SecParam_IsInt64()

bool BSL_SecParam_IsInt64 ( const BSL_SecParam_t *  self)

Returns true when the value type is an integer.

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

References BSL_SECPARAM_TYPE_INT64.

Referenced by BSL_AbsSecBlock_EncodeToCBOR(), BSL_AbsSecBlock_Print(), and BSLX_BIB_InitFromSecOper().

◆ BSL_SecParam_IsParamIDOutput()

bool BSL_SecParam_IsParamIDOutput ( uint64_t  param_id)

Indicates true when this parameter is NOT an implementation-specific security parameter.

Todo:
Rename to avoid using negative logic and clarify.
Parameters
param_idID of the parameter
Returns
True when this is NOT an internal parameter ID.

References BSL_SECPARAM_TYPE_INT_STARTINDEX.

◆ BSL_SecParam_Set()

void BSL_SecParam_Set ( BSL_SecParam_t *  self,
const BSL_SecParam_t *  src 
)

Overwrite with a copy of another value.

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

Referenced by BSL_SecParam_InitSet().