Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/api/10-bsl-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ When heap memory is needed at BSL runtime, the following macros are used and hav
To help with the error reporting conventions above, the following macros can be used to simplify function precondition checking.
The precondition checks (on function parameters or on any other state generally) should be the first thing inside the function definition.

- [CHKRET(cond, val)](@ref CHKRET) for general error values
- [CHKNULL(cond)](@ref CHKNULL) when the function has a pointer return type
- [CHKERR1(cond)](@ref CHKERR1) when the function has an `int` return type
- [CHKVOID(cond)](@ref CHKVOID) when the function has an `void` return type
- [CHKFALSE(cond)](@ref CHKFALSE) when the function has an `bool` return type
- [BSL_CHKRET(cond, val)](@ref BSL_CHKRET) for general error values
- [BSL_CHKNULL(cond)](@ref BSL_CHKNULL) when the function has a pointer return type
- [BSL_CHKERR1(cond)](@ref BSL_CHKERR1) when the function has an `int` return type
- [BSL_CHKVOID(cond)](@ref BSL_CHKVOID) when the function has an `void` return type
- [BSL_CHKFALSE(cond)](@ref BSL_CHKFALSE) when the function has an `bool` return type

# Enumerations

Expand Down
18 changes: 9 additions & 9 deletions src/BPSecLib_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,25 @@ typedef enum
* @param val The return value if the check fails.
* @deprecated
*/
#define CHKRET(cond, val) \
if (!LIKELY(cond)) \
{ \
return val; \
#define BSL_CHKRET(cond, val) \
if (!LIKELY(cond)) \
{ \
return val; \
}
/// Return from void functions if condition fails.
#define CHKVOID(cond) CHKRET(cond, )
#define BSL_CHKVOID(cond) BSL_CHKRET(cond, )
/// Return a null pointer if condition fails.
#define CHKNULL(cond) CHKRET(cond, NULL)
#define BSL_CHKNULL(cond) BSL_CHKRET(cond, NULL)
/// Return false if condition fails.
#define CHKFALSE(cond) CHKRET(cond, false)
#define BSL_CHKFALSE(cond) BSL_CHKRET(cond, false)
/// Return the error value 1 if condition fails.
#define CHKERR1(cond) CHKRET(cond, 1)
#define BSL_CHKERR1(cond) BSL_CHKRET(cond, 1)
/** Check a value for non-zero and return that value.
* @warning The parameter is evaluated twice so should be a simple variable.
*
* @param value The value to check and conditionally return.
*/
#define CHKERRVAL(value) CHKRET(!(value), (value))
#define BSL_CHKERRVAL(value) BSL_CHKRET(!(value), (value))

/** @brief Codes indicating the fate of a block if a security operation over it fails
*
Expand Down
4 changes: 2 additions & 2 deletions src/backend/LoggingStderr.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ void BSL_closelog(void)

int BSL_LogGetSeverity(int *severity, const char *name)
{
CHKERR1(severity)
CHKERR1(name)
BSL_CHKERR1(severity);
BSL_CHKERR1(name);

for (size_t ix = 0; ix < sizeof(sev_names) / sizeof(const char *); ++ix)
{
Expand Down
14 changes: 7 additions & 7 deletions src/mock_bpa/ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr)
{
CHKVOID(ctr);
BSL_CHKVOID(ctr);
memset(ctr, 0, sizeof(*ctr));

BSL_Data_Init(&(ctr->encoded));
Expand All @@ -41,8 +41,8 @@ void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr)

void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src)
{
CHKVOID(ctr);
CHKVOID(src);
BSL_CHKVOID(ctr);
BSL_CHKVOID(src);
BSL_Data_InitMove(&(ctr->encoded), &(src->encoded));

ctr->bundle = src->bundle;
Expand All @@ -54,7 +54,7 @@ void mock_bpa_ctr_init_move(mock_bpa_ctr_t *ctr, mock_bpa_ctr_t *src)

void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr)
{
CHKVOID(ctr);
BSL_CHKVOID(ctr);
BSL_Data_Deinit(&(ctr->encoded));

if (ctr->bundle)
Expand All @@ -66,7 +66,7 @@ void mock_bpa_ctr_deinit(mock_bpa_ctr_t *ctr)

int mock_bpa_decode(mock_bpa_ctr_t *ctr)
{
CHKERR1(ctr);
BSL_CHKERR1(ctr);
MockBPA_Bundle_t *bundle = ctr->bundle_ref.data;

if (ctr->bundle_ref.data)
Expand Down Expand Up @@ -110,9 +110,9 @@ M_ALGO_DEF(MockBPA_BlockList, M_DEQUE_OPLIST(MockBPA_BlockList, M_OPEXTEND(M_POD

int mock_bpa_encode(mock_bpa_ctr_t *ctr)
{
CHKERR1(ctr);
BSL_CHKERR1(ctr);
MockBPA_Bundle_t *bundle = ctr->bundle_ref.data;
CHKERR1(bundle);
BSL_CHKERR1(bundle);

// TODO this is not really defined by BPSec or BPv7
MockBPA_BlockList_sort(bundle->blocks);
Expand Down
12 changes: 6 additions & 6 deletions src/mock_bpa/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ int bsl_mock_decode_eid_from_ctx(QCBORDecodeContext *dec, BSL_HostEID_t *eid)
int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk)
{
// GCOV_EXCL_START
CHKERR1(dec);
CHKERR1(blk);
BSL_CHKERR1(dec);
BSL_CHKERR1(blk);
// GCOV_EXCL_STOP

const size_t begin = QCBORDecode_Tell(dec);
Expand Down Expand Up @@ -236,8 +236,8 @@ int bsl_mock_decode_primary(QCBORDecodeContext *dec, MockBPA_PrimaryBlock_t *blk
int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t *blk)
{
// GCOV_EXCL_START
CHKERR1(dec);
CHKERR1(blk);
BSL_CHKERR1(dec);
BSL_CHKERR1(blk);
// GCOV_EXCL_STOP

const size_t begin = QCBORDecode_Tell(dec);
Expand Down Expand Up @@ -299,8 +299,8 @@ int bsl_mock_decode_canonical(QCBORDecodeContext *dec, MockBPA_CanonicalBlock_t
int bsl_mock_decode_bundle(QCBORDecodeContext *dec, MockBPA_Bundle_t *bundle)
{
// GCOV_EXCL_START
CHKERR1(dec);
CHKERR1(bundle);
BSL_CHKERR1(dec);
BSL_CHKERR1(bundle);
// GCOV_EXCL_STOP

QCBORItem decitem;
Expand Down
16 changes: 8 additions & 8 deletions src/mock_bpa/eid.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

void bsl_mock_eid_init(bsl_mock_eid_t *eid)
{
CHKVOID(eid);
BSL_CHKVOID(eid);
memset(eid, 0, sizeof(bsl_mock_eid_t));
}

void bsl_mock_eid_deinit(bsl_mock_eid_t *eid)
{
CHKVOID(eid);
BSL_CHKVOID(eid);
switch (eid->scheme)
{
case BSL_MOCK_EID_IPN:
Expand All @@ -55,7 +55,7 @@ void bsl_mock_eid_deinit(bsl_mock_eid_t *eid)

int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid)
{
CHKERR1(eid);
BSL_CHKERR1(eid);
memset(eid, 0, sizeof(BSL_HostEID_t));
eid->handle = BSL_MALLOC(sizeof(bsl_mock_eid_t));
if (!(eid->handle))
Expand All @@ -68,7 +68,7 @@ int MockBPA_EID_Init(void *user_data _U_, BSL_HostEID_t *eid)

void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid)
{
CHKVOID(eid);
BSL_CHKVOID(eid);
if (eid->handle)
{
bsl_mock_eid_deinit(eid->handle);
Expand All @@ -79,8 +79,8 @@ void MockBPA_EID_Deinit(void *user_data _U_, BSL_HostEID_t *eid)

int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data _U_)
{
CHKERR1(eid);
CHKERR1(text);
BSL_CHKERR1(eid);
BSL_CHKERR1(text);

// any spaces are invalid URI
// agrees with isspace()
Expand Down Expand Up @@ -174,8 +174,8 @@ int mock_bpa_eid_from_text(BSL_HostEID_t *eid, const char *text, void *user_data

// int mock_bpa_eid_to_text(string_t out, const BSL_HostEID_t *eid, void *user_data _U_)
// {
// CHKERR1(eid);
// CHKERR1(eid->handle);
// BSL_CHKERR1(eid);
// BSL_CHKERR1(eid->handle);
// bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle;

// switch (obj->scheme)
Expand Down
30 changes: 15 additions & 15 deletions src/mock_bpa/eidpat.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ void bsl_mock_eidpat_item_deinit(bsl_mock_eidpat_item_t *obj)
int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *text, const char **endptr)
{
// GCOV_EXCL_START
CHKERR1(item);
CHKERR1(text);
CHKERR1(endptr);
BSL_CHKERR1(item);
BSL_CHKERR1(text);
BSL_CHKERR1(endptr);
// GCOV_EXCL_STOP

// clean up if necessary
Expand Down Expand Up @@ -361,8 +361,8 @@ int mock_bpa_eidpat_item_from_text(bsl_mock_eidpat_item_t *item, const char *tex
bool mock_bpa_eidpat_item_match(const bsl_mock_eidpat_item_t *item, const bsl_mock_eid_t *eid)
{
// GCOV_EXCL_START
CHKERR1(item);
CHKERR1(eid);
BSL_CHKERR1(item);
BSL_CHKERR1(eid);
// GCOV_EXCL_STOP

if (item->scheme != eid->scheme)
Expand All @@ -386,7 +386,7 @@ bool mock_bpa_eidpat_item_match(const bsl_mock_eidpat_item_t *item, const bsl_mo

int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_)
{
CHKERR1(pat); // GCOV_EXCL_LINE
BSL_CHKERR1(pat); // GCOV_EXCL_LINE

memset(pat, 0, sizeof(BSL_HostEIDPattern_t));
pat->handle = BSL_MALLOC(sizeof(bsl_mock_eidpat_t));
Expand All @@ -404,15 +404,15 @@ int mock_bpa_eidpat_init(BSL_HostEIDPattern_t *pat, void *user_data _U_)

static void bsl_mock_eidpat_deinit(bsl_mock_eidpat_t *pat)
{
CHKVOID(pat); // GCOV_EXCL_LINE
BSL_CHKVOID(pat); // GCOV_EXCL_LINE

bsl_mock_eidpat_item_list_clear(pat->items);
memset(pat, 0, sizeof(bsl_mock_eidpat_t));
}

void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_)
{
CHKVOID(pat);
BSL_CHKVOID(pat);
if (pat->handle)
{
bsl_mock_eidpat_deinit(pat->handle);
Expand All @@ -424,10 +424,10 @@ void mock_bpa_eidpat_deinit(BSL_HostEIDPattern_t *pat, void *user_data _U_)
int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void *user_data _U_)
{
// GCOV_EXCL_START
CHKERR1(pat);
CHKERR1(text);
BSL_CHKERR1(pat);
BSL_CHKERR1(text);
bsl_mock_eidpat_t *obj = pat->handle;
CHKERR1(obj);
BSL_CHKERR1(obj);
// GCOV_EXCL_STOP

// clean up if necessary
Expand Down Expand Up @@ -475,10 +475,10 @@ int mock_bpa_eidpat_from_text(BSL_HostEIDPattern_t *pat, const char *text, void
bool mock_bpa_eidpat_match(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid, void *user_data _U_)
{
// GCOV_EXCL_START
CHKERR1(pat);
CHKERR1(pat->handle);
CHKERR1(eid);
CHKERR1(eid->handle);
BSL_CHKERR1(pat);
BSL_CHKERR1(pat->handle);
BSL_CHKERR1(eid);
BSL_CHKERR1(eid->handle);
// GCOV_EXCL_STOP

bsl_mock_eidpat_t *patobj = (bsl_mock_eidpat_t *)pat->handle;
Expand Down
2 changes: 1 addition & 1 deletion src/mock_bpa/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int bsl_mock_encode_eid(const BSL_HostEID_t *eid, BSL_Data_t *encoded_bytes)
bsl_mock_eid_t *obj = (bsl_mock_eid_t *)eid->handle;

// GCOV_EXCL_START
CHKERR1(obj);
BSL_CHKERR1(obj);
// GCOV_EXCL_STOP

QCBOREncodeContext enc;
Expand Down
28 changes: 14 additions & 14 deletions src/mock_bpa/text_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static const char *unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu

int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char *safe)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

const size_t in_len = m_string_size(in);
const char *curs = m_string_get_cstr(in);
Expand Down Expand Up @@ -113,8 +113,8 @@ int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char

int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

const size_t in_len = m_string_size(in);
const char *curs = m_string_get_cstr(in);
Expand Down Expand Up @@ -158,8 +158,8 @@ int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in)

int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

// unicode iterator
m_string_it_t it;
Expand Down Expand Up @@ -214,8 +214,8 @@ int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote)

int mock_bpa_slash_unescape(m_string_t out, const m_string_t in)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

const size_t in_len = m_string_size(in);
if (in_len == 0)
Expand Down Expand Up @@ -369,7 +369,7 @@ void mock_bpa_strip_space(m_string_t out, const char *in, size_t in_len)

void mock_bpa_string_tolower(m_string_t out)
{
CHKVOID(out);
BSL_CHKVOID(out);
size_t len = m_string_size(out);
for (size_t i = 0; i < len; i++)
{
Expand All @@ -379,7 +379,7 @@ void mock_bpa_string_tolower(m_string_t out)

void mock_bpa_string_toupper(m_string_t out)
{
CHKVOID(out);
BSL_CHKVOID(out);
size_t len = m_string_size(out);
for (size_t i = 0; i < len; i++)
{
Expand Down Expand Up @@ -436,8 +436,8 @@ static int base16_decode_char(uint8_t chr)

int mock_bpa_base16_decode(m_bstring_t out, const m_string_t in)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

const size_t in_len = m_string_size(in);
if (in_len % 2 != 0)
Expand Down Expand Up @@ -588,8 +588,8 @@ static int base64_decode_char(uint8_t chr)

int mock_bpa_base64_decode(m_bstring_t out, const m_string_t in)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

size_t in_len = m_string_size(in);
const char *curs = m_string_get_cstr(in);
Expand Down
4 changes: 2 additions & 2 deletions test/bsl_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ static int BSL_TestUtils_DecodeBase16_char(uint8_t chr)

int BSL_TestUtils_DecodeBase16(BSL_Data_t *out, const string_t in)
{
CHKERR1(out);
CHKERR1(in);
BSL_CHKERR1(out);
BSL_CHKERR1(in);

const size_t in_len = string_size(in);
if (in_len % 2 != 0)
Expand Down
Loading