BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
PolicyParser.c File Reference
#include "PolicyParser.h"
#include "bsl/front/TextUtil.h"
#include "bsl/cose_sc/CoseContext.h"
#include "bsl/default_sc/DefaultSecContext.h"
#include <jansson.h>
#include <errno.h>
#include <strings.h>
+ Include dependency graph for PolicyParser.c:

Typedefs

typedef int(* BSLP_OptionHandler_f) (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value)
 Type for individual option handling according to each SC.
 

Functions

static int BSLP_GetTextAsInt (int64_t *as_int, const char *ptr, size_t len)
 Read a text value as long integer.
 
static int BSLP_GetNumberInt (const json_t *value, int64_t *as_int)
 Read a JSON value as long integer, either directly or from text.
 
static int BSLP_GetBytesHex (const json_t *value, BSL_Data_t *as_bytes)
 Read a JSON value as hexadecimal bytes from text.
 
static int BSLP_GetBoolean (const json_t *value, bool *as_bool)
 Read a JSON value as a boolean, either directly or from text.
 
static int BSLP_PolicyOptions_SC1 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value)
 Handle options for Security context ID 1.
 
static int BSLP_PolicyOptions_SC2 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value)
 Handle options for Security context ID 2.
 
static int BSLP_PolicyOptions_SC3 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value)
 Handle options for Security context ID 3.
 
static int BSLP_PolicyParser_ReadOneRule (BSLP_PolicyProvider_t *policy, const json_t *policy_rule_elm)
 
int BSLP_PolicyParser_FromJSON (const char *policy_cfg_path, BSLP_PolicyProvider_t *policy)
 Initialize local policy provider from JSON file.
 
static void BSLP_RegisterPolicyFromBitstring (const BSLP_PolicyParser_BitstringConfig_t policy_bits, BSLP_PolicyProvider_t *policy, BSLB_IdValPairPtrMap_t options)
 
int BSLP_PolicyParser_FromBitstringList (const char *policies, BSLP_PolicyProvider_t *policy)
 Initialize local policy provider from list of bit strings.
 

Typedef Documentation

◆ BSLP_OptionHandler_f

typedef int(* BSLP_OptionHandler_f) (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value)

Type for individual option handling according to each SC.

Function Documentation

◆ BSLP_GetBoolean()

static int BSLP_GetBoolean ( const json_t *  value,
bool *  as_bool 
)
static

Read a JSON value as a boolean, either directly or from text.

Parameters
[in]valueThe value to interpret.
[out]as_boolThe output value.

References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, and BSL_SUCCESS.

Referenced by BSLP_PolicyOptions_SC1(), and BSLP_PolicyOptions_SC2().

◆ BSLP_GetBytesHex()

static int BSLP_GetBytesHex ( const json_t *  value,
BSL_Data_t as_bytes 
)
static

Read a JSON value as hexadecimal bytes from text.

Parameters
[in]valueThe value to interpret.
[out]as_bytesThe output value.

References BSL_TextUtil_Base16_Decode().

Referenced by BSLP_PolicyOptions_SC3().

◆ BSLP_GetNumberInt()

static int BSLP_GetNumberInt ( const json_t *  value,
int64_t *  as_int 
)
static

Read a JSON value as long integer, either directly or from text.

Parameters
[in]valueThe value to interpret.
[out]as_intThe output value.

References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, BSL_SUCCESS, and BSLP_GetTextAsInt().

Referenced by BSLP_PolicyOptions_SC1(), BSLP_PolicyOptions_SC2(), and BSLP_PolicyOptions_SC3().

◆ BSLP_GetTextAsInt()

static int BSLP_GetTextAsInt ( int64_t *  as_int,
const char *  ptr,
size_t  len 
)
static

Read a text value as long integer.

The entire text must be consumed to be valid.

Parameters
[out]as_intThe output value.
[in]ptrThe text pointer.
lenThe text length (excluding null terminator).

References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, and BSL_SUCCESS.

Referenced by BSLP_GetNumberInt(), and BSLP_PolicyOptions_SC3().

◆ BSLP_PolicyOptions_SC1()

static int BSLP_PolicyOptions_SC1 ( BSLB_IdValPairPtrMap_t  options,
const char *  id_str,
json_t *  value 
)
static

◆ BSLP_PolicyOptions_SC2()

static int BSLP_PolicyOptions_SC2 ( BSLB_IdValPairPtrMap_t  options,
const char *  id_str,
json_t *  value 
)
static

◆ BSLP_PolicyOptions_SC3()

◆ BSLP_PolicyParser_FromBitstringList()

int BSLP_PolicyParser_FromBitstringList ( const char *  policies,
BSLP_PolicyProvider_t policy 
)

Initialize local policy provider from list of bit strings.

Parameters
[in]policiescomma separated policy bit strings as described by BSLP_PolicyParser_BitstringConfig_t
[in,out]policypolicy provider to configure. Must be initialize/allocated

References BSL_LOG_ERR, BSL_SUCCESS, BSLP_RegisterPolicyFromBitstring(), CHK_ARG_NONNULL, and policy.

Referenced by main().

◆ BSLP_PolicyParser_FromJSON()

int BSLP_PolicyParser_FromJSON ( const char *  policy_cfg_path,
BSLP_PolicyProvider_t policy 
)

Initialize local policy provider from JSON file.

Parameters
[in]policy_cfg_pathpath to JSON file containing policy configuration
[in,out]policypolicy provider to configure. Must be initialize/allocated

References BSL_ERR_POLICY_CONFIG, BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_SUCCESS, BSLP_PolicyParser_ReadOneRule(), CHK_ARG_NONNULL, and policy.

Referenced by main(), test_PolicyParser_ReadConfigEmpty(), test_PolicyParser_ReadConfigInvalid(), and test_PolicyParser_ReadConfigValid().

◆ BSLP_PolicyParser_ReadOneRule()

◆ BSLP_RegisterPolicyFromBitstring()