refactor: use nullptr (#115)
* refactor: use nullptr
* ci: use cpp on travis
* chore: use cpp 11
* revert: nullptr for test files
diff --git a/.travis.yml b/.travis.yml
index 50620d5..f0b70e6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,4 @@
-language: c
+language: cpp
compiler:
- gcc
sudo: false
diff --git a/src/Cose.cpp b/src/Cose.cpp
index 9260069..03162ee 100644
--- a/src/Cose.cpp
+++ b/src/Cose.cpp
@@ -11,7 +11,7 @@
bool IsValidCOSEHandle(HCOSE h)
{
COSE_Encrypt *p = (COSE_Encrypt *)h;
- if (p == NULL) {
+ if (p == nullptr) {
return false;
}
return true;
@@ -26,7 +26,7 @@
;
#ifdef USE_CBOR_CONTEXT
- if (context != NULL) {
+ if (context != nullptr) {
pcose->m_allocContext = *context;
}
#endif
@@ -39,22 +39,22 @@
pcose->m_protectedMap =
cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & errState);
- CHECK_CONDITION_CBOR(pcose->m_protectedMap != NULL, errState);
+ CHECK_CONDITION_CBOR(pcose->m_protectedMap != nullptr, errState);
pcose->m_dontSendMap =
cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & errState);
- CHECK_CONDITION_CBOR(pcose->m_dontSendMap != NULL, errState);
+ CHECK_CONDITION_CBOR(pcose->m_dontSendMap != nullptr, errState);
pcose->m_cborRoot = pcose->m_cbor =
cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & errState);
- CHECK_CONDITION_CBOR(pcose->m_cbor != NULL, errState);
+ CHECK_CONDITION_CBOR(pcose->m_cbor != nullptr, errState);
pcose->m_ownMsg = 1;
pcose->m_msgType = msgType;
pcose->m_unprotectMap =
cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & errState);
- CHECK_CONDITION_CBOR(pcose->m_unprotectMap != NULL, errState);
+ CHECK_CONDITION_CBOR(pcose->m_unprotectMap != nullptr, errState);
pcose->m_ownUnprotectedMap = true;
CHECK_CONDITION_CBOR(
_COSE_array_replace(pcose, pcose->m_unprotectMap, INDEX_UNPROTECTED,
@@ -66,7 +66,7 @@
cn_cbor_errback cbor_error;
cn_cbor *cn = cn_cbor_tag_create(
msgType, pcose->m_cborRoot, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
pcose->m_cborRoot = cn;
}
@@ -82,7 +82,7 @@
cn_cbor *pcbor,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- const cn_cbor *pmap = NULL;
+ const cn_cbor *pmap = nullptr;
cn_cbor_errback errState; // = { 0 };
cn_cbor_errback cbor_error;
@@ -92,7 +92,7 @@
}
#ifdef USE_CBOR_CONTEXT
- if (context != NULL) {
+ if (context != nullptr) {
pobj->m_allocContext = *context;
}
#endif
@@ -106,38 +106,38 @@
pmap = _COSE_arrayget_int(pobj, INDEX_PROTECTED);
- CHECK_CONDITION(pmap != NULL, COSE_ERR_INVALID_PARAMETER);
- if (pmap != NULL) {
+ CHECK_CONDITION(pmap != nullptr, COSE_ERR_INVALID_PARAMETER);
+ if (pmap != nullptr) {
CHECK_CONDITION(
pmap->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
if (pmap->length == 0) {
pobj->m_protectedMap =
- cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA nullptr);
CHECK_CONDITION(pobj->m_protectedMap, COSE_ERR_OUT_OF_MEMORY);
}
else {
pobj->m_protectedMap = cn_cbor_decode((const byte *)pmap->v.str,
pmap->length, CBOR_CONTEXT_PARAM_COMMA & errState);
CHECK_CONDITION(
- pobj->m_protectedMap != NULL, COSE_ERR_INVALID_PARAMETER);
+ pobj->m_protectedMap != nullptr, COSE_ERR_INVALID_PARAMETER);
}
}
pobj->m_unprotectMap = _COSE_arrayget_int(pobj, INDEX_UNPROTECTED);
- CHECK_CONDITION((pobj->m_unprotectMap != NULL) &&
+ CHECK_CONDITION((pobj->m_unprotectMap != nullptr) &&
(pobj->m_unprotectMap->type == CN_CBOR_MAP),
COSE_ERR_INVALID_PARAMETER);
pobj->m_ownUnprotectedMap = false;
pobj->m_dontSendMap =
cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pobj->m_dontSendMap != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pobj->m_dontSendMap != nullptr, cbor_error);
#if INCLUDE_COUNTERSIGNATURE
cn_cbor *pCounter =
cn_cbor_mapget_int(pobj->m_unprotectMap, COSE_Header_CounterSign);
- if (pCounter != NULL) {
+ if (pCounter != nullptr) {
CHECK_CONDITION(
pCounter->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(pCounter->length > 0, COSE_ERR_INVALID_PARAMETER);
@@ -145,14 +145,14 @@
cn_cbor *pSig = pCounter->first_child;
for (size_t i = 0; i < pCounter->length; i++, pSig = pSig->next) {
COSE_CounterSign *cs = _COSE_CounterSign_Init_From_Object(
- pSig, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
+ pSig, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
cs->m_next = pobj->m_counterSigners;
pobj->m_counterSigners = cs;
}
}
else {
COSE_CounterSign *cs = _COSE_CounterSign_Init_From_Object(
- pCounter, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
+ pCounter, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
pobj->m_counterSigners = cs;
}
}
@@ -171,26 +171,26 @@
cn_cbor_context *context = &pcose->m_allocContext;
#endif
- if (pcose->m_protectedMap != NULL) {
+ if (pcose->m_protectedMap != nullptr) {
CN_CBOR_FREE(pcose->m_protectedMap, context);
}
- if (pcose->m_ownUnprotectedMap && (pcose->m_unprotectMap != NULL)) {
+ if (pcose->m_ownUnprotectedMap && (pcose->m_unprotectMap != nullptr)) {
CN_CBOR_FREE(pcose->m_unprotectMap, context);
}
- if (pcose->m_dontSendMap != NULL) {
+ if (pcose->m_dontSendMap != nullptr) {
CN_CBOR_FREE(pcose->m_dontSendMap, context);
}
- if (pcose->m_ownMsg && (pcose->m_cborRoot != NULL) &&
- (pcose->m_cborRoot->parent == NULL)) {
+ if (pcose->m_ownMsg && (pcose->m_cborRoot != nullptr) &&
+ (pcose->m_cborRoot->parent == nullptr)) {
CN_CBOR_FREE(pcose->m_cborRoot, context);
}
#if INCLUDE_COUNTERSIGNATURE
- if (pcose->m_counterSigners != NULL) {
+ if (pcose->m_counterSigners != nullptr) {
COSE_CounterSign *p = pcose->m_counterSigners;
- COSE_CounterSign *p2 = NULL;
+ COSE_CounterSign *p2 = nullptr;
- while (p != NULL) {
+ while (p != nullptr) {
p2 = p->m_next;
COSE_CounterSign_Free((HCOSE_COUNTERSIGN)p);
p = p2;
@@ -205,7 +205,7 @@
COSE_object_type struct_type,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- cn_cbor *cbor = NULL;
+ cn_cbor *cbor = nullptr;
cn_cbor_errback cbor_err;
HCOSE h;
@@ -213,15 +213,15 @@
errorReturn:
// M00TODO - break up the init and allocation below for memory tests.
CN_CBOR_FREE(cbor, context);
- return NULL;
+ return nullptr;
}
CHECK_CONDITION(
- (rgbData != NULL) && (ptype != NULL), COSE_ERR_INVALID_PARAMETER);
+ (rgbData != nullptr) && (ptype != nullptr), COSE_ERR_INVALID_PARAMETER);
cbor =
cn_cbor_decode(rgbData, cbData, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cbor != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cbor != nullptr, cbor_err);
if (cbor->type == CN_CBOR_TAG) {
if (struct_type != 0) {
@@ -235,9 +235,9 @@
cn_cbor *ptag = cbor;
cbor = ptag->first_child;
- ptag->first_child = NULL;
- ptag->last_child = NULL;
- cbor->parent = NULL;
+ ptag->first_child = nullptr;
+ ptag->last_child = nullptr;
+ cbor->parent = nullptr;
CN_CBOR_FREE(ptag, context);
}
else {
@@ -247,13 +247,13 @@
CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
cn_cbor *cbor2 = cbor;
- cbor = NULL;
+ cbor = nullptr;
switch (*ptype) {
case COSE_enveloped_object:
#if INCLUDE_ENCRYPT
h = (HCOSE)_COSE_Enveloped_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -264,8 +264,8 @@
case COSE_sign_object:
#if INCLUDE_SIGN
h = (HCOSE)_COSE_Sign_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -276,8 +276,8 @@
case COSE_sign1_object:
#if INCLUDE_SIGN1
h = (HCOSE)_COSE_Sign1_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -288,8 +288,8 @@
case COSE_mac_object:
#if INCLUDE_MAC
h = (HCOSE)_COSE_Mac_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -300,8 +300,8 @@
case COSE_mac0_object:
#if INCLUDE_MAC0
h = (HCOSE)_COSE_Mac0_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -312,8 +312,8 @@
case COSE_encrypt_object:
#if INCLUDE_ENCRYPT0
h = (HCOSE)_COSE_Encrypt_Init_From_Object(
- cbor2, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (h == NULL) {
+ cbor2, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (h == nullptr) {
goto errorReturn;
}
#else
@@ -331,7 +331,7 @@
size_t COSE_Encode(HCOSE msg, byte *rgb, size_t ib, size_t cb)
{
- if (rgb == NULL) {
+ if (rgb == nullptr) {
return cn_cbor_encode_size(((COSE *)msg)->m_cbor) + ib;
}
ssize_t size = cn_cbor_encoder_write(rgb, ib, cb, ((COSE *)msg)->m_cbor);
@@ -342,7 +342,7 @@
{
COSE *msg = (COSE *)h;
if (!IsValidCOSEHandle(h)) {
- return NULL;
+ return nullptr;
}
return msg->m_cbor;
@@ -362,32 +362,32 @@
cn_cbor *_COSE_map_get_int(COSE *cose, int key, int flags, cose_errback *perr)
{
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_NONE;
}
- if ((cose->m_protectedMap != NULL) && ((flags & COSE_PROTECT_ONLY) != 0)) {
+ if ((cose->m_protectedMap != nullptr) && ((flags & COSE_PROTECT_ONLY) != 0)) {
p = cn_cbor_mapget_int(cose->m_protectedMap, key);
- if (p != NULL) {
+ if (p != nullptr) {
return p;
}
}
- if ((cose->m_unprotectMap != NULL) &&
+ if ((cose->m_unprotectMap != nullptr) &&
((flags & COSE_UNPROTECT_ONLY) != 0)) {
p = cn_cbor_mapget_int(cose->m_unprotectMap, key);
- if (p != NULL) {
+ if (p != nullptr) {
return p;
}
}
- if ((cose->m_dontSendMap != NULL) && ((flags & COSE_DONT_SEND) != 0)) {
+ if ((cose->m_dontSendMap != nullptr) && ((flags & COSE_DONT_SEND) != 0)) {
p = cn_cbor_mapget_int(cose->m_dontSendMap, key);
}
- if ((p == NULL) && (perr != NULL)) {
+ if ((p == nullptr) && (perr != nullptr)) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
@@ -399,25 +399,25 @@
int flags,
cose_errback *perror)
{
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_NONE;
}
- if ((pcose->m_protectedMap != NULL) && ((flags & COSE_PROTECT_ONLY) != 0)) {
+ if ((pcose->m_protectedMap != nullptr) && ((flags & COSE_PROTECT_ONLY) != 0)) {
p = cn_cbor_mapget_string(pcose->m_protectedMap, key);
- if (p != NULL) {
+ if (p != nullptr) {
return p;
}
}
- if ((pcose->m_unprotectMap != NULL) &&
+ if ((pcose->m_unprotectMap != nullptr) &&
((flags & COSE_UNPROTECT_ONLY) != 0)) {
p = cn_cbor_mapget_string(pcose->m_unprotectMap, key);
}
- if ((pcose->m_dontSendMap != NULL) && ((flags & COSE_DONT_SEND) != 0)) {
+ if ((pcose->m_dontSendMap != nullptr) && ((flags & COSE_DONT_SEND) != 0)) {
p = cn_cbor_mapget_string(pcose->m_dontSendMap, key);
}
@@ -435,13 +435,13 @@
#endif
cn_cbor_errback error;
bool f = false;
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
- CHECK_CONDITION(cn_cbor_mapget_int(cose->m_protectedMap, key) == NULL,
+ CHECK_CONDITION(cn_cbor_mapget_int(cose->m_protectedMap, key) == nullptr,
COSE_ERR_INVALID_PARAMETER);
- CHECK_CONDITION(cn_cbor_mapget_int(cose->m_unprotectMap, key) == NULL,
+ CHECK_CONDITION(cn_cbor_mapget_int(cose->m_unprotectMap, key) == nullptr,
COSE_ERR_INVALID_PARAMETER);
- CHECK_CONDITION(cn_cbor_mapget_int(cose->m_dontSendMap, key) == NULL,
+ CHECK_CONDITION(cn_cbor_mapget_int(cose->m_dontSendMap, key) == nullptr,
COSE_ERR_INVALID_PARAMETER);
switch (flags) {
@@ -475,15 +475,15 @@
{
cn_cbor *pProtected;
int cbProtected;
- byte *pbProtected = NULL;
+ byte *pbProtected = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pMessage->m_allocContext;
#endif // USE_CBOR_CONTEXT
pProtected = cn_cbor_index(pMessage->m_cbor, INDEX_PROTECTED);
- if ((pProtected != NULL) && (pProtected->type != CN_CBOR_INVALID)) {
+ if ((pProtected != nullptr) && (pProtected->type != CN_CBOR_INVALID)) {
errorReturn:
- if (pbProtected != NULL) {
+ if (pbProtected != nullptr) {
COSE_FREE(pbProtected, context);
}
return pProtected;
@@ -492,7 +492,7 @@
if (pMessage->m_protectedMap->length > 0) {
cbProtected = cn_cbor_encode_size(pMessage->m_protectedMap);
pbProtected = (byte *)COSE_CALLOC(cbProtected, 1, context);
- CHECK_CONDITION(pbProtected != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbProtected != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(cn_cbor_encoder_write(pbProtected, 0, cbProtected,
pMessage->m_protectedMap) == cbProtected,
@@ -503,12 +503,12 @@
}
pProtected = cn_cbor_data_create2(
- pbProtected, cbProtected, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(pProtected != NULL, COSE_ERR_OUT_OF_MEMORY);
- pbProtected = NULL;
+ pbProtected, cbProtected, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(pProtected != nullptr, COSE_ERR_OUT_OF_MEMORY);
+ pbProtected = nullptr;
CHECK_CONDITION(_COSE_array_replace(pMessage, pProtected, INDEX_PROTECTED,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
return pProtected;
@@ -544,7 +544,7 @@
void _COSE_InsertInList(COSE **rootNode, COSE *newMsg)
{
- if (*rootNode == NULL) {
+ if (*rootNode == nullptr) {
*rootNode = newMsg;
return;
}
@@ -555,14 +555,14 @@
bool _COSE_IsInList(const COSE *const rootNode, const COSE *const thisMsg)
{
- if (rootNode == NULL) {
+ if (rootNode == nullptr) {
return false;
}
- if (thisMsg == NULL) {
+ if (thisMsg == nullptr) {
return false;
}
- for (const COSE *walk = rootNode; walk != NULL; walk = walk->m_handleList) {
+ for (const COSE *walk = rootNode; walk != nullptr; walk = walk->m_handleList) {
if (walk == thisMsg) {
return true;
}
@@ -574,15 +574,15 @@
{
if (*rootNode == thisMsg) {
*rootNode = thisMsg->m_handleList;
- thisMsg->m_handleList = NULL;
+ thisMsg->m_handleList = nullptr;
return;
}
- for (COSE *walk = *rootNode; walk->m_handleList != NULL;
+ for (COSE *walk = *rootNode; walk->m_handleList != nullptr;
walk = walk->m_handleList) {
if (walk->m_handleList == thisMsg) {
walk->m_handleList = thisMsg->m_handleList;
- thisMsg->m_handleList = NULL;
+ thisMsg->m_handleList = nullptr;
return;
}
}
@@ -619,28 +619,28 @@
{
bool fRet = true;
#if INCLUDE_COUNTERSIGNATURE
- fRet &= CountersignRoot == NULL;
+ fRet &= CountersignRoot == nullptr;
#endif
#if INCLUDE_SIGN
- fRet &= SignerRoot == NULL && SignRoot == NULL;
+ fRet &= SignerRoot == nullptr && SignRoot == nullptr;
#endif
#if INCLUDE_SIGN1
- fRet &= Sign1Root == NULL;
+ fRet &= Sign1Root == nullptr;
#endif
#if INCLUDE_ENCRYPT0
- fRet &= EncryptRoot == NULL;
+ fRet &= EncryptRoot == nullptr;
#endif
#if INCLUDE_ENCRYPT
- fRet &= EnvelopedRoot == NULL;
+ fRet &= EnvelopedRoot == nullptr;
#endif
#if INCLUDE_ENCRYPT || INCLUDE_MAC
- fRet &= RecipientRoot == NULL;
+ fRet &= RecipientRoot == nullptr;
#endif
#if INCLUDE_MAC
- fRet &= MacRoot == NULL;
+ fRet &= MacRoot == nullptr;
#endif
#if INCLUDE_MAC0
- fRet &= Mac0Root == NULL;
+ fRet &= Mac0Root == nullptr;
#endif
return fRet;
}
diff --git a/src/CoseKey.cpp b/src/CoseKey.cpp
index 9a101b5..d22a84e 100644
--- a/src/CoseKey.cpp
+++ b/src/CoseKey.cpp
@@ -5,7 +5,7 @@
#include "cose_int.h"
#include "cose_crypto.h"
-COSE_KEY *KeysRoot = NULL;
+COSE_KEY *KeysRoot = nullptr;
/*! \private
* @brief Test if a HCOSE_ENVELOPED handle is valid
@@ -24,14 +24,14 @@
bool IsValidKeyHandle(HCOSE_KEY h)
{
COSE_KEY *p = (COSE_KEY*)h;
- if (KeysRoot == NULL) {
+ if (KeysRoot == nullptr) {
return false;
}
- if (p == NULL) {
+ if (p == nullptr) {
return false;
}
- for (const COSE_KEY *walk = KeysRoot; walk != NULL; walk = walk->m_nextKey) {
+ for (const COSE_KEY *walk = KeysRoot; walk != nullptr; walk = walk->m_nextKey) {
if (walk == p) {
return true;
}
@@ -42,19 +42,19 @@
HCOSE_KEY COSE_KEY_FromCbor(cn_cbor *pcborKey,
CBOR_CONTEXT_COMMA cose_errback *perror)
{
- COSE_KEY *pkey = NULL;
+ COSE_KEY *pkey = nullptr;
pkey = (COSE_KEY *)COSE_CALLOC(1, sizeof(COSE_KEY), context);
- if (pkey == NULL) {
- if (perror != NULL) {
+ if (pkey == nullptr) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
#ifdef USE_CBOR_CONTEXT
- if (context != NULL) {
+ if (context != nullptr) {
pkey->m_allocContext = *context;
}
#endif
@@ -82,14 +82,14 @@
if (KeysRoot == p) {
KeysRoot = p->m_nextKey;
- p->m_nextKey = NULL;;
+ p->m_nextKey = nullptr;;
}
else {
- for (COSE_KEY *walk = KeysRoot; walk->m_nextKey != NULL;
+ for (COSE_KEY *walk = KeysRoot; walk->m_nextKey != nullptr;
walk = walk->m_nextKey) {
if (walk->m_nextKey == p) {
walk->m_nextKey = p->m_nextKey;
- p->m_nextKey = NULL;
+ p->m_nextKey = nullptr;
break;
}
}
@@ -103,17 +103,17 @@
#if defined(COSE_C_USE_OPENSSL) && (OPENSSL_VERSION_NUMBER > 0x10100000L)
HCOSE_KEY COSE_KEY_FromEVP(EVP_PKEY * opensslKey, cn_cbor * pcborKey, CBOR_CONTEXT_COMMA cose_errback* perror)
{
- COSE_KEY *pkey = NULL;
+ COSE_KEY *pkey = nullptr;
pkey = (COSE_KEY *)COSE_CALLOC(1, sizeof(COSE_KEY), context);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
perror->err = COSE_ERR_OUT_OF_MEMORY;
- return NULL;
+ return nullptr;
}
#ifdef USE_CBOR_CONTEXT
- if (context != NULL) {
+ if (context != nullptr) {
pkey->m_allocContext = *context;
}
#endif
diff --git a/src/CounterSign.cpp b/src/CounterSign.cpp
index 4698fad..6b329c6 100644
--- a/src/CounterSign.cpp
+++ b/src/CounterSign.cpp
@@ -10,7 +10,7 @@
#if INCLUDE_COUNTERSIGNATURE
-COSE* CountersignRoot = NULL;
+COSE* CountersignRoot = nullptr;
bool IsValidCounterSignHandle(HCOSE_COUNTERSIGN h)
{
@@ -39,37 +39,37 @@
COSE_CounterSign* pobj = pIn;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj = (COSE_CounterSign*)COSE_CALLOC(
1, sizeof(COSE_CounterSign), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
}
CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
if (!_COSE_SignerInfo_Init_From_Object(
cbor, &pobj->m_signer, CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_SignerInfo_Release(&pobj->m_signer);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
- return NULL;
+ return nullptr;
}
- if (pIn == NULL) {
+ if (pIn == nullptr) {
_COSE_InsertInList(&CountersignRoot, &pobj->m_signer.m_message);
}
return pobj;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_CounterSign_Free(pobj);
}
- return NULL;
+ return nullptr;
}
bool _COSE_CounterSign_Init(COSE_CounterSign* pobject,
@@ -84,16 +84,16 @@
{
COSE_CounterSign* pobject =
(COSE_CounterSign*)COSE_CALLOC(1, sizeof(COSE_CounterSign), context);
- if (pobject == NULL) {
- if (perror != NULL) {
+ if (pobject == nullptr) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
if (!_COSE_CounterSign_Init(pobject, CBOR_CONTEXT_PARAM_COMMA perror)) {
_COSE_CounterSign_Free(pobject);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&CountersignRoot, &pobject->m_signer.m_message);
@@ -131,7 +131,7 @@
COSE_CounterSign* pSigner = (COSE_CounterSign*)hSigner;
CHECK_CONDITION(IsValidCounterSignHandle(hSigner), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pSigner->m_next == NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pSigner->m_next == nullptr, COSE_ERR_INVALID_PARAMETER);
pSigner->m_next = pMessage->m_counterSigners;
pMessage->m_counterSigners = pSigner;
@@ -155,46 +155,46 @@
cn_cbor* pcnBody,
CBOR_CONTEXT_COMMA cose_errback* perr)
{
- cn_cbor* pArray = NULL;
+ cn_cbor* pArray = nullptr;
cn_cbor_errback cbor_err;
- COSE_CounterSign* pSigner = NULL;
- cn_cbor* pcnProtected = NULL;
- cn_cbor* pcn = NULL;
- cn_cbor* pcn2 = NULL;
+ COSE_CounterSign* pSigner = nullptr;
+ cn_cbor* pcnProtected = nullptr;
+ cn_cbor* pcn = nullptr;
+ cn_cbor* pcn2 = nullptr;
- if (pMessage->m_counterSigners == NULL) {
+ if (pMessage->m_counterSigners == nullptr) {
return true;
}
// One or more than one?
- if (pMessage->m_counterSigners->m_signer.m_signerNext != NULL) {
+ if (pMessage->m_counterSigners->m_signer.m_signerNext != nullptr) {
pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pArray != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pArray != nullptr, cbor_err);
}
pcnProtected = _COSE_arrayget_int(pMessage, INDEX_PROTECTED);
- CHECK_CONDITION(pcnProtected != NULL, COSE_ERR_INTERNAL);
+ CHECK_CONDITION(pcnProtected != nullptr, COSE_ERR_INTERNAL);
- for (pSigner = pMessage->m_counterSigners; pSigner != NULL;
+ for (pSigner = pMessage->m_counterSigners; pSigner != nullptr;
pSigner = pSigner->m_next) {
CHECK_CONDITION(
- pSigner->m_signer.m_signerNext == NULL, COSE_ERR_INTERNAL);
+ pSigner->m_signer.m_signerNext == nullptr, COSE_ERR_INTERNAL);
pcn = cn_cbor_data_create(pcnProtected->v.bytes, pcnProtected->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pcnProtected != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pcnProtected != nullptr, cbor_err);
pcn2 = cn_cbor_clone(pcnBody, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pcnBody != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pcnBody != nullptr, cbor_err);
if (!_COSE_Signer_sign(
&pSigner->m_signer, pcnBody, pcn2, "CounterSignature", perr)) {
goto errorReturn;
}
- pcn = NULL;
- pcn2 = NULL;
+ pcn = nullptr;
+ pcn2 = nullptr;
- if (pArray != NULL) {
+ if (pArray != nullptr) {
bool f = cn_cbor_array_append(
pArray, pSigner->m_signer.m_message.m_cborRoot, &cbor_err);
CHECK_CONDITION_CBOR(f, cbor_err);
@@ -212,13 +212,13 @@
return true;
errorReturn:
- if (pArray != NULL) {
+ if (pArray != nullptr) {
CN_CBOR_FREE(pArray, context);
}
- if ((pcn != NULL) && (pcn->parent != NULL)) {
+ if ((pcn != nullptr) && (pcn->parent != nullptr)) {
CN_CBOR_FREE(pcn, context);
}
- if ((pcn2 != NULL) && (pcn2->parent != NULL)) {
+ if ((pcn2 != nullptr) && (pcn2->parent != nullptr)) {
CN_CBOR_FREE(pcn2, context);
}
return false;
@@ -230,19 +230,19 @@
cose_errback* perr)
{
bool fRet = false;
- HCOSE_KEY coseKey = NULL;
+ HCOSE_KEY coseKey = nullptr;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context* context = NULL;
+ cn_cbor_context* context = nullptr;
#endif
- CHECK_CONDITION(pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
coseKey = COSE_KEY_FromCbor((cn_cbor*) pkey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(coseKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(coseKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
fRet = COSE_CounterSign_SetKey2(h, coseKey, perr);
errorReturn:
- if (coseKey != NULL) {
+ if (coseKey != nullptr) {
COSE_KEY_Free(coseKey);
}
return fRet;
@@ -257,12 +257,12 @@
CHECK_CONDITION(IsValidCounterSignHandle(hSigner), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(IsValidKeyHandle(hKey), COSE_ERR_INVALID_HANDLE);
- if (pSigner->m_signer.m_pkey != NULL) {
+ if (pSigner->m_signer.m_pkey != nullptr) {
COSE_KEY_Free((HCOSE_KEY) pSigner->m_signer.m_pkey);
}
pSigner->m_signer.m_pkey = pKey;
- if (hKey != NULL) {
+ if (hKey != nullptr) {
pKey->m_refCount += 1;
}
fRet = true;
@@ -277,11 +277,11 @@
{
COSE_CounterSign* pCounterSign = pMessage->m_counterSigners;
CHECK_CONDITION(
- pMessage->m_counterSigners != NULL, COSE_ERR_INVALID_PARAMETER);
+ pMessage->m_counterSigners != nullptr, COSE_ERR_INVALID_PARAMETER);
for (int i = 0; i < index; i++) {
pCounterSign = pCounterSign->m_next;
- CHECK_CONDITION(pCounterSign != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pCounterSign != nullptr, COSE_ERR_INVALID_PARAMETER);
}
pCounterSign->m_signer.m_message.m_refCount += 1;
@@ -289,7 +289,7 @@
return pCounterSign;
errorReturn:
- return NULL;
+ return nullptr;
}
bool COSE_CounterSign_map_put_int(HCOSE_COUNTERSIGN h,
@@ -299,7 +299,7 @@
cose_errback* perr)
{
CHECK_CONDITION(IsValidCounterSignHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_map_put(
&((COSE_CounterSign*)h)->m_signer.m_message, key, value, flags, perr);
@@ -330,7 +330,7 @@
cose_errback* perr)
{
if (!IsValidCounterSignHandle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
return false;
@@ -344,16 +344,16 @@
CBOR_CONTEXT_COMMA cose_errback* perr)
{
bool fRet = false;
- cn_cbor* pcborProtectedSign = NULL;
+ cn_cbor* pcborProtectedSign = nullptr;
cn_cbor* pSignature = _COSE_arrayget_int(baseMessage, INDEX_SIGNATURE);
int count = 0;
COSE_CounterSign* pCountersign = baseMessage->m_counterSigners;
- for (; pCountersign != NULL;
+ for (; pCountersign != nullptr;
pCountersign = pCountersign->m_next, count += 1) {
pcborProtectedSign = _COSE_encode_protected(baseMessage, perr);
- if (pcborProtectedSign == NULL) {
+ if (pcborProtectedSign == nullptr) {
goto errorReturn;
}
if (!_COSE_Signer_sign(&pCountersign->m_signer, pSignature,
@@ -374,7 +374,7 @@
cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cn_error);
CHECK_CONDITION_CBOR(cn_counterSign, cn_error);
- for (pCountersign = baseMessage->m_counterSigners; pCountersign != NULL;
+ for (pCountersign = baseMessage->m_counterSigners; pCountersign != nullptr;
pCountersign = pCountersign->m_next) {
cn_cbor* cn = COSE_get_cbor((HCOSE)pCountersign);
CHECK_CONDITION_CBOR(
@@ -399,7 +399,7 @@
* @param[in] key Key to look for
* @param[in] flags What buckets should we look for the message
* @param[out] perror Location to return error codes
- * @return Object which is found or NULL
+ * @return Object which is found or nullptr
*/
cn_cbor* COSE_CounterSign_map_get_int(HCOSE_COUNTERSIGN h,
@@ -408,10 +408,10 @@
cose_errback* perror)
{
if (!IsValidCounterSignHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -439,14 +439,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Signer_get_countersignature(HCOSE_SIGNER hSigner,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidSignerHandle(hSigner), COSE_ERR_INVALID_HANDLE);
@@ -475,12 +475,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSigner->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSigner->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -510,14 +510,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Sign_get_countersignature(HCOSE_SIGN hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidSignHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -546,12 +546,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -583,14 +583,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Sign1_get_countersignature(HCOSE_SIGN1 hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidSign1Handle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -619,12 +619,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -655,14 +655,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Enveloped_get_countersignature(HCOSE_ENVELOPED hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidEnvelopedHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -690,12 +690,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -727,14 +727,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Recipient_get_countersignature(HCOSE_RECIPIENT hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidRecipientHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -763,12 +763,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_encrypt.m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_encrypt.m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -799,14 +799,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Encrypt0_get_countersignature(HCOSE_ENCRYPT hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidEncryptHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -835,12 +835,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -871,14 +871,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Mac0_get_countersignature(HCOSE_MAC0 hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidMac0Handle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -907,12 +907,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
@@ -943,14 +943,14 @@
return hCountersign;
errorReturn:
- return NULL;
+ return nullptr;
}
HCOSE_COUNTERSIGN COSE_Mac_get_countersignature(HCOSE_MAC hSignMsg,
int index,
cose_errback* perr)
{
- COSE_CounterSign* p = NULL;
+ COSE_CounterSign* p = nullptr;
CHECK_CONDITION(IsValidMacHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
@@ -979,12 +979,12 @@
const cn_cbor* cnContent =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
const cn_cbor* cnProtected =
_COSE_arrayget_int(&pSignMsg->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
bool f = _COSE_Signer_validate(&pCountersign->m_signer, cnContent,
diff --git a/src/CounterSign0.cpp b/src/CounterSign0.cpp
index 479e435..174d181 100644
--- a/src/CounterSign0.cpp
+++ b/src/CounterSign0.cpp
@@ -41,43 +41,43 @@
cn_cbor* pcnBody,
CBOR_CONTEXT_COMMA cose_errback* perr)
{
- cn_cbor* pArray = NULL;
+ cn_cbor* pArray = nullptr;
cn_cbor_errback cbor_err;
- COSE_CounterSign1* pSigner = NULL;
- cn_cbor* pcnProtected = NULL;
- cn_cbor* pcn = NULL;
- cn_cbor* pcn2 = NULL;
+ COSE_CounterSign1* pSigner = nullptr;
+ cn_cbor* pcnProtected = nullptr;
+ cn_cbor* pcn = nullptr;
+ cn_cbor* pcn2 = nullptr;
- if (pMessage->m_counterSigners == NULL)
+ if (pMessage->m_counterSigners == nullptr)
return true;
// One or more than one?
- if (pMessage->m_counterSigners->m_signer.m_signerNext != NULL) {
+ if (pMessage->m_counterSigners->m_signer.m_signerNext != nullptr) {
pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pArray != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pArray != nullptr, cbor_err);
}
pcnProtected = _COSE_arrayget_int(pMessage, INDEX_PROTECTED);
- CHECK_CONDITION(pcnProtected != NULL, COSE_ERR_INTERNAL);
+ CHECK_CONDITION(pcnProtected != nullptr, COSE_ERR_INTERNAL);
- for (pSigner = pMessage->m_counterSigners; pSigner != NULL;
+ for (pSigner = pMessage->m_counterSigners; pSigner != nullptr;
pSigner = pSigner->m_next) {
CHECK_CONDITION(
- pSigner->m_signer.m_signerNext == NULL, COSE_ERR_INTERNAL);
+ pSigner->m_signer.m_signerNext == nullptr, COSE_ERR_INTERNAL);
pcn = cn_cbor_data_create(pcnProtected->v.bytes, pcnProtected->v.count,
CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pcnProtected != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pcnProtected != nullptr, cbor_err);
pcn2 = cn_cbor_clone(pcnBody, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(pcnBody != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(pcnBody != nullptr, cbor_err);
if (!_COSE_Signer_sign(&pSigner->m_signer, pcnBody, pcn2, perr))
goto errorReturn;
- pcn = NULL;
- pcn2 = NULL;
+ pcn = nullptr;
+ pcn2 = nullptr;
- if (pArray != NULL) {
+ if (pArray != nullptr) {
bool f = cn_cbor_array_append(
pArray, pSigner->m_signer.m_message.m_cborRoot, &cbor_err);
CHECK_CONDITION_CBOR(f, cbor_err);
@@ -94,11 +94,11 @@
return true;
errorReturn:
- if (pArray != NULL)
+ if (pArray != nullptr)
CN_CBOR_FREE(pArray, context);
- if ((pcn != NULL) && (pcn->parent != NULL))
+ if ((pcn != nullptr) && (pcn->parent != nullptr))
CN_CBOR_FREE(pcn, context);
- if ((pcn2 != NULL) && (pcn2->parent != NULL))
+ if ((pcn2 != nullptr) && (pcn2->parent != nullptr))
CN_CBOR_FREE(pcn2, context);
return false;
}
diff --git a/src/Encrypt.cpp b/src/Encrypt.cpp
index 0872826..79ef464 100644
--- a/src/Encrypt.cpp
+++ b/src/Encrypt.cpp
@@ -19,7 +19,7 @@
#include "cose_crypto.h"
#if INCLUDE_ENCRYPT || INCLUDE_MAC
-COSE *EnvelopedRoot = NULL;
+COSE *EnvelopedRoot = nullptr;
#endif
#if INCLUDE_ENCRYPT
@@ -66,13 +66,13 @@
{
COSE_Enveloped *pobj =
(COSE_Enveloped *)COSE_CALLOC(1, sizeof(COSE_Enveloped), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(flags, &pobj->m_message, COSE_enveloped_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_Enveloped_Release(pobj);
COSE_FREE(pobj, context);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&EnvelopedRoot, &pobj->m_message);
@@ -80,7 +80,7 @@
return (HCOSE_ENVELOPED)pobj;
errorReturn:
- return NULL;
+ return nullptr;
}
#endif
@@ -90,24 +90,24 @@
CBOR_CONTEXT_COMMA cose_errback *perr)
{
COSE_Enveloped *pobj = pIn;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj =
(COSE_Enveloped *)COSE_CALLOC(1, sizeof(COSE_Enveloped), context);
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
errorReturn:
- if (pIn == NULL && pobj != NULL) {
+ if (pIn == nullptr && pobj != nullptr) {
_COSE_Enveloped_Release(pobj);
COSE_FREE(pobj, context);
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init_From_Object(
@@ -116,15 +116,15 @@
}
pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_RECIPIENTS);
- if (pRecipients != NULL) {
+ if (pRecipients != nullptr) {
CHECK_CONDITION(
pRecipients->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
pRecipients = pRecipients->first_child;
- while (pRecipients != NULL) {
+ while (pRecipients != nullptr) {
COSE_RecipientInfo *pInfo = _COSE_Recipient_Init_From_Object(
pRecipients, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(pInfo != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pInfo != nullptr, COSE_ERR_OUT_OF_MEMORY);
pInfo->m_recipientNext = pobj->m_recipientFirst;
pobj->m_recipientFirst = pInfo;
@@ -132,7 +132,7 @@
}
}
- if (pIn == NULL) {
+ if (pIn == nullptr) {
_COSE_InsertInList(&EnvelopedRoot, &pobj->m_message);
}
@@ -177,12 +177,12 @@
COSE_RecipientInfo *pRecipient1;
COSE_RecipientInfo *pRecipient2;
- if (p->pbContent != NULL) {
+ if (p->pbContent != nullptr) {
COSE_FREE((void *)p->pbContent, &p->m_message.m_allocContext);
}
- // if (p->pbIV != NULL) COSE_FREE(p->pbIV, &p->m_message.m_allocContext);
+ // if (p->pbIV != nullptr) COSE_FREE(p->pbIV, &p->m_message.m_allocContext);
- for (pRecipient1 = p->m_recipientFirst; pRecipient1 != NULL;
+ for (pRecipient1 = p->m_recipientFirst; pRecipient1 != nullptr;
pRecipient1 = pRecipient2) {
pRecipient2 = pRecipient1->m_recipientNext;
COSE_Recipient_Free((HCOSE_RECIPIENT)pRecipient1);
@@ -204,9 +204,9 @@
CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(IsValidRecipientHandle(hRecip), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
- pcose->m_recipientFirst != NULL, COSE_ERR_INVALID_PARAMETER);
+ pcose->m_recipientFirst != nullptr, COSE_ERR_INVALID_PARAMETER);
- f = _COSE_Enveloped_decrypt(pcose, pRecip, NULL, 0, "Encrypt", perr);
+ f = _COSE_Enveloped_decrypt(pcose, pRecip, nullptr, 0, "Encrypt", perr);
errorReturn:
return f;
@@ -222,14 +222,14 @@
cose_errback *perr)
{
int alg;
- const cn_cbor *cn = NULL;
- byte *pbKeyNew = NULL;
- const byte *pbKey = NULL;
+ const cn_cbor *cn = nullptr;
+ byte *pbKeyNew = nullptr;
+ const byte *pbKey = nullptr;
size_t cbitKey = 0;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context;
#endif
- byte *pbAuthData = NULL;
+ byte *pbAuthData = nullptr;
size_t cbAuthData;
#ifdef USE_CBOR_CONTEXT
@@ -237,17 +237,17 @@
#endif
CHECK_CONDITION(
- !((pRecip != NULL) && (pbKeyIn != NULL)), COSE_ERR_INTERNAL);
+ !((pRecip != nullptr) && (pbKeyIn != nullptr)), COSE_ERR_INTERNAL);
cn = _COSE_map_get_int(
&pcose->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
error:
errorReturn:
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (pbKeyNew != NULL) {
+ if (pbKeyNew != nullptr) {
memset(pbKeyNew, 0xff, cbitKey / 8);
COSE_FREE(pbKeyNew, context);
}
@@ -333,7 +333,7 @@
// We are doing the enveloped item - so look for the passed in recipient
//
- if (pbKeyIn != NULL) {
+ if (pbKeyIn != nullptr) {
CHECK_CONDITION(cbKeyIn == cbitKey / 8, COSE_ERR_INVALID_PARAMETER);
pbKey = pbKeyIn;
}
@@ -341,20 +341,20 @@
else {
// Allocate the key if we have not already done so
- if (pbKeyNew == NULL) {
+ if (pbKeyNew == nullptr) {
pbKeyNew = static_cast<byte*>(COSE_CALLOC(cbitKey / 8, 1, context));
- CHECK_CONDITION(pbKeyNew != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyNew != nullptr, COSE_ERR_OUT_OF_MEMORY);
pbKey = pbKeyNew;
}
// If there is a recipient - ask it for the key
- if (pRecip != NULL) {
- COSE_RecipientInfo *pRecipX = NULL;
+ if (pRecip != nullptr) {
+ COSE_RecipientInfo *pRecipX = nullptr;
cose_errback errorLocal = {COSE_ERR_NONE};
cose_error errorFound = COSE_ERR_NONE;
- for (pRecipX = pcose->m_recipientFirst; pRecipX != NULL;
+ for (pRecipX = pcose->m_recipientFirst; pRecipX != nullptr;
pRecipX = pRecipX->m_recipientNext) {
if (pRecipX == pRecip) {
if (!_COSE_Recipient_decrypt(
@@ -363,7 +363,7 @@
}
break;
}
- else if (pRecipX->m_encrypt.m_recipientFirst != NULL) {
+ else if (pRecipX->m_encrypt.m_recipientFirst != nullptr) {
if (_COSE_Recipient_decrypt(pRecipX, pRecip, alg, cbitKey,
pbKeyNew, &errorLocal)) {
break;
@@ -375,17 +375,17 @@
perr->err = errorFound;
goto errorReturn;
}
- CHECK_CONDITION(pRecipX != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(pRecipX != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
}
else {
- for (pRecip = pcose->m_recipientFirst; pRecip != NULL;
+ for (pRecip = pcose->m_recipientFirst; pRecip != nullptr;
pRecip = pRecip->m_recipientNext) {
if (_COSE_Recipient_decrypt(
- pRecip, NULL, alg, cbitKey, pbKeyNew, perr)) {
+ pRecip, nullptr, alg, cbitKey, pbKeyNew, perr)) {
break;
}
}
- CHECK_CONDITION(pRecip != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(pRecip != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
}
}
#endif // INCLUDE_ENCRYPT
@@ -398,7 +398,7 @@
}
cn = _COSE_arrayget_int(&pcose->m_message, INDEX_BODY);
- CHECK_CONDITION(cn != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_INVALID_PARAMETER);
switch (alg) {
#ifdef USE_AES_CCM_16_64_128
@@ -505,13 +505,13 @@
break;
}
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (pbKeyNew != NULL) {
+ if (pbKeyNew != nullptr) {
COSE_FREE(pbKeyNew, context);
}
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_NONE;
}
@@ -525,9 +525,9 @@
COSE_Enveloped *pcose = (COSE_Enveloped *)h;
CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pcose->m_recipientFirst != NULL, COSE_ERR_INVALID_HANDLE);
+ CHECK_CONDITION(pcose->m_recipientFirst != nullptr, COSE_ERR_INVALID_HANDLE);
- return _COSE_Enveloped_encrypt(pcose, NULL, 0, "Encrypt", perr);
+ return _COSE_Enveloped_encrypt(pcose, nullptr, 0, "Encrypt", perr);
errorReturn:
return false;
@@ -544,25 +544,25 @@
int alg;
int t;
COSE_RecipientInfo *pri;
- const cn_cbor *cn_Alg = NULL;
- byte *pbAuthData = NULL;
+ const cn_cbor *cn_Alg = nullptr;
+ byte *pbAuthData = nullptr;
size_t cbitKey;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
bool fRet = false;
- byte *pbKeyNew = NULL;
- const byte *pbKey = NULL;
+ byte *pbKeyNew = nullptr;
+ const byte *pbKey = nullptr;
size_t cbKey = 0;
cn_Alg = _COSE_map_get_int(
&pcose->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn_Alg == NULL) {
+ if (cn_Alg == nullptr) {
errorReturn:
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (pbKeyNew != NULL) {
+ if (pbKeyNew != nullptr) {
memset(pbKeyNew, 0, cbKey);
COSE_FREE(pbKeyNew, context);
}
@@ -650,7 +650,7 @@
// Enveloped or Encrypted?
- if (pbKeyIn != NULL) {
+ if (pbKeyIn != nullptr) {
CHECK_CONDITION(cbKeyIn == cbitKey / 8, COSE_ERR_INVALID_PARAMETER);
pbKey = pbKeyIn;
cbKey = cbKeyIn;
@@ -660,16 +660,16 @@
// If we are doing direct encryption - then recipient generates the key
t = 0;
- for (pri = pcose->m_recipientFirst; pri != NULL;
+ for (pri = pcose->m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (pri->m_encrypt.m_message.m_flags & 1) {
- CHECK_CONDITION(pbKey == NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKey == nullptr, COSE_ERR_INVALID_PARAMETER);
t |= 1;
pbKeyNew =
_COSE_RecipientInfo_generateKey(pri, alg, cbitKey, perr);
cbKey = cbitKey / 8;
- if (pbKeyNew == NULL) {
+ if (pbKeyNew == nullptr) {
goto errorReturn;
}
}
@@ -681,7 +681,7 @@
if (t == 2) {
pbKeyNew = (byte *)COSE_CALLOC(cbitKey / 8, 1, context);
- CHECK_CONDITION(pbKeyNew != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyNew != nullptr, COSE_ERR_OUT_OF_MEMORY);
cbKey = cbitKey / 8;
rand_bytes(pbKeyNew, cbKey);
}
@@ -693,7 +693,7 @@
const cn_cbor *cbProtected =
_COSE_encode_protected(&pcose->m_message, perr);
- if (cbProtected == NULL) {
+ if (cbProtected == nullptr) {
goto errorReturn;
}
@@ -810,7 +810,7 @@
}
#if INCLUDE_ENCRYPT
- for (pri = pcose->m_recipientFirst; pri != NULL;
+ for (pri = pcose->m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (!_COSE_Recipient_encrypt(pri, pbKey, cbKey, perr)) {
goto errorReturn;
@@ -819,7 +819,7 @@
#endif // INCLUDE_ENCRYPT
#if INCLUDE_COUNTERSIGNATURE
- if (pcose->m_message.m_counterSigners != NULL) {
+ if (pcose->m_message.m_counterSigners != nullptr) {
if (!_COSE_CounterSign_Sign(
&pcose->m_message, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
@@ -841,7 +841,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(rgb != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(rgb != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_Enveloped_SetContent((COSE_Enveloped *)h, rgb, cb, perr);
@@ -871,7 +871,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidEnvelopedHandle(hcose), COSE_ERR_INVALID_HANDLE)
- CHECK_CONDITION((pbExternalData != NULL) || (cbExternalData == 0),
+ CHECK_CONDITION((pbExternalData != nullptr) || (cbExternalData == 0),
COSE_ERR_INVALID_PARAMETER);
return _COSE_SetExternal(&((COSE_Enveloped *)hcose)->m_message,
@@ -889,8 +889,8 @@
byte *pb;
cose->pbContent = pb =
(byte *)COSE_CALLOC(cb, 1, &cose->m_message.m_allocContext);
- if (cose->pbContent == NULL) {
- if (perror != NULL) {
+ if (cose->pbContent == nullptr) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -910,7 +910,7 @@
* @param[in] key Key to look for
* @param[in] flags What buckets should we look for the message
* @param[out] perror Location to return error codes
- * @return Object which is found or NULL
+ * @return Object which is found or nullptr
*/
cn_cbor *COSE_Enveloped_map_get_int(HCOSE_ENVELOPED h,
@@ -919,10 +919,10 @@
cose_errback *perror)
{
if (!IsValidEnvelopedHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -936,7 +936,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidEnvelopedHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_map_put(
&((COSE_Enveloped *)h)->m_message, key, value, flags, perr);
@@ -951,7 +951,7 @@
{
COSE_RecipientInfo *pRecip;
COSE_Enveloped *pEncrypt;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context;
#endif
@@ -972,15 +972,15 @@
pRecip->m_encrypt.m_message.m_refCount++;
pRecipients = _COSE_arrayget_int(&pEncrypt->m_message, INDEX_RECIPIENTS);
- if (pRecipients == NULL) {
+ if (pRecipients == nullptr) {
pRecipients =
cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pRecipients != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pRecipients != nullptr, cbor_error);
if (!_COSE_array_replace(&pEncrypt->m_message, pRecipients,
INDEX_RECIPIENTS, CBOR_CONTEXT_PARAM_COMMA & cbor_error)) {
CN_CBOR_FREE(pRecipients, context);
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = _MapFromCBOR(cbor_error);
}
goto errorReturn;
@@ -1009,48 +1009,48 @@
cn_cbor_context *context = &pMessage->m_allocContext;
#endif
cn_cbor_errback cbor_error;
- byte *pbAuthData = NULL;
+ byte *pbAuthData = nullptr;
size_t cbAuthData;
- cn_cbor *pAuthData = NULL;
- cn_cbor *pItem = NULL;
- cn_cbor *ptmp = NULL;
+ cn_cbor *pAuthData = nullptr;
+ cn_cbor *pItem = nullptr;
+ cn_cbor *ptmp = nullptr;
// Build authenticated data
pAuthData = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pAuthData != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pAuthData != nullptr, cbor_error);
ptmp =
cn_cbor_string_create(szContext, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
pItem = _COSE_arrayget_int(pMessage, INDEX_PROTECTED);
- CHECK_CONDITION(pItem != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pItem != nullptr, COSE_ERR_INVALID_PARAMETER);
if ((pItem->length == 1) && (pItem->v.bytes[0] == 0xa0)) {
ptmp =
- cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
+ cn_cbor_data_create(nullptr, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
ptmp = cn_cbor_data_create(pItem->v.bytes, (int)pItem->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
ptmp = cn_cbor_data_create(pMessage->m_pbExternal,
(int)pMessage->m_cbExternal, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
cbAuthData = cn_cbor_encode_size(pAuthData);
pbAuthData = (byte *)COSE_CALLOC(cbAuthData, 1, context);
- CHECK_CONDITION(pbAuthData != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbAuthData != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION((size_t)cn_cbor_encoder_write(
pbAuthData, 0, cbAuthData, pAuthData) == cbAuthData,
COSE_ERR_CBOR);
@@ -1069,20 +1069,20 @@
}
#endif
- if (pAuthData != NULL) {
+ if (pAuthData != nullptr) {
CN_CBOR_FREE(pAuthData, context);
}
return true;
errorReturn:
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (ptmp != NULL) {
- CN_CBOR_FREE(ptmp, NULL);
+ if (ptmp != nullptr) {
+ CN_CBOR_FREE(ptmp, nullptr);
}
- if (pAuthData != NULL) {
+ if (pAuthData != nullptr) {
CN_CBOR_FREE(pAuthData, context);
}
return false;
@@ -1095,17 +1095,17 @@
cose_errback *perr)
{
int i;
- COSE_RecipientInfo *p = NULL;
+ COSE_RecipientInfo *p = nullptr;
CHECK_CONDITION(IsValidEnvelopedHandle(cose), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(iRecipient >= 0, COSE_ERR_INVALID_PARAMETER);
p = ((COSE_Enveloped *)cose)->m_recipientFirst;
for (i = 0; i < iRecipient; i++) {
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
p = p->m_recipientNext;
}
- if (p != NULL) {
+ if (p != nullptr) {
p->m_encrypt.m_message.m_refCount++;
}
diff --git a/src/Encrypt0.cpp b/src/Encrypt0.cpp
index 4c901d3..604aafd 100644
--- a/src/Encrypt0.cpp
+++ b/src/Encrypt0.cpp
@@ -19,7 +19,7 @@
#if INCLUDE_ENCRYPT0 || INCLUDE_MAC0
-COSE *EncryptRoot = NULL;
+COSE *EncryptRoot = nullptr;
#endif
#if INCLUDE_ENCRYPT0
@@ -50,19 +50,19 @@
{
if (false) {
errorReturn:
- return NULL;
+ return nullptr;
}
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
COSE_Encrypt *pobj =
(COSE_Encrypt *)COSE_CALLOC(1, sizeof(COSE_Encrypt), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(flags, &pobj->m_message, COSE_enveloped_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_Encrypt_Release(pobj);
COSE_FREE(pobj, context);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&EncryptRoot, &pobj->m_message);
@@ -78,19 +78,19 @@
COSE_Encrypt *pobj;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
pobj = (COSE_Encrypt *)COSE_CALLOC(1, sizeof(COSE_Encrypt), context);
- if (pobj == NULL) {
+ if (pobj == nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Encrypt_Release(pobj);
COSE_FREE(pobj, context);
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init_From_Object(
@@ -110,25 +110,25 @@
CBOR_CONTEXT_COMMA cose_errback *perr)
{
COSE_Encrypt *pobj = pIn;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj = (COSE_Encrypt *)COSE_CALLOC(1, sizeof(COSE_Encrypt), context);
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Encrypt_Release(pobj);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init_From_Object(
@@ -137,7 +137,7 @@
}
pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_RECIPIENTS);
- CHECK_CONDITION(pRecipients == NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pRecipients == nullptr, COSE_ERR_INVALID_PARAMETER);
_COSE_InsertInList(&EncryptRoot, &pobj->m_message);
@@ -172,7 +172,7 @@
#if INCLUDE_ENCRYPT0 || INCLUDE_MAC0
void _COSE_Encrypt_Release(COSE_Encrypt *p)
{
- if (p->pbContent != NULL) {
+ if (p->pbContent != nullptr) {
COSE_FREE((void *)p->pbContent, &p->m_message.m_allocContext);
}
@@ -190,13 +190,13 @@
bool f;
if (!IsValidEncryptHandle(h)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
}
- f = _COSE_Enveloped_decrypt(pcose, NULL, pbKey, cbKey, "Encrypt0", perr);
+ f = _COSE_Enveloped_decrypt(pcose, nullptr, pbKey, cbKey, "Encrypt0", perr);
return f;
}
@@ -206,7 +206,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidEncryptHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pbKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKey != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_Enveloped_encrypt(
(COSE_Encrypt *)h, pbKey, cbKey, "Encrypt0", perr);
@@ -220,11 +220,11 @@
cose_errback *perror)
{
COSE_Encrypt *cose = (COSE_Encrypt *)h;
- if (!IsValidEncryptHandle(h) || (pcbContent == NULL)) {
- if (perror != NULL) {
+ if (!IsValidEncryptHandle(h) || (pcbContent == nullptr)) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
- return NULL;
+ return nullptr;
}
*pcbContent = cose->cbContent;
@@ -236,8 +236,8 @@
size_t cb,
cose_errback *perror)
{
- if (!IsValidEncryptHandle(h) || (rgb == NULL)) {
- if (perror != NULL) {
+ if (!IsValidEncryptHandle(h) || (rgb == nullptr)) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -254,8 +254,8 @@
byte *pb;
cose->pbContent = pb =
(byte *)COSE_CALLOC(cb, 1, &cose->m_message.m_allocContext);
- if (cose->pbContent == NULL) {
- if (perror != NULL) {
+ if (cose->pbContent == nullptr) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -288,7 +288,7 @@
cose_errback *perr)
{
if (!IsValidEncryptHandle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -304,10 +304,10 @@
cose_errback *perror)
{
if (!IsValidEncryptHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -320,8 +320,8 @@
int flags,
cose_errback *perror)
{
- if (!IsValidEncryptHandle(h) || (value == NULL)) {
- if (perror != NULL) {
+ if (!IsValidEncryptHandle(h) || (value == nullptr)) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
diff --git a/src/MacMessage.cpp b/src/MacMessage.cpp
index 7bff626..304b665 100644
--- a/src/MacMessage.cpp
+++ b/src/MacMessage.cpp
@@ -17,7 +17,7 @@
#if INCLUDE_MAC
-COSE *MacRoot = NULL;
+COSE *MacRoot = nullptr;
/*! \private
* @brief Test if a HCOSE_MAC handle is valid
@@ -42,12 +42,12 @@
HCOSE_MAC COSE_Mac_Init(COSE_INIT_FLAGS flags,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- COSE_MacMessage *pobj = NULL;
+ COSE_MacMessage *pobj = nullptr;
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
pobj = (COSE_MacMessage *)COSE_CALLOC(1, sizeof(COSE_MacMessage), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(flags, &pobj->m_message, COSE_mac_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
@@ -59,11 +59,11 @@
return (HCOSE_MAC)pobj;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Mac_Release(pobj);
COSE_FREE(pobj, context);
}
- return NULL;
+ return nullptr;
}
HCOSE_MAC _COSE_Mac_Init_From_Object(cn_cbor *cbor,
@@ -71,27 +71,27 @@
CBOR_CONTEXT_COMMA cose_errback *perr)
{
COSE_MacMessage *pobj = pIn;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
// cn_cbor * tmp;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj =
(COSE_MacMessage *)COSE_CALLOC(1, sizeof(COSE_MacMessage), context);
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Mac_Release(pobj);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init_From_Object(
@@ -100,15 +100,15 @@
}
pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_MAC_RECIPIENTS);
- if (pRecipients != NULL) {
+ if (pRecipients != nullptr) {
CHECK_CONDITION(
pRecipients->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
pRecipients = pRecipients->first_child;
- while (pRecipients != NULL) {
+ while (pRecipients != nullptr) {
COSE_RecipientInfo *pInfo = _COSE_Recipient_Init_From_Object(
pRecipients, CBOR_CONTEXT_PARAM_COMMA perr);
- if (pInfo == NULL) {
+ if (pInfo == nullptr) {
goto errorReturn;
}
@@ -157,7 +157,7 @@
COSE_RecipientInfo *pRecipient;
COSE_RecipientInfo *pRecipient2;
- for (pRecipient = p->m_recipientFirst; pRecipient != NULL;
+ for (pRecipient = p->m_recipientFirst; pRecipient != nullptr;
pRecipient = pRecipient2) {
pRecipient2 = pRecipient->m_recipientNext;
COSE_Recipient_Free((HCOSE_RECIPIENT)pRecipient);
@@ -177,24 +177,24 @@
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &p->m_message.m_allocContext;
#endif
- cn_cbor *ptmp = NULL;
+ cn_cbor *ptmp = nullptr;
cn_cbor_errback cbor_error;
CHECK_CONDITION(IsValidMacHandle(cose), COSE_ERR_INVALID_PARAMETER);
ptmp = cn_cbor_data_create(
rgbContent, (int)cbContent, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(_COSE_array_replace(&p->m_message, ptmp, INDEX_BODY,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
return true;
errorReturn:
- if (ptmp != NULL) {
+ if (ptmp != nullptr) {
CN_CBOR_FREE(ptmp, context);
}
return false;
@@ -222,7 +222,7 @@
cose_errback *perr)
{
if (!IsValidMacHandle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -238,10 +238,10 @@
cose_errback *perror)
{
if (!IsValidMacHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -254,8 +254,8 @@
int flags,
cose_errback *perror)
{
- if (!IsValidMacHandle(h) || (value == NULL)) {
- if (perror != NULL) {
+ if (!IsValidMacHandle(h) || (value == nullptr)) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -273,89 +273,89 @@
size_t *pcbAuthData,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- cn_cbor *pAuthData = NULL;
+ cn_cbor *pAuthData = nullptr;
bool fRet = false;
cn_cbor_errback cbor_error;
- cn_cbor *ptmp = NULL;
+ cn_cbor *ptmp = nullptr;
cn_cbor *pcn;
size_t cbAuthData;
- byte *pbAuthData = NULL;
+ byte *pbAuthData = nullptr;
// Build authenticated data
// Protected headers
// external data
// body
- pAuthData = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(pAuthData != NULL, COSE_ERR_OUT_OF_MEMORY);
+ pAuthData = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(pAuthData != nullptr, COSE_ERR_OUT_OF_MEMORY);
// Add the context string
ptmp =
cn_cbor_string_create(szContext, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
// Add the protected attributes
pcn = _COSE_arrayget_int(pCose, INDEX_PROTECTED);
- CHECK_CONDITION((pcn != NULL) && (pcn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((pcn != nullptr) && (pcn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
if ((pcn->length == 1) && (pcn->v.bytes[0] == 0xa0)) {
- ptmp = cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
+ ptmp = cn_cbor_data_create(nullptr, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
}
else {
ptmp = cn_cbor_data_create(
- pcn->v.bytes, (int)pcn->length, CBOR_CONTEXT_PARAM_COMMA NULL);
+ pcn->v.bytes, (int)pcn->length, CBOR_CONTEXT_PARAM_COMMA nullptr);
}
- CHECK_CONDITION(ptmp != NULL, COSE_ERR_CBOR);
+ CHECK_CONDITION(ptmp != nullptr, COSE_ERR_CBOR);
- CHECK_CONDITION(cn_cbor_array_append(pAuthData, ptmp, NULL), COSE_ERR_CBOR);
- ptmp = NULL;
+ CHECK_CONDITION(cn_cbor_array_append(pAuthData, ptmp, nullptr), COSE_ERR_CBOR);
+ ptmp = nullptr;
// Add the external bytes
ptmp = cn_cbor_data_create(pCose->m_pbExternal, (int)pCose->m_cbExternal,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
// Add the content
pcn = _COSE_arrayget_int(pCose, INDEX_BODY);
ptmp = cn_cbor_data_create(
pcn->v.bytes, (int)pcn->length, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pAuthData, ptmp, &cbor_error), cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
// Turn it into bytes
cbAuthData = cn_cbor_encode_size(pAuthData);
CHECK_CONDITION(cbAuthData > 0, COSE_ERR_CBOR);
pbAuthData = (byte *)COSE_CALLOC(cbAuthData, 1, context);
- CHECK_CONDITION(pbAuthData != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbAuthData != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(cn_cbor_encoder_write(pbAuthData, 0, cbAuthData,
pAuthData) == (ssize_t)cbAuthData,
COSE_ERR_CBOR);
*ppbAuthData = pbAuthData;
*pcbAuthData = cbAuthData;
- pbAuthData = NULL;
+ pbAuthData = nullptr;
fRet = true;
errorReturn:
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (pAuthData != NULL) {
+ if (pAuthData != nullptr) {
CN_CBOR_FREE(pAuthData, context);
}
- if (ptmp != NULL) {
+ if (ptmp != nullptr) {
CN_CBOR_FREE(ptmp, context);
}
return fRet;
@@ -369,9 +369,9 @@
CHECK_CONDITION(IsValidMacHandle(h), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
- pcose->m_recipientFirst != NULL, COSE_ERR_INVALID_PARAMETER);
+ pcose->m_recipientFirst != nullptr, COSE_ERR_INVALID_PARAMETER);
- return _COSE_Mac_compute(pcose, NULL, 0, "MAC", perr);
+ return _COSE_Mac_compute(pcose, nullptr, 0, "MAC", perr);
errorReturn:
return false;
@@ -388,25 +388,25 @@
int alg;
int t;
COSE_RecipientInfo *pri;
- const cn_cbor *cn_Alg = NULL;
- byte *pbAuthData = NULL;
+ const cn_cbor *cn_Alg = nullptr;
+ byte *pbAuthData = nullptr;
size_t cbitKey;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
bool fRet = false;
size_t cbAuthData = 0;
- const byte *pbKey = NULL;
- byte *pbKeyNew = NULL;
+ const byte *pbKey = nullptr;
+ byte *pbKeyNew = nullptr;
size_t cbKey = 0;
if (false) {
errorReturn:
- if (pbKeyNew != NULL) {
+ if (pbKeyNew != nullptr) {
memset(pbKeyNew, 0, cbKey);
COSE_FREE(pbKeyNew, context);
}
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
return fRet;
@@ -414,7 +414,7 @@
cn_Alg = _COSE_map_get_int(
&pcose->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn_Alg == NULL) {
+ if (cn_Alg == nullptr) {
goto errorReturn;
}
CHECK_CONDITION(cn_Alg->type != CN_CBOR_TEXT, COSE_ERR_UNKNOWN_ALGORITHM);
@@ -481,23 +481,23 @@
// If we are doing direct encryption - then recipient generates the key
- if (pbKeyIn != NULL) {
+ if (pbKeyIn != nullptr) {
CHECK_CONDITION(cbKeyIn == cbitKey / 8, COSE_ERR_INVALID_PARAMETER);
pbKey = pbKeyIn;
cbKey = cbKeyIn;
}
else {
t = 0;
- for (pri = pcose->m_recipientFirst; pri != NULL;
+ for (pri = pcose->m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (pri->m_encrypt.m_message.m_flags & 1) {
- CHECK_CONDITION(pbKey == NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKey == nullptr, COSE_ERR_INVALID_PARAMETER);
t |= 1;
pbKeyNew =
_COSE_RecipientInfo_generateKey(pri, alg, cbitKey, perr);
cbKey = cbitKey / 8;
- CHECK_CONDITION(pbKeyNew != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyNew != nullptr, COSE_ERR_OUT_OF_MEMORY);
pbKey = pbKeyNew;
}
else {
@@ -508,7 +508,7 @@
if (t == 2) {
pbKeyNew = (byte *)COSE_CALLOC(cbitKey / 8, 1, context);
- CHECK_CONDITION(pbKeyNew != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyNew != nullptr, COSE_ERR_OUT_OF_MEMORY);
pbKey = pbKeyNew;
cbKey = cbitKey / 8;
rand_bytes(pbKeyNew, cbKey);
@@ -519,7 +519,7 @@
const cn_cbor *cbProtected =
_COSE_encode_protected(&pcose->m_message, perr);
- if (cbProtected == NULL) {
+ if (cbProtected == nullptr) {
goto errorReturn;
}
@@ -607,7 +607,7 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- for (pri = pcose->m_recipientFirst; pri != NULL;
+ for (pri = pcose->m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (!_COSE_Recipient_encrypt(pri, pbKey, cbKey, perr)) {
goto errorReturn;
@@ -615,7 +615,7 @@
}
#if INCLUDE_COUNTERSIGNATURE
- if (pcose->m_message.m_counterSigners != NULL) {
+ if (pcose->m_message.m_counterSigners != nullptr) {
if (!_COSE_CounterSign_Sign(
&pcose->m_message, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
@@ -635,7 +635,7 @@
{
cose_errback error;
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
@@ -645,7 +645,7 @@
CHECK_CONDITION(IsValidMacHandle(h) && IsValidRecipientHandle(hRecip),
COSE_ERR_INVALID_PARAMETER);
- return _COSE_Mac_validate(pcose, pRecip, NULL, 0, "MAC", perr);
+ return _COSE_Mac_validate(pcose, pRecip, nullptr, 0, "MAC", perr);
errorReturn:
return false;
@@ -660,25 +660,25 @@
const char *szContext,
cose_errback *perr)
{
- byte *pbAuthData = NULL;
+ byte *pbAuthData = nullptr;
size_t cbitKey = 0;
bool fRet = false;
int alg;
- const cn_cbor *cn = NULL;
- byte *pbKeyNew = NULL;
- const byte *pbKey = NULL;
+ const cn_cbor *cn = nullptr;
+ byte *pbKeyNew = nullptr;
+ const byte *pbKey = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
size_t cbAuthData;
CHECK_CONDITION(
- !((pRecip != NULL) && (pbKeyIn != NULL)), COSE_ERR_INTERNAL);
+ !((pRecip != nullptr) && (pbKeyIn != nullptr)), COSE_ERR_INTERNAL);
cn = _COSE_map_get_int(
&pcose->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
goto errorReturn;
}
@@ -747,23 +747,23 @@
// Allocate the key if we have not already done so
- if (pbKeyIn != NULL) {
+ if (pbKeyIn != nullptr) {
CHECK_CONDITION(cbitKey / 8 == cbKeyIn, COSE_ERR_INVALID_PARAMETER);
pbKey = pbKeyIn;
}
else {
- if (pbKeyNew == NULL) {
+ if (pbKeyNew == nullptr) {
pbKeyNew = static_cast<byte*>(COSE_CALLOC(cbitKey / 8, 1, context));
- CHECK_CONDITION(pbKeyNew != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyNew != nullptr, COSE_ERR_OUT_OF_MEMORY);
pbKey = pbKeyNew;
}
// If there is a recipient - ask it for the key
- if (pRecip != NULL) {
+ if (pRecip != nullptr) {
COSE_RecipientInfo *pRecipX;
- for (pRecipX = pcose->m_recipientFirst; pRecipX != NULL;
+ for (pRecipX = pcose->m_recipientFirst; pRecipX != nullptr;
pRecipX = pRecipX->m_recipientNext) {
if (pRecip == pRecipX) {
if (!_COSE_Recipient_decrypt(
@@ -772,24 +772,24 @@
}
break;
}
- else if (pRecipX->m_encrypt.m_recipientFirst != NULL) {
+ else if (pRecipX->m_encrypt.m_recipientFirst != nullptr) {
if (_COSE_Recipient_decrypt(
pRecipX, pRecip, alg, cbitKey, pbKeyNew, perr)) {
break;
}
}
}
- CHECK_CONDITION(pRecipX != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(pRecipX != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
}
else {
- for (pRecip = pcose->m_recipientFirst; pRecip != NULL;
+ for (pRecip = pcose->m_recipientFirst; pRecip != nullptr;
pRecip = pRecip->m_recipientNext) {
if (_COSE_Recipient_decrypt(
- pRecip, NULL, alg, cbitKey, pbKeyNew, perr)) {
+ pRecip, nullptr, alg, cbitKey, pbKeyNew, perr)) {
break;
}
}
- CHECK_CONDITION(pRecip != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(pRecip != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
}
}
@@ -881,12 +881,12 @@
fRet = true;
errorReturn:
- if (pbKeyNew != NULL) {
+ if (pbKeyNew != nullptr) {
memset(pbKeyNew, 0xff, cbitKey / 8);
COSE_FREE(pbKeyNew, context);
}
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
@@ -901,10 +901,10 @@
{
COSE_RecipientInfo *pRecip;
COSE_MacMessage *pMac;
- cn_cbor *pRecipients = NULL;
- cn_cbor *pRecipientsT = NULL;
+ cn_cbor *pRecipients = nullptr;
+ cn_cbor *pRecipientsT = nullptr;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
cn_cbor_errback cbor_error;
@@ -922,17 +922,17 @@
#endif // USE_CBOR_CONTEXT
pRecipients = _COSE_arrayget_int(&pMac->m_message, INDEX_MAC_RECIPIENTS);
- if (pRecipients == NULL) {
+ if (pRecipients == nullptr) {
pRecipientsT =
cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pRecipientsT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pRecipientsT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
_COSE_array_replace(&pMac->m_message, pRecipientsT,
INDEX_MAC_RECIPIENTS, CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
pRecipients = pRecipientsT;
- pRecipientsT = NULL;
+ pRecipientsT = nullptr;
}
CHECK_CONDITION_CBOR(cn_cbor_array_append(pRecipients,
@@ -943,7 +943,7 @@
return true;
errorReturn:
- if (pRecipientsT == NULL) {
+ if (pRecipientsT == nullptr) {
CN_CBOR_FREE(pRecipientsT, context);
}
return false;
@@ -960,16 +960,16 @@
p = ((COSE_MacMessage *)cose)->m_recipientFirst;
for (i = 0; i < iRecipient; i++) {
- CHECK_CONDITION(p != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
p = p->m_recipientNext;
}
- if (p != NULL) {
+ if (p != nullptr) {
p->m_encrypt.m_message.m_refCount++;
}
return (HCOSE_RECIPIENT)p;
errorReturn:
- return NULL;
+ return nullptr;
}
#endif
diff --git a/src/MacMessage0.cpp b/src/MacMessage0.cpp
index 5c66546..c3683d2 100644
--- a/src/MacMessage0.cpp
+++ b/src/MacMessage0.cpp
@@ -18,7 +18,7 @@
#if INCLUDE_MAC0
-COSE *Mac0Root = NULL;
+COSE *Mac0Root = nullptr;
/*! \private
* @brief Test if a HCOSE_MAC0 handle is valid
@@ -43,13 +43,13 @@
HCOSE_MAC0 COSE_Mac0_Init(COSE_INIT_FLAGS flags,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- COSE_Mac0Message *pobj = NULL;
+ COSE_Mac0Message *pobj = nullptr;
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
pobj =
(COSE_Mac0Message *)COSE_CALLOC(1, sizeof(COSE_Mac0Message), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(flags, &pobj->m_message, COSE_mac0_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
@@ -61,11 +61,11 @@
return (HCOSE_MAC0)pobj;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Mac0_Release(pobj);
COSE_FREE(pobj, context);
}
- return NULL;
+ return nullptr;
}
HCOSE_MAC0 _COSE_Mac0_Init_From_Object(cn_cbor *cbor,
@@ -73,27 +73,27 @@
CBOR_CONTEXT_COMMA cose_errback *perr)
{
COSE_Mac0Message *pobj = pIn;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
// cn_cbor * tmp;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj = (COSE_Mac0Message *)COSE_CALLOC(
1, sizeof(COSE_Mac0Message), context);
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Mac0_Release(pobj);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init_From_Object(
@@ -102,7 +102,7 @@
}
pRecipients = _COSE_arrayget_int(&pobj->m_message, INDEX_MAC_RECIPIENTS);
- CHECK_CONDITION(pRecipients == NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pRecipients == nullptr, COSE_ERR_INVALID_PARAMETER);
_COSE_InsertInList(&Mac0Root, &pobj->m_message);
@@ -154,24 +154,24 @@
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &p->m_message.m_allocContext;
#endif
- cn_cbor *ptmp = NULL;
+ cn_cbor *ptmp = nullptr;
cn_cbor_errback cbor_error;
CHECK_CONDITION(IsValidMac0Handle(cose), COSE_ERR_INVALID_PARAMETER);
ptmp = cn_cbor_data_create(
rgbContent, (int)cbContent, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(_COSE_array_replace(&p->m_message, ptmp, INDEX_BODY,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
return true;
errorReturn:
- if (ptmp != NULL) {
+ if (ptmp != nullptr) {
CN_CBOR_FREE(ptmp, context);
}
return false;
@@ -199,7 +199,7 @@
cose_errback *perr)
{
if (!IsValidMac0Handle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -215,10 +215,10 @@
cose_errback *perror)
{
if (!IsValidMac0Handle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -231,8 +231,8 @@
int flags,
cose_errback *perror)
{
- if (!IsValidMac0Handle(h) || (value == NULL)) {
- if (perror != NULL) {
+ if (!IsValidMac0Handle(h) || (value == nullptr)) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_PARAMETER;
}
return false;
@@ -250,7 +250,7 @@
COSE_Mac0Message *pcose = (COSE_Mac0Message *)h;
CHECK_CONDITION(IsValidMac0Handle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pbKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKey != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_Mac_compute(pcose, pbKey, cbKey, "MAC0", perr);
@@ -265,9 +265,9 @@
{
COSE_Mac0Message *pcose = (COSE_Mac0Message *)h;
CHECK_CONDITION(IsValidMac0Handle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pbKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKey != nullptr, COSE_ERR_INVALID_PARAMETER);
- return _COSE_Mac_validate(pcose, NULL, pbKey, cbKey, "MAC0", perr);
+ return _COSE_Mac_validate(pcose, nullptr, pbKey, cbKey, "MAC0", perr);
errorReturn:
return false;
diff --git a/src/Recipient.cpp b/src/Recipient.cpp
index 3714f32..e6f3147 100644
--- a/src/Recipient.cpp
+++ b/src/Recipient.cpp
@@ -20,7 +20,7 @@
#endif
#if INCLUDE_ENCRYPT || INCLUDE_MAC
-COSE *RecipientRoot = NULL;
+COSE *RecipientRoot = nullptr;
/*! \private
* @brief Test if a HCOSE_RECIPIENT handle is valid
@@ -39,7 +39,7 @@
{
COSE_RecipientInfo *p = (COSE_RecipientInfo *)h;
- if (p == NULL) {
+ if (p == nullptr) {
return false;
}
return _COSE_IsInList(RecipientRoot, &p->m_encrypt.m_message);
@@ -50,19 +50,19 @@
{
if (false) {
errorReturn:
- return NULL;
+ return nullptr;
}
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
COSE_RecipientInfo *pobj = (COSE_RecipientInfo *)COSE_CALLOC(
1, sizeof(COSE_RecipientInfo), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(static_cast<COSE_INIT_FLAGS>(COSE_INIT_FLAGS_NO_CBOR_TAG | flags),
&pobj->m_encrypt.m_message, COSE_recipient_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_Recipient_Free(pobj);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&RecipientRoot, &pobj->m_encrypt.m_message);
@@ -94,11 +94,11 @@
int cbKid,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- HCOSE_RECIPIENT hRecipient = NULL;
+ HCOSE_RECIPIENT hRecipient = nullptr;
hRecipient = COSE_Recipient_Init(
COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA perr);
- if (hRecipient == NULL) {
+ if (hRecipient == nullptr) {
goto errorReturn;
}
@@ -110,25 +110,25 @@
return hRecipient;
errorReturn:
- if (hRecipient != NULL) {
+ if (hRecipient != nullptr) {
COSE_Recipient_Free(hRecipient);
}
- return NULL;
+ return nullptr;
}
COSE_RecipientInfo *_COSE_Recipient_Init_From_Object(cn_cbor *cbor,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- COSE_RecipientInfo *pRecipient = NULL;
+ COSE_RecipientInfo *pRecipient = nullptr;
pRecipient = (COSE_RecipientInfo *)COSE_CALLOC(
1, sizeof(COSE_RecipientInfo), context);
- CHECK_CONDITION(pRecipient != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pRecipient != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
if (_COSE_Enveloped_Init_From_Object(cbor, &pRecipient->m_encrypt,
- CBOR_CONTEXT_PARAM_COMMA perr) == NULL) {
+ CBOR_CONTEXT_PARAM_COMMA perr) == nullptr) {
goto errorReturn;
}
@@ -137,10 +137,10 @@
return pRecipient;
errorReturn:
- if (pRecipient != NULL) {
+ if (pRecipient != nullptr) {
_COSE_Recipient_Free(pRecipient);
}
- return NULL;
+ return nullptr;
}
void _COSE_Recipient_Free(COSE_RecipientInfo *pRecipient)
@@ -151,10 +151,10 @@
}
_COSE_Enveloped_Release(&pRecipient->m_encrypt);
- if (pRecipient->m_pkey != NULL) {
+ if (pRecipient->m_pkey != nullptr) {
COSE_KEY_Free((HCOSE_KEY) pRecipient->m_pkey);
}
- if (pRecipient->m_pkeyStatic != NULL) {
+ if (pRecipient->m_pkeyStatic != nullptr) {
COSE_KEY_Free((HCOSE_KEY) pRecipient->m_pkeyStatic);
}
@@ -192,13 +192,13 @@
size_t cbitHash,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- byte *pbContext = NULL;
+ byte *pbContext = nullptr;
size_t cbContext;
bool fRet = false;
const cn_cbor *cn;
byte rgbDigest[512 / 8];
size_t cbDigest;
- byte *pbSecret = NULL;
+ byte *pbSecret = nullptr;
size_t cbSecret = 0;
if (!BuildContextBytes(pCose, algResult, cbitKey, &pbContext, &cbContext,
@@ -210,31 +210,31 @@
#ifdef USE_ECDH
COSE_KEY *pkeyMessage;
- if (pKeyPrivate != NULL) {
+ if (pKeyPrivate != nullptr) {
cn = cn_cbor_mapget_int(pKeyPrivate->m_cborKey, COSE_Key_Type);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_UINT),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_UINT),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
cn->v.uint == COSE_Key_Type_EC2, COSE_ERR_INVALID_PARAMETER);
}
- if (pKeyPublic != NULL) {
+ if (pKeyPublic != nullptr) {
cn = cn_cbor_mapget_int(pKeyPublic->m_cborKey, COSE_Key_Type);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_UINT),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_UINT),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
cn->v.uint == COSE_Key_Type_EC2, COSE_ERR_INVALID_PARAMETER);
}
if (fSend) {
- CHECK_CONDITION(pKeyPublic != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKeyPublic != nullptr, COSE_ERR_INVALID_PARAMETER);
pkeyMessage = pKeyPrivate;
if (!ECDH_ComputeSecret(pCose, &pkeyMessage, pKeyPublic, &pbSecret,
&cbSecret, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
- if (!fStatic && pkeyMessage->m_cborKey->parent == NULL) {
+ if (!fStatic && pkeyMessage->m_cborKey->parent == nullptr) {
if (!_COSE_map_put(pCose, COSE_Header_ECDH_EPHEMERAL,
pkeyMessage->m_cborKey, COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
@@ -245,14 +245,14 @@
cn_cbor * cborKey = _COSE_map_get_int(pCose,
fStatic ? COSE_Header_ECDH_STATIC : COSE_Header_ECDH_EPHEMERAL,
COSE_BOTH, perr);
- CHECK_CONDITION(cborKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(cborKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
pkeyMessage = (COSE_KEY *) COSE_KEY_FromCbor(cborKey, CBOR_CONTEXT_PARAM_COMMA perr);
- if (pkeyMessage == NULL) {
+ if (pkeyMessage == nullptr) {
goto errorReturn;
}
- CHECK_CONDITION(pKeyPrivate != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKeyPrivate != nullptr, COSE_ERR_INVALID_PARAMETER);
if (!ECDH_ComputeSecret(pCose, &pKeyPrivate,
pkeyMessage, &pbSecret, &cbSecret,
@@ -265,9 +265,9 @@
#endif
}
else {
- CHECK_CONDITION(pKeyPrivate != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKeyPrivate != nullptr, COSE_ERR_INVALID_PARAMETER);
cn = cn_cbor_mapget_int(pKeyPrivate->m_cborKey, COSE_Key_Type);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_UINT),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_UINT),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
cn->v.uint == COSE_Key_Type_OCTET, COSE_ERR_INVALID_PARAMETER);
@@ -275,7 +275,7 @@
CHECK_CONDITION(cn->v.sint == 4, COSE_ERR_INVALID_PARAMETER);
cn = cn_cbor_mapget_int(pKeyPrivate->m_cborKey, -1);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
pbSecret = (byte *)cn->v.bytes;
cbSecret = cn->length;
@@ -309,12 +309,12 @@
fRet = true;
errorReturn:
- if (fECDH && pbSecret != NULL) {
+ if (fECDH && pbSecret != nullptr) {
memset(pbSecret, 0, cbSecret);
COSE_FREE(pbSecret, context);
}
memset(rgbDigest, 0, sizeof(rgbDigest));
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
return fRet;
@@ -330,19 +330,19 @@
{
UNUSED(pRecipUse);
int alg;
- const cn_cbor *cn = NULL;
+ const cn_cbor *cn = nullptr;
COSE_RecipientInfo *pRecip2;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context;
#endif
- byte *pbAuthData = NULL;
- byte *pbProtected = NULL;
+ byte *pbAuthData = nullptr;
+ byte *pbProtected = nullptr;
COSE_Enveloped *pcose = &pRecip->m_encrypt;
- cn_cbor *cnBody = NULL;
- byte *pbContext = NULL;
- byte *pbSecret = NULL;
+ cn_cbor *cnBody = nullptr;
+ byte *pbContext = nullptr;
+ byte *pbSecret = nullptr;
int cbKey2;
- byte *pbKeyX = NULL;
+ byte *pbKeyX = nullptr;
int cbitKeyX = 0;
byte rgbKey[256 / 8];
@@ -354,21 +354,21 @@
cn = _COSE_map_get_int(
&pRecip->m_encrypt.m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
errorReturn:
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
- if (pbProtected != NULL) {
+ if (pbProtected != nullptr) {
COSE_FREE(pbProtected, context);
}
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (pbSecret != NULL) {
+ if (pbSecret != nullptr) {
COSE_FREE(pbSecret, context);
}
- if (pbKeyX != NULL) {
+ if (pbKeyX != nullptr) {
COSE_FREE(pbKeyX, context);
}
return false;
@@ -378,13 +378,13 @@
COSE_ERR_INVALID_PARAMETER);
alg = (int)cn->v.uint;
- CHECK_CONDITION(pbKeyOut != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pbKeyOut != nullptr, COSE_ERR_INVALID_PARAMETER);
switch (alg) {
case COSE_Algorithm_Direct:
- CHECK_CONDITION(pRecip->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pRecip->m_pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
cn = cn_cbor_mapget_int(pRecip->m_pkey->m_cborKey, -1);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(((size_t)cn->length == cbitKeyOut / 8),
COSE_ERR_INVALID_PARAMETER);
@@ -485,18 +485,18 @@
break;
}
- if (pcose->m_recipientFirst != NULL) {
+ if (pcose->m_recipientFirst != nullptr) {
// If there is a recipient - ask it for the key
CHECK_CONDITION(cbitKeyX != 0, COSE_ERR_INVALID_PARAMETER);
pbKeyX = (byte*) COSE_CALLOC(cbitKeyX / 8, 1, context);
- CHECK_CONDITION(pbKeyX != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKeyX != nullptr, COSE_ERR_OUT_OF_MEMORY);
cose_errback error = {COSE_ERR_NONE};
cose_error errorFound = COSE_ERR_NONE;
- for (pRecip2 = pcose->m_recipientFirst; pRecip2 != NULL;
+ for (pRecip2 = pcose->m_recipientFirst; pRecip2 != nullptr;
pRecip2 = pRecip->m_recipientNext) {
if (_COSE_Recipient_decrypt(
- pRecip2, NULL, alg, cbitKeyX, pbKeyX, &error)) {
+ pRecip2, nullptr, alg, cbitKeyX, pbKeyX, &error)) {
break;
}
if (error.err == COSE_ERR_NO_COMPRESSED_POINTS ||
@@ -509,16 +509,16 @@
perr->err = errorFound;
goto errorReturn;
}
- CHECK_CONDITION(pRecip2 != NULL, COSE_ERR_NO_RECIPIENT_FOUND);
+ CHECK_CONDITION(pRecip2 != nullptr, COSE_ERR_NO_RECIPIENT_FOUND);
}
cnBody = _COSE_arrayget_int(&pcose->m_message, INDEX_BODY);
- CHECK_CONDITION(cnBody != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cnBody != nullptr, COSE_ERR_INVALID_PARAMETER);
switch (alg) {
#ifdef USE_AES_KW_128
case COSE_Algorithm_AES_KW_128:
- if (pbKeyX != NULL) {
+ if (pbKeyX != nullptr) {
int x = (int) (cbitKeyOut / 8);
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, pbKeyX, cbitKeyX,
cnBody->v.bytes, cnBody->length, pbKeyOut, &x, perr)) {
@@ -527,10 +527,10 @@
}
else {
CHECK_CONDITION(
- pRecip->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ pRecip->m_pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
int x = cbitKeyOut / 8;
cn = cn_cbor_mapget_int(pRecip->m_pkey->m_cborKey, -1);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, cn->v.bytes,
@@ -544,7 +544,7 @@
#ifdef USE_AES_KW_192
case COSE_Algorithm_AES_KW_192:
- if (pbKeyX != NULL) {
+ if (pbKeyX != nullptr) {
int x = cbitKeyOut / 8;
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, pbKeyX, cbitKeyX,
cnBody->v.bytes, cnBody->length, pbKeyOut, &x, perr)) {
@@ -553,10 +553,10 @@
}
else {
CHECK_CONDITION(
- pRecip->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ pRecip->m_pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
int x = cbitKeyOut / 8;
cn = cn_cbor_mapget_int(pRecip->m_pkey->m_cborKey, -1);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, cn->v.bytes,
@@ -570,7 +570,7 @@
#ifdef USE_AES_KW_256
case COSE_Algorithm_AES_KW_256:
- if (pbKeyX != NULL) {
+ if (pbKeyX != nullptr) {
int x = cbitKeyOut / 8;
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, pbKeyX, cbitKeyX,
cnBody->v.bytes, cnBody->length, pbKeyOut, &x, perr)) {
@@ -579,10 +579,10 @@
}
else {
CHECK_CONDITION(
- pRecip->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ pRecip->m_pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
int x = cbitKeyOut / 8;
cn = cn_cbor_mapget_int(pRecip->m_pkey->m_cborKey, -1);
- CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((cn != nullptr) && (cn->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Decrypt((COSE_Enveloped *)pcose, cn->v.bytes,
@@ -597,7 +597,7 @@
#ifdef USE_Direct_HKDF_HMAC_SHA_256
case COSE_Algorithm_Direct_HKDF_HMAC_SHA_256:
if (!HKDF_X(&pcose->m_message, true, false, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 256,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -607,7 +607,7 @@
#ifdef USE_Direct_HKDF_HMAC_SHA_512
case COSE_Algorithm_Direct_HKDF_HMAC_SHA_512:
if (!HKDF_X(&pcose->m_message, true, false, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 512,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 512,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -617,7 +617,7 @@
#ifdef USE_Direct_HKDF_AES_128
case COSE_Algorithm_Direct_HKDF_AES_128:
if (!HKDF_X(&pcose->m_message, false, false, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 128,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 128,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -627,7 +627,7 @@
#ifdef USE_Direct_HKDF_AES_256
case COSE_Algorithm_Direct_HKDF_AES_256:
if (!HKDF_X(&pcose->m_message, false, false, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 256,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -637,7 +637,7 @@
#ifdef USE_ECDH_ES_HKDF_256
case COSE_Algorithm_ECDH_ES_HKDF_256:
if (!HKDF_X(&pcose->m_message, true, true, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 256,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -647,7 +647,7 @@
#ifdef USE_ECDH_ES_HKDF_512
case COSE_Algorithm_ECDH_ES_HKDF_512:
if (!HKDF_X(&pcose->m_message, true, true, false, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 512,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 512,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -657,7 +657,7 @@
#ifdef USE_ECDH_SS_HKDF_256
case COSE_Algorithm_ECDH_SS_HKDF_256:
if (!HKDF_X(&pcose->m_message, true, true, true, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 256,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -667,7 +667,7 @@
#ifdef USE_ECDH_SS_HKDF_512
case COSE_Algorithm_ECDH_SS_HKDF_512:
if (!HKDF_X(&pcose->m_message, true, true, true, false, algIn,
- pRecip->m_pkey, NULL, pbKeyOut, cbitKeyOut, 512,
+ pRecip->m_pkey, nullptr, pbKeyOut, cbitKeyOut, 512,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -677,7 +677,7 @@
#ifdef USE_ECDH_ES_A128KW
case COSE_Algorithm_ECDH_ES_A128KW:
if (!HKDF_X(&pcose->m_message, true, true, false, false,
- COSE_Algorithm_AES_KW_128, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_128, pRecip->m_pkey, nullptr, rgbKey,
128, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -693,7 +693,7 @@
#ifdef USE_ECDH_ES_A192KW
case COSE_Algorithm_ECDH_ES_A192KW:
if (!HKDF_X(&pcose->m_message, true, true, false, false,
- COSE_Algorithm_AES_KW_192, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_192, pRecip->m_pkey, nullptr, rgbKey,
192, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -709,7 +709,7 @@
#ifdef USE_ECDH_ES_A256KW
case COSE_Algorithm_ECDH_ES_A256KW:
if (!HKDF_X(&pcose->m_message, true, true, false, false,
- COSE_Algorithm_AES_KW_256, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_256, pRecip->m_pkey, nullptr, rgbKey,
256, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -725,7 +725,7 @@
#ifdef USE_ECDH_SS_A128KW
case COSE_Algorithm_ECDH_SS_A128KW:
if (!HKDF_X(&pcose->m_message, true, true, true, false,
- COSE_Algorithm_AES_KW_128, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_128, pRecip->m_pkey, nullptr, rgbKey,
128, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -741,7 +741,7 @@
#ifdef USE_ECDH_SS_A192KW
case COSE_Algorithm_ECDH_SS_A192KW:
if (!HKDF_X(&pcose->m_message, true, true, true, false,
- COSE_Algorithm_AES_KW_192, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_192, pRecip->m_pkey, nullptr, rgbKey,
192, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -757,7 +757,7 @@
#ifdef USE_ECDH_SS_A256KW
case COSE_Algorithm_ECDH_SS_A256KW:
if (!HKDF_X(&pcose->m_message, true, true, true, false,
- COSE_Algorithm_AES_KW_256, pRecip->m_pkey, NULL, rgbKey,
+ COSE_Algorithm_AES_KW_256, pRecip->m_pkey, nullptr, rgbKey,
256, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -775,7 +775,7 @@
break;
}
- if (pbKeyX != NULL) {
+ if (pbKeyX != nullptr) {
COSE_FREE(pbKeyX, context);
}
@@ -790,19 +790,19 @@
int alg;
int t = 0;
COSE_RecipientInfo *pri;
- const cn_cbor *cn_Alg = NULL;
- byte *pbAuthData = NULL;
- cn_cbor *ptmp = NULL;
+ const cn_cbor *cn_Alg = nullptr;
+ byte *pbAuthData = nullptr;
+ cn_cbor *ptmp = nullptr;
size_t cbitKey;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
cn_cbor_errback cbor_error;
bool fRet = false;
- byte *pbContext = NULL;
+ byte *pbContext = nullptr;
byte rgbKey[256 / 8];
- byte *pbSecret = NULL;
- byte *pbKey = NULL;
+ byte *pbSecret = nullptr;
+ byte *pbKey = nullptr;
size_t cbKey = 0;
#ifdef USE_CBOR_CONTEXT
@@ -811,23 +811,23 @@
cn_Alg = _COSE_map_get_int(&pRecipient->m_encrypt.m_message,
COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn_Alg == NULL) {
+ if (cn_Alg == nullptr) {
errorReturn:
memset(rgbKey, 0, sizeof(rgbKey));
- if (pbKey != NULL) {
+ if (pbKey != nullptr) {
memset(pbKey, 0, cbKey);
COSE_FREE(pbKey, context);
}
- if (pbSecret != NULL) {
+ if (pbSecret != nullptr) {
COSE_FREE(pbSecret, context);
}
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
- if (pbAuthData != NULL) {
+ if (pbAuthData != nullptr) {
COSE_FREE(pbAuthData, context);
}
- if (ptmp != NULL) {
+ if (ptmp != nullptr) {
cn_cbor_free(ptmp CBOR_CONTEXT_PARAM);
}
return fRet;
@@ -870,7 +870,7 @@
#endif
// This is a NOOP
cbitKey = 0;
- CHECK_CONDITION(pRecipient->m_encrypt.m_recipientFirst == NULL,
+ CHECK_CONDITION(pRecipient->m_encrypt.m_recipientFirst == nullptr,
COSE_ERR_INVALID_PARAMETER);
break;
@@ -934,15 +934,15 @@
// If we are doing direct encryption - then recipient generates the key
- if (pRecipient->m_encrypt.m_recipientFirst != NULL) {
+ if (pRecipient->m_encrypt.m_recipientFirst != nullptr) {
t = 0;
- for (pri = pRecipient->m_encrypt.m_recipientFirst; pri != NULL;
+ for (pri = pRecipient->m_encrypt.m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (pri->m_encrypt.m_message.m_flags & 1) {
t |= 1;
pbKey =
_COSE_RecipientInfo_generateKey(pri, alg, cbitKey, perr);
- if (pbKey == NULL) {
+ if (pbKey == nullptr) {
goto errorReturn;
}
cbKey = cbitKey / 8;
@@ -959,7 +959,7 @@
if (t == 2) {
pbKey = (byte *)COSE_CALLOC(cbitKey / 8, 1, context);
- CHECK_CONDITION(pbKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
cbKey = cbitKey / 8;
rand_bytes(pbKey, cbKey);
}
@@ -969,7 +969,7 @@
const cn_cbor *cbProtected =
_COSE_encode_protected(&pRecipient->m_encrypt.m_message, perr);
- if (cbProtected == NULL) {
+ if (cbProtected == nullptr) {
goto errorReturn;
}
@@ -1008,20 +1008,20 @@
case COSE_Algorithm_ECDH_SS_HKDF_512:
#endif
ptmp = cn_cbor_data_create(
- NULL, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(ptmp != NULL, cbor_error);
+ nullptr, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
+ CHECK_CONDITION_CBOR(ptmp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
_COSE_array_replace(&pRecipient->m_encrypt.m_message, ptmp,
INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- ptmp = NULL;
+ ptmp = nullptr;
break;
#ifdef USE_AES_KW_128
case COSE_Algorithm_AES_KW_128:
- if (pRecipient->m_pkey != NULL) {
+ if (pRecipient->m_pkey != nullptr) {
cn_cbor *pK = cn_cbor_mapget_int(pRecipient->m_pkey->m_cborKey, -1);
- CHECK_CONDITION(pK != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pK != nullptr, COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Encrypt(pRecipient, pK->v.bytes,
(int)pK->length * 8, pbContent, (int)cbContent, perr)) {
goto errorReturn;
@@ -1038,9 +1038,9 @@
#ifdef USE_AES_KW_192
case COSE_Algorithm_AES_KW_192:
- if (pRecipient->m_pkey != NULL) {
+ if (pRecipient->m_pkey != nullptr) {
cn_cbor *pK = cn_cbor_mapget_int(pRecipient->m_pkey->m_cborKey, -1);
- CHECK_CONDITION(pK != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pK != nullptr, COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Encrypt(pRecipient, pK->v.bytes,
(int)pK->length * 8, pbContent, (int)cbContent, perr)) {
goto errorReturn;
@@ -1057,9 +1057,9 @@
#ifdef USE_AES_KW_256
case COSE_Algorithm_AES_KW_256:
- if (pRecipient->m_pkey != NULL) {
+ if (pRecipient->m_pkey != nullptr) {
cn_cbor *pK = cn_cbor_mapget_int(pRecipient->m_pkey->m_cborKey, -1);
- CHECK_CONDITION(pK != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pK != nullptr, COSE_ERR_INVALID_PARAMETER);
if (!AES_KW_Encrypt(pRecipient, pK->v.bytes,
(int)pK->length * 8, pbContent, (int)cbContent, perr)) {
goto errorReturn;
@@ -1077,7 +1077,7 @@
#ifdef USE_ECDH_ES_A128KW
case COSE_Algorithm_ECDH_ES_A128KW:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, true, false,
- true, COSE_Algorithm_AES_KW_128, NULL, pRecipient->m_pkey,
+ true, COSE_Algorithm_AES_KW_128, nullptr, pRecipient->m_pkey,
rgbKey, 128, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1091,7 +1091,7 @@
#ifdef USE_ECDH_ES_A192KW
case COSE_Algorithm_ECDH_ES_A192KW:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, true, false,
- true, COSE_Algorithm_AES_KW_192, NULL, pRecipient->m_pkey,
+ true, COSE_Algorithm_AES_KW_192, nullptr, pRecipient->m_pkey,
rgbKey, 192, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1105,7 +1105,7 @@
#ifdef USE_ECDH_ES_A256KW
case COSE_Algorithm_ECDH_ES_A256KW:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, true, false,
- true, COSE_Algorithm_AES_KW_256, NULL, pRecipient->m_pkey,
+ true, COSE_Algorithm_AES_KW_256, nullptr, pRecipient->m_pkey,
rgbKey, 256, 256, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1165,7 +1165,7 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- for (pri = pRecipient->m_encrypt.m_recipientFirst; pri != NULL;
+ for (pri = pRecipient->m_encrypt.m_recipientFirst; pri != nullptr;
pri = pri->m_recipientNext) {
if (!_COSE_Recipient_encrypt(pri, pbKey, cbKey, perr)) {
goto errorReturn;
@@ -1186,15 +1186,15 @@
int alg;
const cn_cbor *cn_Alg = _COSE_map_get_int(&pRecipient->m_encrypt.m_message,
COSE_Header_Algorithm, COSE_BOTH, perr);
- byte *pbContext = NULL;
- byte *pb = NULL;
+ byte *pbContext = nullptr;
+ byte *pb = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pRecipient->m_encrypt.m_message.m_allocContext;
#endif
const cn_cbor *pK;
- byte *pbSecret = NULL;
+ byte *pbSecret = nullptr;
- CHECK_CONDITION(cn_Alg != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cn_Alg != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
(cn_Alg->type == CN_CBOR_UINT) || (cn_Alg->type == CN_CBOR_INT),
COSE_ERR_INVALID_PARAMETER);
@@ -1203,14 +1203,14 @@
_COSE_encode_protected(&pRecipient->m_encrypt.m_message, perr);
pb = (byte*) COSE_CALLOC(cbitKeySize / 8, 1, context);
- CHECK_CONDITION(pb != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pb != nullptr, COSE_ERR_OUT_OF_MEMORY);
switch (alg) {
case COSE_Algorithm_Direct:
CHECK_CONDITION(
- pRecipient->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ pRecipient->m_pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
pK = cn_cbor_mapget_int(pRecipient->m_pkey->m_cborKey, -1);
- CHECK_CONDITION((pK != NULL) && (pK->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((pK != nullptr) && (pK->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION((size_t)pK->length == cbitKeySize / 8,
COSE_ERR_INVALID_PARAMETER);
@@ -1220,7 +1220,7 @@
#ifdef USE_Direct_HKDF_HMAC_SHA_256
case COSE_Algorithm_Direct_HKDF_HMAC_SHA_256:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, false, false,
- true, algIn, pRecipient->m_pkey, NULL, pb, cbitKeySize, 256,
+ true, algIn, pRecipient->m_pkey, nullptr, pb, cbitKeySize, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1230,7 +1230,7 @@
#ifdef USE_Direct_HKDF_HMAC_SHA_512
case COSE_Algorithm_Direct_HKDF_HMAC_SHA_512:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, false, false,
- true, algIn, pRecipient->m_pkey, NULL, pb, cbitKeySize, 512,
+ true, algIn, pRecipient->m_pkey, nullptr, pb, cbitKeySize, 512,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1240,7 +1240,7 @@
#ifdef USE_Direct_HKDF_AES_128
case COSE_Algorithm_Direct_HKDF_AES_128:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, false, false, false,
- true, algIn, pRecipient->m_pkey, NULL, pb, cbitKeySize, 128,
+ true, algIn, pRecipient->m_pkey, nullptr, pb, cbitKeySize, 128,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1250,7 +1250,7 @@
#ifdef USE_Direct_HKDF_AES_256
case COSE_Algorithm_Direct_HKDF_AES_256:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, false, false, false,
- true, algIn, pRecipient->m_pkey, NULL, pb, cbitKeySize, 256,
+ true, algIn, pRecipient->m_pkey, nullptr, pb, cbitKeySize, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1260,7 +1260,7 @@
#ifdef USE_ECDH_ES_HKDF_256
case COSE_Algorithm_ECDH_ES_HKDF_256:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, true, false,
- true, algIn, NULL, pRecipient->m_pkey, pb, cbitKeySize, 256,
+ true, algIn, nullptr, pRecipient->m_pkey, pb, cbitKeySize, 256,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1270,7 +1270,7 @@
#ifdef USE_ECDH_ES_HKDF_512
case COSE_Algorithm_ECDH_ES_HKDF_512:
if (!HKDF_X(&pRecipient->m_encrypt.m_message, true, true, false,
- true, algIn, NULL, pRecipient->m_pkey, pb, cbitKeySize, 512,
+ true, algIn, nullptr, pRecipient->m_pkey, pb, cbitKeySize, 512,
CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
@@ -1301,26 +1301,26 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- if (pbSecret != NULL) {
+ if (pbSecret != nullptr) {
COSE_FREE(pbSecret, context);
}
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
return pb;
errorReturn:
- if (pbSecret != NULL) {
+ if (pbSecret != nullptr) {
COSE_FREE(pbSecret, context);
}
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
- if (pb != NULL) {
+ if (pb != nullptr) {
COSE_FREE(pb, context);
}
- return NULL;
+ return nullptr;
}
#endif
@@ -1333,31 +1333,31 @@
cose_errback *perr)
{
COSE_RecipientInfo *p;
- cn_cbor *cn_Temp = NULL;
- cn_cbor *cnTemp = NULL;
+ cn_cbor *cn_Temp = nullptr;
+ cn_cbor *cnTemp = nullptr;
cn_cbor_errback cbor_error;
- byte *pbTemp = NULL;
- byte *pbKey = NULL;
+ byte *pbTemp = nullptr;
+ byte *pbKey = nullptr;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
- HCOSE_KEY hKey = NULL;
+ HCOSE_KEY hKey = nullptr;
if (false) {
errorReturn:
- if (hKey != NULL) {
+ if (hKey != nullptr) {
COSE_KEY_Free(hKey);
}
- if (cn_Temp != NULL) {
+ if (cn_Temp != nullptr) {
CN_CBOR_FREE(cn_Temp, context);
}
- if (cnTemp != NULL) {
+ if (cnTemp != nullptr) {
CN_CBOR_FREE(cnTemp, context);
}
- if (pbTemp != NULL) {
+ if (pbTemp != nullptr) {
COSE_FREE(pbTemp, context);
}
- if (pbKey != NULL) {
+ if (pbKey != nullptr) {
COSE_FREE(pbKey, context);
}
return false;
@@ -1365,7 +1365,7 @@
CHECK_CONDITION(
IsValidRecipientHandle(hRecipient), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(rgbKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(rgbKey != nullptr, COSE_ERR_INVALID_PARAMETER);
p = (COSE_RecipientInfo *)hRecipient;
@@ -1375,7 +1375,7 @@
cn_cbor *cnAlg = _COSE_map_get_int(
&p->m_encrypt.m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cnAlg != NULL) {
+ if (cnAlg != nullptr) {
CHECK_CONDITION(cnAlg->type == CN_CBOR_INT &&
cnAlg->v.sint == COSE_Algorithm_Direct,
COSE_ERR_INVALID_PARAMETER);
@@ -1383,23 +1383,23 @@
else {
cn_Temp = cn_cbor_int_create(
COSE_Algorithm_Direct, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn_Temp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_Temp != nullptr, cbor_error);
if (!COSE_Recipient_map_put_int(hRecipient, COSE_Header_Algorithm,
cn_Temp, COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cn_Temp = NULL;
+ cn_Temp = nullptr;
}
if (cbKid > 0) {
pbTemp = (byte *)COSE_CALLOC(cbKid, 1, context);
- CHECK_CONDITION(pbTemp != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbTemp != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbTemp, rgbKid, cbKid);
cnTemp = cn_cbor_data_create(
pbTemp, cbKid, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnTemp != NULL, cbor_error);
- pbTemp = NULL;
+ CHECK_CONDITION_CBOR(cnTemp != nullptr, cbor_error);
+ pbTemp = nullptr;
if (!COSE_Recipient_map_put_int(hRecipient, COSE_Header_KID, cnTemp,
COSE_UNPROTECT_ONLY, perr)) {
@@ -1408,36 +1408,36 @@
}
pbKey = (byte *)COSE_CALLOC(cbKey, 1, context);
- CHECK_CONDITION(pbKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbKey, rgbKey, cbKey);
cn_Temp = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn_Temp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_Temp != nullptr, cbor_error);
cnTemp = cn_cbor_int_create(4, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnTemp != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnTemp != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn_Temp, COSE_Key_Type, cnTemp,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- cnTemp = NULL;
+ cnTemp = nullptr;
cnTemp = cn_cbor_data_create(
pbKey, cbKey, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnTemp != NULL, cbor_error);
- pbKey = NULL;
+ CHECK_CONDITION_CBOR(cnTemp != nullptr, cbor_error);
+ pbKey = nullptr;
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn_Temp, -1, cnTemp,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- cnTemp = NULL;
+ cnTemp = nullptr;
hKey = COSE_KEY_FromCbor(cn_Temp, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(hKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(hKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!COSE_Recipient_SetKey2(hRecipient, hKey, perr)) {
goto errorReturn;
}
- cn_Temp = NULL;
+ cn_Temp = nullptr;
return true;
}
@@ -1446,18 +1446,18 @@
const cn_cbor *pKey,
cose_errback *perr)
{
- HCOSE_KEY hkey = NULL;
+ HCOSE_KEY hkey = nullptr;
if (false) {
errorReturn:
- if (hkey != NULL) {
+ if (hkey != nullptr) {
COSE_KEY_Free(hkey);
}
return false;
}
CHECK_CONDITION(IsValidRecipientHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKey != nullptr, COSE_ERR_INVALID_PARAMETER);
COSE_RecipientInfo *p = (COSE_RecipientInfo *)h;
@@ -1467,7 +1467,7 @@
hkey = COSE_KEY_FromCbor(
(cn_cbor *)pKey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(hkey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(hkey != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!COSE_Recipient_SetKey2(h, hkey, perr)) {
goto errorReturn;
}
@@ -1482,12 +1482,12 @@
CHECK_CONDITION(IsValidRecipientHandle(h), COSE_ERR_INVALID_HANDLE);
p = (COSE_RecipientInfo *)h;
- if (p->m_pkey != NULL) {
+ if (p->m_pkey != nullptr) {
COSE_KEY_Free((HCOSE_KEY) p->m_pkey);
}
p->m_pkey = (COSE_KEY *)hKey;
- if (p->m_pkey != NULL) {
+ if (p->m_pkey != nullptr) {
p->m_pkey->m_refCount += 1;
}
@@ -1519,25 +1519,25 @@
cose_errback *perr)
{
bool fRet = false;
- HCOSE_KEY coseKey = NULL;
+ HCOSE_KEY coseKey = nullptr;
if (false) {
errorReturn:
- if (coseKey != NULL) {
+ if (coseKey != nullptr) {
COSE_KEY_Free(coseKey);
}
return fRet;
}
CHECK_CONDITION(IsValidRecipientHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKey != nullptr, COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
coseKey = COSE_KEY_FromCbor((cn_cbor *)pKey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(coseKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(coseKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
fRet = COSE_Recipient_SetSenderKey2(h, coseKey, destination, perr);
goto errorReturn;
@@ -1551,19 +1551,19 @@
COSE_RecipientInfo *p;
bool f = false;
cn_cbor *cn;
- cn_cbor *cn2 = NULL;
- cn_cbor *cn3 = NULL;
+ cn_cbor *cn2 = nullptr;
+ cn_cbor *cn3 = nullptr;
cn_cbor_errback cbor_err;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
if (false) {
errorReturn:
- if (cn2 != NULL) {
+ if (cn2 != nullptr) {
CN_CBOR_FREE(cn2, context);
}
- if (cn3 != NULL) {
+ if (cn3 != nullptr) {
CN_CBOR_FREE(cn3, context);
}
return f;
@@ -1585,60 +1585,60 @@
case 1:
cn = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_ID);
- CHECK_CONDITION(cn != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_INVALID_PARAMETER);
cn2 = cn_cbor_clone(cn, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn2 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn2 != nullptr, cbor_err);
CHECK_CONDITION(
_COSE_map_put(&p->m_encrypt.m_message, COSE_Header_ECDH_SPK_KID,
cn2, COSE_UNPROTECT_ONLY, perr),
perr->err);
- cn2 = NULL;
+ cn2 = nullptr;
break;
case 2:
cn2 = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn2 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn2 != nullptr, cbor_err);
cn = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_Type);
- CHECK_CONDITION(cn != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_INVALID_PARAMETER);
cn3 = cn_cbor_clone(cn, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn3 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn3 != nullptr, cbor_err);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn2, COSE_Key_Type, cn3,
CBOR_CONTEXT_PARAM_COMMA & cbor_err),
cbor_err);
- cn3 = NULL;
+ cn3 = nullptr;
cn = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC2_Curve);
cn3 = cn_cbor_clone(cn, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn3 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn3 != nullptr, cbor_err);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn2, COSE_Key_EC2_Curve,
cn3, CBOR_CONTEXT_PARAM_COMMA & cbor_err),
cbor_err);
- cn3 = NULL;
+ cn3 = nullptr;
cn = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC2_X);
cn3 = cn_cbor_clone(cn, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn3 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn3 != nullptr, cbor_err);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn2, COSE_Key_EC2_X, cn3,
CBOR_CONTEXT_PARAM_COMMA & cbor_err),
cbor_err);
- cn3 = NULL;
+ cn3 = nullptr;
cn = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC2_Y);
cn3 = cn_cbor_clone(cn, CBOR_CONTEXT_PARAM_COMMA & cbor_err);
- CHECK_CONDITION_CBOR(cn3 != NULL, cbor_err);
+ CHECK_CONDITION_CBOR(cn3 != nullptr, cbor_err);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(cn2, COSE_Key_EC2_Y, cn3,
CBOR_CONTEXT_PARAM_COMMA & cbor_err),
cbor_err);
- cn3 = NULL;
+ cn3 = nullptr;
CHECK_CONDITION(
_COSE_map_put(&p->m_encrypt.m_message, COSE_Header_ECDH_SPK,
cn2, COSE_UNPROTECT_ONLY, perr),
perr->err);
- cn2 = NULL;
+ cn2 = nullptr;
break;
default:
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- if (p->m_pkeyStatic != NULL) {
+ if (p->m_pkeyStatic != nullptr) {
COSE_KEY_Free((HCOSE_KEY)p->m_pkeyStatic);
}
p->m_pkeyStatic = pKey;
@@ -1670,7 +1670,7 @@
cose_errback *perr)
{
if (!IsValidRecipientHandle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
return false;
@@ -1688,7 +1688,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidRecipientHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
if (!_COSE_map_put(&((COSE_RecipientInfo *)h)->m_encrypt.m_message, key,
value, flags, perr)) {
@@ -1766,191 +1766,191 @@
cn_cbor *pArray;
cn_cbor_errback cbor_error;
bool fReturn = false;
- cn_cbor *cnT = NULL;
- cn_cbor *cnArrayT = NULL;
+ cn_cbor *cnT = nullptr;
+ cn_cbor *cnArrayT = nullptr;
cn_cbor *cnParam;
- byte *pbContext = NULL;
+ byte *pbContext = nullptr;
if (false) {
errorReturn:
fReturn = false;
returnHere:
- if (pbContext != NULL) {
+ if (pbContext != nullptr) {
COSE_FREE(pbContext, context);
}
- if (pArray != NULL) {
+ if (pArray != nullptr) {
CN_CBOR_FREE(pArray, context);
}
- if (cnArrayT != NULL) {
+ if (cnArrayT != nullptr) {
CN_CBOR_FREE(cnArrayT, context);
}
- if (cnT != NULL) {
+ if (cnT != nullptr) {
CN_CBOR_FREE(cnT, context);
}
return fReturn;
}
pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pArray != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pArray != nullptr, cbor_error);
cnT = cn_cbor_int_create(algID, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cnT, &cbor_error), cbor_error);
- cnT = NULL;
+ cnT = nullptr;
cnArrayT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnArrayT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnArrayT != nullptr, cbor_error);
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_U_name, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
cnParam =
_COSE_map_get_int(pcose, COSE_Header_KDF_U_nonce, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
cnParam =
_COSE_map_get_int(pcose, COSE_Header_KDF_U_other, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cnArrayT, &cbor_error), cbor_error);
- cnArrayT = NULL;
+ cnArrayT = nullptr;
cnArrayT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnArrayT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnArrayT != nullptr, cbor_error);
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_V_name, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
cnParam =
_COSE_map_get_int(pcose, COSE_Header_KDF_V_nonce, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
cnParam =
_COSE_map_get_int(pcose, COSE_Header_KDF_V_other, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cnArrayT, &cbor_error), cbor_error);
- cnArrayT = NULL;
+ cnArrayT = nullptr;
cnArrayT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnArrayT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnArrayT != nullptr, cbor_error);
cnT = cn_cbor_int_create(cbitKey, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
+ cnT = nullptr;
cnParam = _COSE_arrayget_int(pcose, INDEX_PROTECTED);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
}
cnParam =
_COSE_map_get_int(pcose, COSE_Header_KDF_PUB_other, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
}
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cnArrayT, &cbor_error), cbor_error);
- cnArrayT = NULL;
+ cnArrayT = nullptr;
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_PRIV, COSE_BOTH, perr);
- if (cnParam != NULL) {
+ if (cnParam != nullptr) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cnT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
+ cnT = nullptr;
+ cnParam = nullptr;
}
size_t cbContext = cn_cbor_encode_size(pArray);
CHECK_CONDITION(cbContext > 0, COSE_ERR_CBOR);
pbContext = (byte *)COSE_CALLOC(cbContext, 1, context);
- CHECK_CONDITION(pbContext != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbContext != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(cn_cbor_encoder_write(pbContext, 0, cbContext, pArray) ==
(ssize_t)cbContext,
COSE_ERR_CBOR);
*ppbContext = pbContext;
*pcbContext = cbContext;
- pbContext = NULL;
+ pbContext = nullptr;
fReturn = true;
goto returnHere;
@@ -1967,7 +1967,7 @@
* @param[in] key Key to look for
* @param[in] flags What buckets should we look for the message
* @param[out] perror Location to return error codes
- * @return Object which is found or NULL
+ * @return Object which is found or nullptr
*/
cn_cbor *COSE_Recipient_map_get_int(HCOSE_RECIPIENT h,
@@ -1976,10 +1976,10 @@
cose_errback *perror)
{
if (!IsValidRecipientHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -1991,17 +1991,17 @@
cose_errback *perr)
{
int i;
- COSE_RecipientInfo *p = NULL;
+ COSE_RecipientInfo *p = nullptr;
CHECK_CONDITION(IsValidRecipientHandle(cose), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(iRecipient >= 0, COSE_ERR_INVALID_PARAMETER);
p = ((COSE_RecipientInfo *)cose)->m_encrypt.m_recipientFirst;
for (i = 0; i < iRecipient; i++) {
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
p = p->m_recipientNext;
}
- if (p != NULL) {
+ if (p != nullptr) {
p->m_encrypt.m_message.m_refCount++;
}
@@ -2015,7 +2015,7 @@
{
COSE_RecipientInfo *pRecip;
COSE_Enveloped *pEncrypt;
- cn_cbor *pRecipients = NULL;
+ cn_cbor *pRecipients = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context;
#endif
@@ -2035,15 +2035,15 @@
pEncrypt->m_recipientFirst = pRecip;
pRecipients = _COSE_arrayget_int(&pEncrypt->m_message, INDEX_RECIPIENTS);
- if (pRecipients == NULL) {
+ if (pRecipients == nullptr) {
pRecipients =
cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pRecipients != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pRecipients != nullptr, cbor_error);
if (!_COSE_array_replace(&pEncrypt->m_message, pRecipients,
INDEX_RECIPIENTS, CBOR_CONTEXT_PARAM_COMMA & cbor_error)) {
CN_CBOR_FREE(pRecipients, context);
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = _MapFromCBOR(cbor_error);
}
goto errorReturn;
diff --git a/src/Sign.cpp b/src/Sign.cpp
index a66ff76..8061c34 100644
--- a/src/Sign.cpp
+++ b/src/Sign.cpp
@@ -11,7 +11,7 @@
#if INCLUDE_SIGN
-COSE *SignRoot = NULL;
+COSE *SignRoot = nullptr;
/*! \private
* @brief Test if a HCOSE_SIGN handle is valid
@@ -31,7 +31,7 @@
{
COSE_SignMessage *p = (COSE_SignMessage *)h;
- if (p == NULL) {
+ if (p == nullptr) {
return false;
}
return _COSE_IsInList(SignRoot, (COSE *)p);
@@ -49,18 +49,18 @@
{
if (false) {
errorReturn:
- return NULL;
+ return nullptr;
}
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
COSE_SignMessage *pobj =
(COSE_SignMessage *)COSE_CALLOC(1, sizeof(COSE_SignMessage), context);
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init(flags, &pobj->m_message, COSE_sign_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_Sign_Release(pobj);
COSE_FREE(pobj, context);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&SignRoot, &pobj->m_message);
@@ -73,18 +73,18 @@
CBOR_CONTEXT_COMMA cose_errback *perr)
{
COSE_SignMessage *pobj = pIn;
- cn_cbor *pSigners = NULL;
+ cn_cbor *pSigners = nullptr;
// cn_cbor * tmp;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj = (COSE_SignMessage *)COSE_CALLOC(
1, sizeof(COSE_SignMessage), context);
}
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init_From_Object(
&pobj->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) {
@@ -92,7 +92,7 @@
}
pSigners = _COSE_arrayget_int(&pobj->m_message, INDEX_SIGNERS);
- CHECK_CONDITION(pSigners != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pSigners != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
pSigners->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(pSigners->length > 0,
@@ -101,30 +101,30 @@
pSigners = pSigners->first_child;
do {
COSE_SignerInfo *pInfo = _COSE_SignerInfo_Init_From_Object(
- pSigners, NULL, CBOR_CONTEXT_PARAM_COMMA perr);
- if (pInfo == NULL) {
+ pSigners, nullptr, CBOR_CONTEXT_PARAM_COMMA perr);
+ if (pInfo == nullptr) {
goto errorReturn;
}
pInfo->m_signerNext = pobj->m_signerFirst;
pobj->m_signerFirst = pInfo;
pSigners = pSigners->next;
- } while (pSigners != NULL);
+ } while (pSigners != nullptr);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
_COSE_InsertInList(&SignRoot, &pobj->m_message);
}
return (HCOSE_SIGN)pobj;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Sign_Release(pobj);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
}
- return NULL;
+ return nullptr;
}
bool COSE_Sign_Free(HCOSE_SIGN h)
@@ -162,7 +162,7 @@
COSE_SignerInfo *pSigner;
COSE_SignerInfo *pSigner2;
- for (pSigner = p->m_signerFirst; pSigner != NULL; pSigner = pSigner2) {
+ for (pSigner = p->m_signerFirst; pSigner != nullptr; pSigner = pSigner2) {
pSigner2 = pSigner->m_signerNext;
COSE_Signer_Free((HCOSE_SIGNER)pSigner);
}
@@ -176,30 +176,30 @@
cose_errback *perr)
{
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
COSE_SignMessage *pMessage = (COSE_SignMessage *)h;
bool f = false;
CHECK_CONDITION(IsValidSignHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(rgb != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(rgb != nullptr, COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
context = &pMessage->m_message.m_allocContext;
#endif
- p = cn_cbor_data_create(rgb, (int)cb, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(p != NULL, COSE_ERR_OUT_OF_MEMORY);
+ p = cn_cbor_data_create(rgb, (int)cb, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(_COSE_array_replace(&pMessage->m_message, p, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_OUT_OF_MEMORY);
- p = NULL;
+ p = nullptr;
f = true;
errorReturn:
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
@@ -212,46 +212,46 @@
cose_errback *perr)
{
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
COSE_SignMessage *pMessage = (COSE_SignMessage *)hSign;
#endif
const cn_cbor *cbor;
- cn_cbor *cbor2 = NULL;
- HCOSE_SIGNER hSigner = NULL;
+ cn_cbor *cbor2 = nullptr;
+ HCOSE_SIGNER hSigner = nullptr;
cn_cbor_errback cbor_error;
CHECK_CONDITION(IsValidSignHandle(hSign), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(pkey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pkey != nullptr, COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
context = &pMessage->m_message.m_allocContext;
#endif
hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA perr);
- if (hSigner == NULL) {
+ if (hSigner == nullptr) {
goto errorReturn;
}
cbor2 = cn_cbor_int_create(algId, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor2 != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cbor2 != nullptr, cbor_error);
if (!COSE_Signer_map_put_int(
hSigner, COSE_Header_Algorithm, cbor2, COSE_PROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor2 = NULL;
+ cbor2 = nullptr;
cbor = cn_cbor_mapget_int(pkey, COSE_Key_ID);
- if (cbor != NULL) {
+ if (cbor != nullptr) {
CHECK_CONDITION(
cbor->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
cbor2 = cn_cbor_data_create(cbor->v.bytes, (int)cbor->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor2 != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cbor2 != nullptr, cbor_error);
if (!COSE_Signer_map_put_int(
hSigner, COSE_Header_KID, cbor2, COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor2 = NULL;
+ cbor2 = nullptr;
}
if (!COSE_Signer_SetKey(hSigner, pkey, perr)) {
@@ -265,19 +265,19 @@
return hSigner;
errorReturn:
- if (cbor2 != NULL) {
+ if (cbor2 != nullptr) {
CN_CBOR_FREE(cbor2, context);
}
- if (hSigner != NULL) {
+ if (hSigner != nullptr) {
COSE_Signer_Free(hSigner);
}
- return NULL;
+ return nullptr;
}
bool COSE_Sign_Sign(HCOSE_SIGN h, cose_errback *perr)
{
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
COSE_SignMessage *pMessage = (COSE_SignMessage *)h;
COSE_SignerInfo *pSigner;
@@ -294,15 +294,15 @@
#endif
pcborBody = _COSE_arrayget_int(&pMessage->m_message, INDEX_BODY);
- CHECK_CONDITION((pcborBody != NULL) && (pcborBody->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((pcborBody != nullptr) && (pcborBody->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
pcborProtected = _COSE_encode_protected(&pMessage->m_message, perr);
- if (pcborProtected == NULL) {
+ if (pcborProtected == nullptr) {
goto errorReturn;
}
- for (pSigner = pMessage->m_signerFirst; pSigner != NULL;
+ for (pSigner = pMessage->m_signerFirst; pSigner != nullptr;
pSigner = pSigner->m_signerNext) {
if (!_COSE_Signer_sign(
pSigner, pcborBody, pcborProtected, "Signature", perr)) {
@@ -311,7 +311,7 @@
}
#if INCLUDE_COUNTERSIGNATURE
- if (pMessage->m_message.m_counterSigners != NULL) {
+ if (pMessage->m_message.m_counterSigners != nullptr) {
if (!_COSE_CounterSign_Sign(
&pMessage->m_message, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
@@ -339,11 +339,11 @@
pSigner = (COSE_SignerInfo *)hSigner;
cnContent = _COSE_arrayget_int(&pSign->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
cnProtected = _COSE_arrayget_int(&pSign->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
f = _COSE_Signer_validate(
@@ -361,10 +361,10 @@
{
COSE_SignerInfo *pSigner;
COSE_SignMessage *pSign;
- cn_cbor *pSigners = NULL;
- cn_cbor *pSignersT = NULL;
+ cn_cbor *pSigners = nullptr;
+ cn_cbor *pSignersT = nullptr;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
cn_cbor_errback cbor_error;
@@ -382,16 +382,16 @@
#endif // USE_CBOR_CONTEXT
pSigners = _COSE_arrayget_int(&pSign->m_message, INDEX_SIGNERS);
- if (pSigners == NULL) {
+ if (pSigners == nullptr) {
pSignersT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pSignersT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pSignersT != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
_COSE_array_replace(&pSign->m_message, pSignersT, INDEX_SIGNERS,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
pSigners = pSignersT;
- pSignersT = NULL;
+ pSignersT = nullptr;
}
CHECK_CONDITION_CBOR(
@@ -402,7 +402,7 @@
return true;
errorReturn:
- if (pSignersT == NULL) {
+ if (pSignersT == nullptr) {
CN_CBOR_FREE(pSignersT, context);
}
return false;
@@ -414,10 +414,10 @@
cose_errback *perror)
{
if (!IsValidSignHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -431,7 +431,7 @@
cose_errback *perror)
{
if (!IsValidSignHandle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
return false;
@@ -449,19 +449,19 @@
COSE_SignerInfo *p;
if (!IsValidSignHandle(cose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
p = ((COSE_SignMessage *)cose)->m_signerFirst;
for (i = 0; i < iSigner; i++) {
- if (p == NULL) {
- if (perr != NULL) {
+ if (p == nullptr) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
- return NULL;
+ return nullptr;
}
p = p->m_signerNext;
}
diff --git a/src/Sign1.cpp b/src/Sign1.cpp
index 87b8f75..7d9eefa 100644
--- a/src/Sign1.cpp
+++ b/src/Sign1.cpp
@@ -19,7 +19,7 @@
COSE_KEY *pKey,
cose_errback *perr);
-COSE *Sign1Root = NULL;
+COSE *Sign1Root = nullptr;
/*! \private
* @brief Test if a HCOSE_SIGN1 handle is valid
@@ -39,7 +39,7 @@
{
COSE_Sign1Message *p = (COSE_Sign1Message *)h;
- if (p == NULL) {
+ if (p == nullptr) {
return false;
}
return _COSE_IsInList(Sign1Root, (COSE *)p);
@@ -50,24 +50,24 @@
{
if (false) {
errorReturn:
- return NULL;
+ return nullptr;
}
CHECK_CONDITION(flags == COSE_INIT_FLAGS_NONE, COSE_ERR_INVALID_PARAMETER);
COSE_Sign1Message *pobj =
(COSE_Sign1Message *)COSE_CALLOC(1, sizeof(COSE_Sign1Message), context);
- if (pobj == NULL) {
- if (perr != NULL) {
+ if (pobj == nullptr) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
if (!_COSE_Init(flags, &pobj->m_message, COSE_sign_object,
CBOR_CONTEXT_PARAM_COMMA perr)) {
_COSE_Sign1_Release(pobj);
COSE_FREE(pobj, context);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&Sign1Root, &pobj->m_message);
@@ -82,35 +82,35 @@
COSE_Sign1Message *pobj = pIn;
cose_errback error = {COSE_ERR_NONE};
- if (perr == NULL) {
+ if (perr == nullptr) {
perr = &error;
}
- if (pobj == NULL) {
+ if (pobj == nullptr) {
pobj = (COSE_Sign1Message *)COSE_CALLOC(
1, sizeof(COSE_Sign1Message), context);
}
- CHECK_CONDITION(pobj != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pobj != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (!_COSE_Init_From_Object(
&pobj->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
}
- if (pIn == NULL) {
+ if (pIn == nullptr) {
_COSE_InsertInList(&Sign1Root, &pobj->m_message);
}
return (HCOSE_SIGN1)pobj;
errorReturn:
- if (pobj != NULL) {
+ if (pobj != nullptr) {
_COSE_Sign1_Release(pobj);
- if (pIn == NULL) {
+ if (pIn == nullptr) {
COSE_FREE(pobj, context);
}
}
- return NULL;
+ return nullptr;
}
bool COSE_Sign1_Free(HCOSE_SIGN1 h)
@@ -154,31 +154,31 @@
cose_errback *perr)
{
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
COSE_Sign1Message *pMessage = (COSE_Sign1Message *)h;
bool fRet = false;
CHECK_CONDITION(IsValidSign1Handle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(rgb != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(rgb != nullptr, COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
context = &pMessage->m_message.m_allocContext;
#endif
- p = cn_cbor_data_create(rgb, (int)cb, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(p != NULL, COSE_ERR_OUT_OF_MEMORY);
+ p = cn_cbor_data_create(rgb, (int)cb, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(_COSE_array_replace(&pMessage->m_message, p, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_OUT_OF_MEMORY);
- p = NULL;
+ p = nullptr;
fRet = true;
errorReturn:
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
return fRet;
@@ -206,7 +206,7 @@
cose_errback *perr)
{
if (!IsValidSign1Handle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
return false;
@@ -218,25 +218,25 @@
bool COSE_Sign1_Sign(HCOSE_SIGN1 h, const cn_cbor *pKey, cose_errback *perr)
{
- HCOSE_KEY cose = NULL;
+ HCOSE_KEY cose = nullptr;
bool fRet = false;
if (false) {
errorReturn:
- if (cose != NULL) {
+ if (cose != nullptr) {
COSE_KEY_Free(cose);
}
return fRet;
}
- CHECK_CONDITION(pKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKey != nullptr, COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
cose = COSE_KEY_FromCbor((cn_cbor *)pKey, CBOR_CONTEXT_PARAM_COMMA perr);
- if (cose == NULL) {
+ if (cose == nullptr) {
goto errorReturn;
}
@@ -248,7 +248,7 @@
bool COSE_Sign1_Sign2(HCOSE_SIGN1 h, HCOSE_KEY hKey, cose_errback *perr)
{
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
COSE_Sign1Message *pMessage = (COSE_Sign1Message *)h;
const cn_cbor *pcborProtected;
@@ -265,7 +265,7 @@
#endif
pcborProtected = _COSE_encode_protected(&pMessage->m_message, perr);
- if (pcborProtected == NULL) {
+ if (pcborProtected == nullptr) {
goto errorReturn;
}
@@ -274,7 +274,7 @@
}
#if INCLUDE_COUNTERSIGNATURE
- if (pMessage->m_message.m_counterSigners != NULL) {
+ if (pMessage->m_message.m_counterSigners != nullptr) {
if (!_COSE_CounterSign_Sign(
&pMessage->m_message, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
@@ -293,11 +293,11 @@
COSE_Sign1Message *pSign;
const cn_cbor *cnContent;
const cn_cbor *cnProtected;
- COSE_KEY *pcose = NULL;
+ COSE_KEY *pcose = nullptr;
if (false) {
errorReturn:
- if (pcose != NULL) {
+ if (pcose != nullptr) {
COSE_KEY_Free((HCOSE_KEY)pcose);
}
return false;
@@ -308,11 +308,11 @@
pSign = (COSE_Sign1Message *)hSign;
cnContent = _COSE_arrayget_int(&pSign->m_message, INDEX_BODY);
- CHECK_CONDITION(cnContent != NULL && cnContent->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnContent != nullptr && cnContent->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
cnProtected = _COSE_arrayget_int(&pSign->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cnProtected != NULL && cnProtected->type == CN_CBOR_BYTES,
+ CHECK_CONDITION(cnProtected != nullptr && cnProtected->type == CN_CBOR_BYTES,
COSE_ERR_INVALID_PARAMETER);
#ifdef USE_CBOR_CONTEXT
@@ -320,7 +320,7 @@
#endif
pcose = (COSE_KEY*) COSE_KEY_FromCbor((cn_cbor *)pKey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(pKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
f = _COSE_Signer1_validate(pSign, pcose, perr);
@@ -334,10 +334,10 @@
cose_errback *perror)
{
if (!IsValidSign1Handle(h)) {
- if (perror != NULL) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int(
@@ -351,7 +351,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidSign1Handle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_map_put(
&((COSE_Sign1Message *)h)->m_message, key, value, flags, perr);
@@ -366,86 +366,86 @@
const char *szContext,
cose_errback *perr)
{
- cn_cbor *pArray = NULL;
+ cn_cbor *pArray = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pMessage->m_message.m_allocContext;
#endif
cn_cbor_errback cbor_error;
- cn_cbor *cn = NULL;
+ cn_cbor *cn = nullptr;
cn_cbor *cn2;
size_t cbToSign;
- byte *pbToSign = NULL;
+ byte *pbToSign = nullptr;
pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pArray != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pArray != nullptr, cbor_error);
cn =
cn_cbor_string_create(szContext, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cn2 = _COSE_arrayget_int(&pMessage->m_message, INDEX_PROTECTED);
- CHECK_CONDITION(cn2 != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(cn2 != nullptr, COSE_ERR_INVALID_PARAMETER);
if ((cn2->length == 1) && (cn2->v.bytes[0] == 0xa0)) {
cn =
- cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
+ cn_cbor_data_create(nullptr, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cn = cn_cbor_data_create(cn2->v.bytes, (int)cn2->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cn = cn_cbor_data_create(pMessage->m_message.m_pbExternal,
(int)pMessage->m_message.m_cbExternal,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cn2 = _COSE_arrayget_int(&pMessage->m_message, INDEX_BODY);
cn = cn_cbor_data_create(
cn2->v.bytes, (int)cn2->length, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cbToSign = cn_cbor_encode_size(pArray);
CHECK_CONDITION(cbToSign > 0, COSE_ERR_CBOR);
pbToSign = (byte *)COSE_CALLOC(cbToSign, 1, context);
- CHECK_CONDITION(pbToSign != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbToSign != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray) ==
(ssize_t)cbToSign,
COSE_ERR_CBOR);
*ppbToSign = pbToSign;
*pcbToSign = cbToSign;
- pbToSign = NULL;
+ pbToSign = nullptr;
- if (cn != NULL) {
+ if (cn != nullptr) {
CN_CBOR_FREE(cn, context);
}
- if (pArray != NULL) {
+ if (pArray != nullptr) {
CN_CBOR_FREE(pArray, context);
}
return true;
errorReturn:
- if (pbToSign != NULL) {
+ if (pbToSign != nullptr) {
COSE_FREE(pbToSign, context);
}
- if (cn != NULL) {
+ if (cn != nullptr) {
CN_CBOR_FREE(cn, context);
}
- if (pArray != NULL) {
+ if (pArray != nullptr) {
CN_CBOR_FREE(pArray, context);
}
return false;
@@ -458,31 +458,31 @@
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_message.m_allocContext;
#endif
- cn_cbor *pcborBody2 = NULL;
- cn_cbor *pcborProtected2 = NULL;
- cn_cbor *pArray = NULL;
- cn_cbor *cn = NULL;
+ cn_cbor *pcborBody2 = nullptr;
+ cn_cbor *pcborProtected2 = nullptr;
+ cn_cbor *pArray = nullptr;
+ cn_cbor *cn = nullptr;
size_t cbToSign;
- byte *pbToSign = NULL;
+ byte *pbToSign = nullptr;
bool f;
int alg;
- pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (pArray == NULL) {
- if (perr != NULL) {
+ pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (pArray == nullptr) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_OUT_OF_MEMORY;
}
errorReturn:
- if (pcborBody2 != NULL) {
+ if (pcborBody2 != nullptr) {
CN_CBOR_FREE(pcborBody2, context);
}
- if (pcborProtected2 != NULL) {
+ if (pcborProtected2 != nullptr) {
CN_CBOR_FREE(pcborProtected2, context);
}
- if (pArray != NULL) {
+ if (pArray != nullptr) {
COSE_FREE(pArray, context);
}
- if (pbToSign != NULL) {
+ if (pbToSign != nullptr) {
COSE_FREE(pbToSign, context);
}
return false;
@@ -490,7 +490,7 @@
cn = _COSE_map_get_int(
&pSigner->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
goto errorReturn;
}
@@ -551,11 +551,11 @@
COSE_KEY *pKey,
cose_errback *perr)
{
- byte *pbToSign = NULL;
+ byte *pbToSign = nullptr;
int alg;
- const cn_cbor *cn = NULL;
+ const cn_cbor *cn = nullptr;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
size_t cbToSign;
bool fRet = false;
@@ -566,7 +566,7 @@
cn = _COSE_map_get_int(
&pSign->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
goto errorReturn;
}
@@ -631,7 +631,7 @@
fRet = true;
errorReturn:
- if (pbToSign != NULL) {
+ if (pbToSign != nullptr) {
COSE_FREE(pbToSign, context);
}
diff --git a/src/SignerInfo.cpp b/src/SignerInfo.cpp
index 292e21d..55ac6f0 100644
--- a/src/SignerInfo.cpp
+++ b/src/SignerInfo.cpp
@@ -16,7 +16,7 @@
#if INCLUDE_SIGN || INCLUDE_COUNTERSIGNATURE
#if INCLUDE_SIGN
-COSE *SignerRoot = NULL;
+COSE *SignerRoot = nullptr;
bool IsValidSignerHandle(HCOSE_SIGNER h)
{
@@ -34,7 +34,7 @@
}
_COSE_Release(&pSigner->m_message);
- if (pSigner->m_pkey != NULL) {
+ if (pSigner->m_pkey != nullptr) {
COSE_KEY_Free((HCOSE_KEY)pSigner->m_pkey);
}
@@ -71,18 +71,18 @@
{
COSE_SignerInfo *pobj =
(COSE_SignerInfo *)COSE_CALLOC(1, sizeof(COSE_SignerInfo), context);
- if (pobj == NULL) {
- if (perror != NULL) {
+ if (pobj == nullptr) {
+ if (perror != nullptr) {
perror->err = COSE_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
if (!_COSE_SignerInfo_Init(COSE_INIT_FLAGS_NO_CBOR_TAG, pobj,
COSE_recipient_object, CBOR_CONTEXT_PARAM_COMMA perror)) {
_COSE_SignerInfo_Release(pobj);
COSE_FREE(pobj, context);
- return NULL;
+ return nullptr;
}
_COSE_InsertInList(&SignerRoot, &pobj->m_message);
@@ -105,10 +105,10 @@
{
COSE_SignerInfo *pSigner = pIn;
- if (pSigner == NULL) {
+ if (pSigner == nullptr) {
pSigner =
(COSE_SignerInfo *)COSE_CALLOC(1, sizeof(COSE_SignerInfo), context);
- CHECK_CONDITION(pSigner != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pSigner != nullptr, COSE_ERR_OUT_OF_MEMORY);
}
CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
@@ -119,18 +119,18 @@
}
#if INCLUDE_SIGN
- if (pIn == NULL) {
+ if (pIn == nullptr) {
_COSE_InsertInList(&SignerRoot, &pSigner->m_message);
}
#endif
return pSigner;
errorReturn:
- if (pSigner != NULL && pIn == NULL) {
+ if (pSigner != nullptr && pIn == nullptr) {
_COSE_SignerInfo_Release(pSigner);
COSE_FREE(pSigner, context);
}
- return NULL;
+ return nullptr;
}
static bool BuildToBeSigned(byte **ppbToSign,
@@ -143,82 +143,82 @@
const char *const contextString,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- cn_cbor *pArray = NULL;
+ cn_cbor *pArray = nullptr;
cn_cbor_errback cbor_error;
size_t cbToSign;
- byte *pbToSign = NULL;
+ byte *pbToSign = nullptr;
bool f = false;
- cn_cbor *cn = NULL;
+ cn_cbor *cn = nullptr;
if (false) {
errorReturn:
- if (cn != NULL) {
+ if (cn != nullptr) {
CN_CBOR_FREE(cn, context);
}
- if (pArray != NULL) {
+ if (pArray != nullptr) {
CN_CBOR_FREE(pArray, context);
}
- if (pbToSign != NULL) {
+ if (pbToSign != nullptr) {
COSE_FREE(pbToSign, context);
}
return f;
}
pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pArray != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pArray != nullptr, cbor_error);
cn = cn_cbor_string_create(
contextString, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
if (pcborProtected->length == 1 && (pcborProtected->v.bytes[0] == 0xa0)) {
cn =
- cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
+ cn_cbor_data_create(nullptr, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cn = cn_cbor_data_create(pcborProtected->v.bytes,
(int)pcborProtected->length, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
if ((pcborProtectedSign->length == 1) &&
(pcborProtectedSign->v.bytes[0] == 0xa0)) {
cn =
- cn_cbor_data_create(NULL, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
+ cn_cbor_data_create(nullptr, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
else {
cn = cn_cbor_data_create(pcborProtectedSign->v.bytes,
(int)pcborProtectedSign->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
}
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cn = cn_cbor_data_create(
pbExternal, (int)cbExternal, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cn = cn_cbor_data_create(pcborBody->v.bytes, (int)pcborBody->length,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cn != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn != nullptr, cbor_error);
CHECK_CONDITION_CBOR(
cn_cbor_array_append(pArray, cn, &cbor_error), cbor_error);
- cn = NULL;
+ cn = nullptr;
cbToSign = cn_cbor_encode_size(pArray);
CHECK_CONDITION(cbToSign > 0, COSE_ERR_CBOR);
pbToSign = (byte *)COSE_CALLOC(cbToSign, 1, context);
- CHECK_CONDITION(pbToSign != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbToSign != nullptr, COSE_ERR_OUT_OF_MEMORY);
const ssize_t writtenBits =
cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray);
CHECK_CONDITION(writtenBits >= 0, COSE_ERR_CBOR);
@@ -226,7 +226,7 @@
*ppbToSign = pbToSign;
*pcbToSign = cbToSign;
- pbToSign = NULL;
+ pbToSign = nullptr;
f = true;
goto errorReturn;
}
@@ -240,20 +240,20 @@
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_message.m_allocContext;
#endif
- cn_cbor *pcborProtectedSign = NULL;
- cn_cbor *pArray = NULL;
- cn_cbor *cnAlgorithm = NULL;
+ cn_cbor *pcborProtectedSign = nullptr;
+ cn_cbor *pArray = nullptr;
+ cn_cbor *cnAlgorithm = nullptr;
size_t cbToSign;
- byte *pbToSign = NULL;
+ byte *pbToSign = nullptr;
int alg;
bool fRet = false;
- pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(pArray != NULL, COSE_ERR_OUT_OF_MEMORY);
+ pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(pArray != nullptr, COSE_ERR_OUT_OF_MEMORY);
cnAlgorithm = _COSE_map_get_int(
&pSigner->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cnAlgorithm == NULL) {
+ if (cnAlgorithm == nullptr) {
goto errorReturn;
}
@@ -269,7 +269,7 @@
}
pcborProtectedSign = _COSE_encode_protected(&pSigner->m_message, perr);
- if (pcborProtectedSign == NULL) {
+ if (pcborProtectedSign == nullptr) {
goto errorReturn;
}
@@ -322,7 +322,7 @@
}
#if INCLUDE_COUNTERSIGNATURE
- if (pSigner->m_message.m_counterSigners != NULL) {
+ if (pSigner->m_message.m_counterSigners != nullptr) {
if (!_COSE_CounterSign_Sign(
&pSigner->m_message, CBOR_CONTEXT_PARAM_COMMA perr)) {
goto errorReturn;
@@ -333,10 +333,10 @@
fRet = true;
errorReturn:
- if (pArray != NULL) {
+ if (pArray != nullptr) {
COSE_FREE(pArray, context);
}
- if (pbToSign != NULL) {
+ if (pbToSign != nullptr) {
COSE_FREE(pbToSign, context);
}
return fRet;
@@ -356,12 +356,12 @@
CHECK_CONDITION(IsValidKeyHandle(pKey), COSE_ERR_INVALID_HANDLE);
p = (COSE_SignerInfo *)h;
- if (p->m_pkey != NULL) {
+ if (p->m_pkey != nullptr) {
COSE_KEY_Free((HCOSE_KEY)p->m_pkey);
}
COSE_KEY *pcose = (COSE_KEY *)pKey;
p->m_pkey = pcose;
- if (pcose != NULL) {
+ if (pcose != nullptr) {
pcose->m_refCount += 1;
}
@@ -370,21 +370,21 @@
bool COSE_Signer_SetKey(HCOSE_SIGNER h, const cn_cbor *pKey, cose_errback *perr)
{
- HCOSE_KEY cose = NULL;
+ HCOSE_KEY cose = nullptr;
bool fRet = false;
#ifdef USE_CBOR_CONTEXT
- cn_cbor_context *context = NULL;
+ cn_cbor_context *context = nullptr;
#endif
- CHECK_CONDITION(pKey != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKey != nullptr, COSE_ERR_INVALID_PARAMETER);
cose = COSE_KEY_FromCbor((cn_cbor*) pKey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(cose != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(cose != nullptr, COSE_ERR_OUT_OF_MEMORY);
fRet =COSE_Signer_SetKey2(h, cose, perr);
errorReturn:
- if (cose != NULL) {
+ if (cose != nullptr) {
COSE_KEY_Free(cose);
}
return fRet;
@@ -412,7 +412,7 @@
cose_errback *perr)
{
if (!IsValidSignerHandle(hcose)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
return false;
@@ -429,7 +429,7 @@
const char *const contextString,
cose_errback *perr)
{
- byte *pbToBeSigned = NULL;
+ byte *pbToBeSigned = nullptr;
int alg = 0;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_message.m_allocContext;
@@ -439,9 +439,9 @@
const cn_cbor *cn = _COSE_map_get_int(
&pSigner->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
- if (cn == NULL) {
+ if (cn == nullptr) {
errorReturn:
- if (pbToBeSigned != NULL) {
+ if (pbToBeSigned != nullptr) {
COSE_FREE(pbToBeSigned, context);
}
@@ -463,7 +463,7 @@
cn_cbor *cnProtected =
_COSE_arrayget_int(&pSigner->m_message, INDEX_PROTECTED);
CHECK_CONDITION(
- (cnProtected != NULL) && (cnProtected->type == CN_CBOR_BYTES),
+ (cnProtected != nullptr) && (cnProtected->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
// Build authenticated data
@@ -477,7 +477,7 @@
cn_cbor *cnSignature =
_COSE_arrayget_int(&pSigner->m_message, INDEX_SIGNATURE);
CHECK_CONDITION(
- (cnSignature != NULL) && (cnSignature->type == CN_CBOR_BYTES),
+ (cnSignature != nullptr) && (cnSignature->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
switch (alg) {
@@ -533,10 +533,10 @@
cose_errback *perr)
{
if (!IsValidSignerHandle(h)) {
- if (perr != NULL) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_HANDLE;
}
- return NULL;
+ return nullptr;
}
return _COSE_map_get_int((COSE *)h, key, flags, perr);
@@ -549,7 +549,7 @@
cose_errback *perr)
{
CHECK_CONDITION(IsValidSignerHandle(h), COSE_ERR_INVALID_HANDLE);
- CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(value != nullptr, COSE_ERR_INVALID_PARAMETER);
return _COSE_map_put(
&((COSE_SignerInfo *)h)->m_message, key, value, flags, perr);
diff --git a/src/bcrypt.cpp b/src/bcrypt.cpp
index c8f8b55..6739751 100644
--- a/src/bcrypt.cpp
+++ b/src/bcrypt.cpp
@@ -15,37 +15,37 @@
int cbAuthData)
{
NTSTATUS err;
- BCRYPT_ALG_HANDLE hAlg = NULL;
- BCRYPT_KEY_DATA_BLOB_HEADER *pHdr = NULL;
- BCRYPT_KEY_HANDLE hKey = NULL;
+ BCRYPT_ALG_HANDLE hAlg = nullptr;
+ BCRYPT_KEY_DATA_BLOB_HEADER *pHdr = nullptr;
+ BCRYPT_KEY_HANDLE hKey = nullptr;
BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO authInfo = {0};
byte rgbTag[16];
int cbOut;
- byte *pbOut = NULL;
+ byte *pbOut = nullptr;
- err = BCryptOpenAlgorithmProvider(&hAlg, "AES_CCM", NULL, 0);
+ err = BCryptOpenAlgorithmProvider(&hAlg, "AES_CCM", nullptr, 0);
if (err != 0) {
error:
- if (pbOut != NULL)
+ if (pbOut != nullptr)
free(pbOut);
- if (pHdr != NULL)
+ if (pHdr != nullptr)
free(pHdr);
- if (hKey != NULL)
+ if (hKey != nullptr)
BCryptDestroyKey(hKey);
- if (hAlg != NULL)
+ if (hAlg != nullptr)
BCryptCloseAlgorithmProvider(hAlg, 0);
return false;
}
pHdr = (BCRYPT_KEY_DATA_BLOB_HEADER *)malloc(sizeof(*pHdr) + KSize / 8);
- if (pHdr == NULL)
+ if (pHdr == nullptr)
goto error;
pHdr->dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC;
pHdr->dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1;
pHdr->cbKeyData = KSize / 8;
memcpy(&pHdr[1], pcose->pbKey, pcose->cbKey);
- err = BCryptImportKey(hAlg, NULL, BCRYPT_KEY_DATA_BLOB, &hKey, NULL, 0,
+ err = BCryptImportKey(hAlg, nullptr, BCRYPT_KEY_DATA_BLOB, &hKey, nullptr, 0,
pHdr, (sizeof(*pHdr) + KSize / 8), 0);
if (err != 0)
goto error;
@@ -57,22 +57,22 @@
authInfo.cbAuthData = cbAuthData;
authInfo.pbTag = rgbTag;
authInfo.cbTag = TSize / 8;
- authInfo.pbMacContext = NULL;
+ authInfo.pbMacContext = nullptr;
cbOut = pcose->cbContent + TSize / 8;
pbOut = (byte *)malloc(cbOut);
- if (pbOut == NULL)
+ if (pbOut == nullptr)
goto error;
err = BCryptEncrypt(hKey, pcose->pbContent, pcose->cbContent, &authInfo,
- NULL, 0, pbOut, cbOut, 0, 0);
+ nullptr, 0, pbOut, cbOut, 0, 0);
if (err != 0)
goto error;
memcpy(&pbOut[pcose->cbContent], rgbTag, TSize / 8);
cn_cbor_mapput_int(pcose->m_message.m_cbor, COSE_Header_Ciphertext,
- cn_cbor_data_create(pbOut, cbOut, NULL), NULL);
+ cn_cbor_data_create(pbOut, cbOut, nullptr), nullptr);
return true;
}
diff --git a/src/cbor.cpp b/src/cbor.cpp
index d26c850..a28a154 100644
--- a/src/cbor.cpp
+++ b/src/cbor.cpp
@@ -60,7 +60,7 @@
cn_cbor *cb_temp2;
if (!cb_array || !cb_value || cb_array->type != CN_CBOR_ARRAY) {
- if (errp != NULL) {
+ if (errp != nullptr) {
errp->err = CN_CBOR_ERR_INVALID_PARAMETER;
}
return false;
@@ -76,15 +76,15 @@
cb_array->last_child = cb_value;
}
cb_array->first_child = cb_value;
- cb_temp->parent = NULL;
- cb_temp->next = NULL;
+ cb_temp->parent = nullptr;
+ cb_temp->next = nullptr;
cn_cbor_free(cb_temp CBOR_CONTEXT_PARAM);
return true;
}
return cn_cbor_array_append(cb_array, cb_value, errp);
}
- if (cb_array->first_child == NULL) {
+ if (cb_array->first_child == nullptr) {
INIT_CB(cb_temp2);
cb_array->first_child = cb_array->last_child = cb_temp2;
cb_temp2->parent = cb_array;
@@ -94,7 +94,7 @@
cb_temp = cb_array->first_child;
for (i = 1; i < index; i++) {
- if (cb_temp->next == NULL) {
+ if (cb_temp->next == nullptr) {
INIT_CB(cb_temp2);
cb_temp2->type = CN_CBOR_INVALID;
cb_temp->next = cb_temp2;
@@ -106,7 +106,7 @@
cb_temp = cb_temp->next;
}
- if (cb_temp->next == NULL) {
+ if (cb_temp->next == nullptr) {
cb_temp->next = cb_value;
cb_value->parent = cb_array;
cb_array->last_child = cb_value;
@@ -122,8 +122,8 @@
cb_array->last_child = cb_value;
}
- cb_temp2->next = NULL;
- cb_temp2->parent = NULL;
+ cb_temp2->next = nullptr;
+ cb_temp2->parent = nullptr;
cn_cbor_free(cb_temp2 CBOR_CONTEXT_PARAM);
return true;
@@ -132,15 +132,15 @@
cn_cbor *cn_cbor_clone(const cn_cbor *pIn,
CBOR_CONTEXT_COMMA cn_cbor_errback *pcn_cbor_error)
{
- cn_cbor *pOut = NULL;
+ cn_cbor *pOut = nullptr;
char *sz;
unsigned char *pb;
switch (pIn->type) {
case CN_CBOR_TEXT:
sz = (char*)( CN_CBOR_CALLOC(pIn->length + 1, 1, context));
- if (sz == NULL) {
- return NULL;
+ if (sz == nullptr) {
+ return nullptr;
}
memcpy(sz, pIn->v.str, pIn->length);
sz[pIn->length] = 0;
@@ -155,8 +155,8 @@
case CN_CBOR_BYTES:
pb = static_cast<unsigned char *> (CN_CBOR_CALLOC(
(int)pIn->length, 1, context));
- if (pb == NULL) {
- return NULL;
+ if (pb == nullptr) {
+ return nullptr;
}
memcpy(pb, pIn->v.bytes, pIn->length);
pOut = cn_cbor_data_create2(
@@ -176,11 +176,11 @@
CBOR_CONTEXT_COMMA cn_cbor_errback *perr)
{
cn_cbor *pcnTag = CN_CALLOC(context);
- if (pcnTag == NULL) {
- if (perr != NULL) {
+ if (pcnTag == nullptr) {
+ if (perr != nullptr) {
perr->err = CN_CBOR_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
pcnTag->type = CN_CBOR_TAG;
@@ -195,11 +195,11 @@
CBOR_CONTEXT_COMMA cn_cbor_errback *errp)
{
cn_cbor *pcn = CN_CALLOC(context);
- if (pcn == NULL) {
- if (errp != NULL) {
+ if (pcn == nullptr) {
+ if (errp != nullptr) {
errp->err = CN_CBOR_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
pcn->type = CN_CBOR_FALSE + (boolValue != 0);
@@ -209,11 +209,11 @@
cn_cbor *cn_cbor_null_create(CBOR_CONTEXT_COMMA cn_cbor_errback *errp)
{
cn_cbor *pcn = CN_CALLOC(context);
- if (pcn == NULL) {
- if (errp != NULL) {
+ if (pcn == nullptr) {
+ if (errp != nullptr) {
errp->err = CN_CBOR_ERR_OUT_OF_MEMORY;
}
- return NULL;
+ return nullptr;
}
pcn->type = CN_CBOR_NULL;
return pcn;
@@ -222,6 +222,6 @@
size_t cn_cbor_encode_size(cn_cbor *object)
{
- ssize_t size = cn_cbor_encoder_write(NULL, 0, 0, object);
+ ssize_t size = cn_cbor_encoder_write(nullptr, 0, 0, object);
return size >= 0 ? size : 0;
}
diff --git a/src/cose_int.h b/src/cose_int.h
index 802705d..2b69b48 100644
--- a/src/cose_int.h
+++ b/src/cose_int.h
@@ -128,8 +128,8 @@
/**
* Allocate enough space for 1 `cn_cbor` structure.
*
- * @param[in] ctx The allocation context, or NULL for calloc.
- * @return A pointer to a `cn_cbor` or NULL on failure
+ * @param[in] ctx The allocation context, or nullptr for calloc.
+ * @return A pointer to a `cn_cbor` or nullptr on failure
*/
#define CN_CALLOC(ctx) \
((ctx) && (ctx)->calloc_func) \
@@ -139,7 +139,7 @@
/**
* Allocate space required
*
- * @param[in] ctx The allocation context, or NULL for normal calloc.
+ * @param[in] ctx The allocation context, or nullptr for normal calloc.
* @param[in] count Number of items to allocate
* @param[in] size Size of item to allocate
* @return A pointer to the object needed
@@ -360,7 +360,7 @@
{ \
if (!(condition)) { \
DO_ASSERT; \
- if (perr != NULL) { \
+ if (perr != nullptr) { \
perr->err = error; \
} \
goto errorReturn; \
@@ -370,7 +370,7 @@
{ \
if ((condition)) { \
DO_ASSERT; \
- if (perr != NULL) { \
+ if (perr != nullptr) { \
perr->err = error; \
} \
goto errorReturn; \
@@ -379,7 +379,7 @@
#define FAIL_CONDITION(error) \
{ \
DO_ASSERT; \
- if (perr != NULL) { \
+ if (perr != nullptr) { \
perr->err = error; \
} \
goto errorReturn; \
@@ -388,7 +388,7 @@
{ \
if (!(condition)) { \
DO_ASSERT; \
- if (perr != NULL) { \
+ if (perr != nullptr) { \
perr->err = _MapFromCBOR(error); \
} \
goto errorReturn; \
diff --git a/src/mbedtls.cpp b/src/mbedtls.cpp
index bb87940..d22760b 100644
--- a/src/mbedtls.cpp
+++ b/src/mbedtls.cpp
@@ -38,10 +38,10 @@
{
mbedtls_ccm_context ctx;
int cbOut = 0;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
size_t NSize = 15 - (LSize / 8);
byte rgbIV[15] = {0};
- const cn_cbor *pIV = NULL;
+ const cn_cbor *pIV = nullptr;
mbedtls_cipher_id_t cipher;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
@@ -50,14 +50,14 @@
mbedtls_ccm_init(&ctx);
// Setup the IV/Nonce and put it into the message
- pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, NULL);
- if ((pIV == NULL) || (pIV->type != CN_CBOR_BYTES)) {
- if (perr != NULL) {
+ pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, nullptr);
+ if ((pIV == nullptr) || (pIV->type != CN_CBOR_BYTES)) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
mbedtls_ccm_free(&ctx);
@@ -75,7 +75,7 @@
cbOut = (int)cbCrypto - TSize;
rgbOut = (byte *)COSE_CALLOC(cbOut, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
!mbedtls_ccm_auth_decrypt(&ctx, cbOut, rgbIV, NSize, pbAuthData,
@@ -100,17 +100,17 @@
{
mbedtls_ccm_context ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
size_t NSize = 15 - (LSize / 8);
- const cn_cbor *cbor_iv = NULL;
- cn_cbor *cbor_iv_t = NULL;
+ const cn_cbor *cbor_iv = nullptr;
+ cn_cbor *cbor_iv_t = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
- cn_cbor *cnTmp = NULL;
+ cn_cbor *cnTmp = nullptr;
mbedtls_cipher_id_t cipher;
byte rgbIV[16];
- byte *pbIV = NULL;
+ byte *pbIV = nullptr;
cn_cbor_errback cbor_error;
mbedtls_ccm_init(&ctx);
@@ -120,21 +120,21 @@
// Setup the IV/Nonce and put it into the message
cbor_iv =
_COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, perr);
- if (cbor_iv == NULL) {
+ if (cbor_iv == nullptr) {
pbIV = (byte *) COSE_CALLOC(NSize, 1, context);
- CHECK_CONDITION(pbIV != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbIV != nullptr, COSE_ERR_OUT_OF_MEMORY);
rand_bytes(pbIV, NSize);
memcpy(rgbIV, pbIV, NSize);
cbor_iv_t = cn_cbor_data_create2(
pbIV, NSize, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor_iv_t != NULL, cbor_error);
- pbIV = NULL;
+ CHECK_CONDITION_CBOR(cbor_iv_t != nullptr, cbor_error);
+ pbIV = nullptr;
if (!_COSE_map_put(&pcose->m_message, COSE_Header_IV, cbor_iv_t,
COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor_iv_t = NULL;
+ cbor_iv_t = nullptr;
}
else {
CHECK_CONDITION(
@@ -153,7 +153,7 @@
cbOut = pcose->cbContent; // M00BUG - This is a missing call?
rgbOut = (byte *)COSE_CALLOC(cbOut + TSize, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(!mbedtls_ccm_encrypt_and_tag(&ctx, pcose->cbContent, rgbIV,
NSize, pbAuthData, cbAuthData, pcose->pbContent, rgbOut,
@@ -161,30 +161,30 @@
COSE_ERR_CRYPTO_FAIL);
cnTmp = cn_cbor_data_create2(
- rgbOut, (int)pcose->cbContent + TSize, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- rgbOut = NULL;
+ rgbOut, (int)pcose->cbContent + TSize, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cnTmp, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- cnTmp = NULL;
+ cnTmp = nullptr;
mbedtls_ccm_free(&ctx);
return true;
errorReturn:
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
- if (cbor_iv_t != NULL) {
+ if (cbor_iv_t != nullptr) {
COSE_FREE(cbor_iv_t, context);
}
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
- if (cnTmp != NULL) {
+ if (cnTmp != nullptr) {
COSE_FREE(cnTmp, context);
}
mbedtls_ccm_free(&ctx);
@@ -204,9 +204,9 @@
{
mbedtls_gcm_context ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
byte rgbIV[15] = {0};
- const cn_cbor *pIV = NULL;
+ const cn_cbor *pIV = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
@@ -217,14 +217,14 @@
// Setup the IV/Nonce and put it into the message
- pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, NULL);
- if ((pIV == NULL) || (pIV->type != CN_CBOR_BYTES)) {
- if (perr != NULL) {
+ pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, nullptr);
+ if ((pIV == nullptr) || (pIV->type != CN_CBOR_BYTES)) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
mbedtls_gcm_free(&ctx);
@@ -257,7 +257,7 @@
cbOut = (int)cbCrypto - TSize;
rgbOut = (byte *)COSE_CALLOC(cbOut, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
// Process content
@@ -291,11 +291,11 @@
cose_errback *perr)
{
mbedtls_gcm_context ctx;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
byte rgbIV[16] = {0};
- byte *pbIV = NULL;
- const cn_cbor *cbor_iv = NULL;
- cn_cbor *cbor_iv_t = NULL;
+ byte *pbIV = nullptr;
+ const cn_cbor *cbor_iv = nullptr;
+ cn_cbor *cbor_iv_t = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
@@ -303,13 +303,13 @@
if (false) {
errorReturn:
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
- if (cbor_iv_t != NULL) {
+ if (cbor_iv_t != nullptr) {
COSE_FREE(cbor_iv_t, context);
}
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
mbedtls_gcm_free(&ctx);
@@ -323,21 +323,21 @@
cbor_iv =
_COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, perr);
- if (cbor_iv == NULL) {
+ if (cbor_iv == nullptr) {
pbIV = (byte*) COSE_CALLOC(96, 1, context);
- CHECK_CONDITION(pbIV != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbIV != nullptr, COSE_ERR_OUT_OF_MEMORY);
rand_bytes(pbIV, 96 / 8);
memcpy(rgbIV, pbIV, 96 / 8);
cbor_iv_t = cn_cbor_data_create2(
pbIV, 96 / 8, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor_iv_t != NULL, cbor_error);
- pbIV = NULL;
+ CHECK_CONDITION_CBOR(cbor_iv_t != nullptr, cbor_error);
+ pbIV = nullptr;
if (!_COSE_map_put(&pcose->m_message, COSE_Header_IV, cbor_iv_t,
COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor_iv_t = NULL;
+ cbor_iv_t = nullptr;
}
else {
CHECK_CONDITION(
@@ -368,7 +368,7 @@
COSE_ERR_CRYPTO_FAIL);
rgbOut = (byte *)COSE_CALLOC(pcose->cbContent + 128 / 8, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION0(
mbedtls_gcm_update(&ctx, pcose->cbContent, pcose->pbContent, rgbOut),
@@ -379,16 +379,16 @@
COSE_ERR_CRYPTO_FAIL);
cn_cbor *cnTmp = cn_cbor_data_create2(
- rgbOut, (int)pcose->cbContent + 128 / 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- rgbOut = NULL;
+ rgbOut, (int)pcose->cbContent + 128 / 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cnTmp, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
mbedtls_gcm_free(&ctx);
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
return true;
@@ -404,11 +404,11 @@
size_t *pcbDigest,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- const mbedtls_md_info_t *pmd = NULL;
+ const mbedtls_md_info_t *pmd = nullptr;
mbedtls_md_type_t mdType;
int cbSalt = 0;
- cn_cbor *cnSalt = NULL;
+ cn_cbor *cnSalt = nullptr;
unsigned int cbDigest;
if (0) {
@@ -435,16 +435,16 @@
}
pmd = mbedtls_md_info_from_type(mdType);
- if (pmd == NULL) {
+ if (pmd == nullptr) {
goto errorReturn;
}
cbSalt = 0;
- const byte *pbSalt = NULL;
+ const byte *pbSalt = nullptr;
cnSalt = _COSE_map_get_int(pcose, COSE_Header_HKDF_salt, COSE_BOTH, perr);
- if (cnSalt != NULL) {
+ if (cnSalt != nullptr) {
pbSalt = cnSalt->v.bytes;
cbSalt = (int)cnSalt->length;
}
@@ -470,7 +470,7 @@
{
UNUSED(pcose);
mbedtls_md_type_t mdType;
- const mbedtls_md_info_t *pmd = NULL;
+ const mbedtls_md_info_t *pmd = nullptr;
unsigned int cbDigest = 0;
@@ -498,7 +498,7 @@
}
pmd = mbedtls_md_info_from_type(mdType);
- if (pmd == NULL) {
+ if (pmd == nullptr) {
goto errorReturn;
}
@@ -521,12 +521,12 @@
size_t cbAuthData,
cose_errback *perr)
{
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
// unsigned int cbOut;
mbedtls_md_context_t contx;
const char *md_name;
const struct mbedtls_md_info_t *info;
- cn_cbor *cbor = NULL;
+ cn_cbor *cbor = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
@@ -549,7 +549,7 @@
if (0) {
errorReturn:
- if (cbor != NULL) {
+ if (cbor != nullptr) {
COSE_FREE(cbor, context);
}
COSE_FREE(rgbOut, context);
@@ -562,7 +562,7 @@
mbedtls_md_setup(&contx, info, 1);
rgbOut = (byte *) COSE_CALLOC(mbedtls_md_get_size(info), 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
!(mbedtls_md_hmac_starts(&contx, pbKey, cbKey)), COSE_ERR_CRYPTO_FAIL);
@@ -572,11 +572,11 @@
!(mbedtls_md_hmac_finish(&contx, rgbOut)), COSE_ERR_CRYPTO_FAIL);
cbor = cn_cbor_data_create2(
- rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cbor != NULL, COSE_ERR_OUT_OF_MEMORY);
- rgbOut = NULL;
+ rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cbor != nullptr, COSE_ERR_OUT_OF_MEMORY);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cbor, INDEX_MAC_TAG,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
mbedtls_md_free(&contx);
@@ -595,7 +595,7 @@
mbedtls_md_context_t contx;
const char *md_name;
const struct mbedtls_md_info_t *info;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
unsigned int cbOut;
bool f = false;
unsigned int i;
@@ -606,7 +606,7 @@
if (false) {
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
mbedtls_md_free(&contx);
@@ -635,7 +635,7 @@
cbOut = mbedtls_md_get_size(info);
rgbOut = (byte*) COSE_CALLOC(cbOut, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
!(mbedtls_md_hmac_starts(&contx, pbKey, cbKey)), COSE_ERR_CRYPTO_FAIL);
@@ -645,7 +645,7 @@
!(mbedtls_md_hmac_finish(&contx, rgbOut)), COSE_ERR_CRYPTO_FAIL);
cn_cbor *cn = _COSE_arrayget_int(&pcose->m_message, INDEX_MAC_TAG);
- CHECK_CONDITION(cn != NULL, COSE_ERR_CBOR);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_CBOR);
if (cn->length > (int)cbOut) {
return false;
@@ -676,7 +676,7 @@
mbedtls_ecp_group_id groupId;
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_Type);
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
if (p->type == CN_CBOR_UINT) {
CHECK_CONDITION(
p->v.uint == COSE_Key_Type_EC2, COSE_ERR_INVALID_PARAMETER);
@@ -687,7 +687,7 @@
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_Curve);
CHECK_CONDITION(
- (p != NULL) && (p->type == CN_CBOR_UINT), COSE_ERR_INVALID_PARAMETER);
+ (p != nullptr) && (p->type == CN_CBOR_UINT), COSE_ERR_INVALID_PARAMETER);
switch (p->v.uint) {
case 1: // P-256
@@ -711,12 +711,12 @@
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_X);
CHECK_CONDITION(
- (p != NULL) && (p->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
+ (p != nullptr) && (p->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(p->length == cbGroup, COSE_ERR_INVALID_PARAMETER);
memcpy(rgbKey + 1, p->v.str, p->length);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_Y);
- CHECK_CONDITION((p != NULL), COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION((p != nullptr), COSE_ERR_INVALID_PARAMETER);
if (p->type == CN_CBOR_BYTES) {
rgbKey[0] = 0x04;
cbKey = cbGroup * 2 + 1;
@@ -748,7 +748,7 @@
COSE_ERR_INVALID_PARAMETER);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_d);
- if (p != NULL) {
+ if (p != nullptr) {
CHECK_CONDITION(p->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
mbedtls_mpi_read_binary(&keypair->d, p->v.bytes, p->length) == 0,
@@ -770,7 +770,7 @@
{
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
byte rgbDigest[MBEDTLS_MD_MAX_SIZE];
- uint8_t *pbSig = NULL;
+ uint8_t *pbSig = nullptr;
cn_cbor_errback cbor_error;
int cbR;
mbedtls_md_type_t mdType;
@@ -781,7 +781,7 @@
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_allocContext;
#endif
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
bool result = false;
mbedtls_ecp_keypair_init(&keypair);
@@ -811,7 +811,7 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
pmdInfo = mbedtls_md_info_from_type(mdType);
- CHECK_CONDITION(pmdInfo != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pmdInfo != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(mbedtls_md(pmdInfo, rgbToSign, cbToSign, rgbDigest) == 0,
COSE_ERR_INVALID_PARAMETER);
@@ -822,7 +822,7 @@
cbR = (keypair.grp.nbits + 7) / 8;
pbSig = (byte *) COSE_CALLOC(cbR, 2, context);
- CHECK_CONDITION(pbSig != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbSig != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
mbedtls_mpi_write_binary(&r, pbSig, cbR) == 0, COSE_ERR_INTERNAL);
@@ -831,14 +831,14 @@
p = cn_cbor_data_create(
pbSig, cbR * 2, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION(
- _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA NULL),
+ _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- p = NULL;
- pbSig = NULL;
+ p = nullptr;
+ pbSig = nullptr;
result = true;
errorReturn:
@@ -895,12 +895,12 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
pmdInfo = mbedtls_md_info_from_type(mdType);
- CHECK_CONDITION(pmdInfo != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pmdInfo != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(mbedtls_md(pmdInfo, rgbToSign, cbToSign, rgbDigest) == 0,
COSE_ERR_INVALID_PARAMETER);
pSig = _COSE_arrayget_int(pSigner, index);
- CHECK_CONDITION((pSig != NULL) && (pSig->type == CN_CBOR_BYTES),
+ CHECK_CONDITION((pSig != nullptr) && (pSig->type == CN_CBOR_BYTES),
COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
@@ -963,18 +963,18 @@
int cbContent,
cose_errback *perr)
{
- byte *pbOut = NULL;
+ byte *pbOut = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_encrypt.m_message.m_allocContext;
#endif
- cn_cbor *cnTmp = NULL;
+ cn_cbor *cnTmp = nullptr;
mbedtls_nist_kw_context ctx;
size_t cbOut;
mbedtls_nist_kw_init(&ctx);
pbOut = COSE_CALLOC(cbContent + 8, 1, context);
- CHECK_CONDITION(pbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION0(mbedtls_nist_kw_setkey(
&ctx, MBEDTLS_CIPHER_ID_AES, pbKeyIn, cbitKey, TRUE),
@@ -985,20 +985,20 @@
COSE_ERR_CRYPTO_FAIL);
cnTmp = cn_cbor_data_create(
- pbOut, (int)cbContent + 8, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- pbOut = NULL;
+ pbOut, (int)cbContent + 8, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ pbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_encrypt.m_message, cnTmp,
- INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA NULL),
+ INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- cnTmp = NULL;
+ cnTmp = nullptr;
mbedtls_nist_kw_free(&ctx);
return true;
errorReturn:
COSE_FREE(cnTmp, context);
- if (pbOut != NULL) {
+ if (pbOut != nullptr) {
COSE_FREE(pbOut, context);
}
mbedtls_nist_kw_free(&ctx);
@@ -1118,15 +1118,15 @@
int cbGroup = 0;
int cbsecret = 0;
- byte *pbsecret = NULL;
+ byte *pbsecret = nullptr;
bool fRet = false;
mbedtls_ecp_group_id groupId;
mbedtls_ecp_keypair keypair;
mbedtls_ecdh_context ctx;
mbedtls_mpi d;
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
mbedtls_mpi z;
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
int cose_group = 0;
mbedtls_ecp_group group = {MBEDTLS_ECP_DP_NONE};
@@ -1137,13 +1137,13 @@
if (false) {
errorReturn:
- if (pbsecret != NULL) {
+ if (pbsecret != nullptr) {
COSE_FREE(pbsecret, context);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
@@ -1157,7 +1157,7 @@
p = cn_cbor_mapget_int(pKeyPublic->m_cborKey, COSE_Key_EC_Curve);
CHECK_CONDITION(
- (p != NULL) && (p->type == CN_CBOR_UINT), COSE_ERR_INVALID_PARAMETER);
+ (p != nullptr) && (p->type == CN_CBOR_UINT), COSE_ERR_INVALID_PARAMETER);
switch (p->v.uint) {
case 1: // P-256
@@ -1181,7 +1181,7 @@
default:
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- p = NULL;
+ p = nullptr;
CHECK_CONDITION0(
mbedtls_ecp_group_load(&group, groupId), COSE_ERR_INVALID_PARAMETER);
@@ -1190,12 +1190,12 @@
goto errorReturn;
}
- if (*ppKeyPrivate == NULL) {
+ if (*ppKeyPrivate == nullptr) {
mbedtls_ecp_keypair privateKeyPair;
mbedtls_ecp_keypair_init(&privateKeyPair);
CHECK_CONDITION0(
- mbedtls_ecp_gen_key(groupId, &privateKeyPair, rand_bytes2, NULL),
+ mbedtls_ecp_gen_key(groupId, &privateKeyPair, rand_bytes2, nullptr),
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION0(
mbedtls_mpi_copy(&d, &privateKeyPair.d), COSE_ERR_CRYPTO_FAIL);
@@ -1211,82 +1211,82 @@
int cbSize = (int) (olen - 1) / 2;
pkey = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pkey != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pkey != nullptr, cbor_error);
p = cn_cbor_int_create(
cose_group, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_Curve, p,
CBOR_CONTEXT_PARAM_COMMA &cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
pbsecret = (byte *) COSE_CALLOC(cbSize, 1, context);
- CHECK_CONDITION(pbsecret != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbsecret != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbsecret, buff + 1, cbSize);
p = cn_cbor_data_create2(
pbsecret, (int)cbSize, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
- pbsecret = NULL;
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
+ pbsecret = nullptr;
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_X, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
pbsecret = (byte *) COSE_CALLOC(cbSize, 1, context);
- CHECK_CONDITION(pbsecret != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbsecret != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbsecret, buff + 1 + cbSize, cbSize);
p = cn_cbor_data_create2(
pbsecret, cbSize, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
- pbsecret = NULL;
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
+ pbsecret = nullptr;
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_Y, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
p = cn_cbor_int_create(
COSE_Key_Type_EC2, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_Type, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
COSE_KEY *coseKey = (COSE_KEY*) COSE_KEY_FromCbor(pkey, CBOR_CONTEXT_PARAM_COMMA perr);
- if (coseKey == NULL) {
+ if (coseKey == nullptr) {
goto errorReturn;
}
*ppKeyPrivate = coseKey;
- pkey = NULL;
+ pkey = nullptr;
}
else {
p = cn_cbor_mapget_int((*ppKeyPrivate)->m_cborKey, COSE_Key_EC_d);
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(p->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION0(mbedtls_mpi_read_binary(&d, p->v.bytes, p->length),
COSE_ERR_CRYPTO_FAIL);
- p = NULL;
+ p = nullptr;
}
CHECK_CONDITION0(
- mbedtls_ecdh_compute_shared(&group, &z, &keypair.Q, &d, NULL, NULL),
+ mbedtls_ecdh_compute_shared(&group, &z, &keypair.Q, &d, nullptr, nullptr),
COSE_ERR_CRYPTO_FAIL);
cbsecret = cbGroup;
pbsecret = (byte *) COSE_CALLOC(cbsecret, 1, context);
- CHECK_CONDITION(pbsecret != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbsecret != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION0(
mbedtls_mpi_write_binary(&z, pbsecret, cbsecret), COSE_ERR_CRYPTO_FAIL);
*ppbSecret = pbsecret;
*pcbSecret = cbsecret;
- pbsecret = NULL;
+ pbsecret = nullptr;
fRet = true;
goto errorReturn;
diff --git a/src/openssl.cpp b/src/openssl.cpp
index 129e9ec..addf8d4 100644
--- a/src/openssl.cpp
+++ b/src/openssl.cpp
@@ -29,7 +29,7 @@
HMAC_CTX *HMAC_CTX_new()
{
HMAC_CTX *foo = (HMAC_CTX *) malloc(sizeof(HMAC_CTX));
- if (foo != NULL) {
+ if (foo != nullptr) {
HMAC_CTX_init(foo);
}
return foo;
@@ -37,21 +37,21 @@
void HMAC_CTX_free(HMAC_CTX *foo)
{
- if (foo != NULL)
+ if (foo != nullptr)
free(foo);
}
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
{
- if (pr != NULL)
+ if (pr != nullptr)
*pr = sig->r;
- if (ps != NULL)
+ if (ps != nullptr)
*ps = sig->s;
}
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
{
- if (r == NULL || s == NULL)
+ if (r == nullptr || s == nullptr)
return 0;
BN_clear_free(sig->r);
BN_clear_free(sig->s);
@@ -74,29 +74,29 @@
{
EVP_CIPHER_CTX *ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
size_t NSize = 15 - (LSize / 8);
int outl = 0;
byte rgbIV[15] = {0};
- const cn_cbor *pIV = NULL;
+ const cn_cbor *pIV = nullptr;
const EVP_CIPHER *cipher;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(ctx != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(ctx != nullptr, COSE_ERR_OUT_OF_MEMORY);
// Setup the IV/Nonce and put it into the message
- pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, NULL);
- if ((pIV == NULL) || (pIV->type != CN_CBOR_BYTES)) {
- if (perr != NULL) {
+ pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, nullptr);
+ if ((pIV == nullptr) || (pIV->type != CN_CBOR_BYTES)) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
EVP_CIPHER_CTX_free(ctx);
@@ -125,7 +125,7 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
break;
}
- CHECK_CONDITION(EVP_DecryptInit_ex(ctx, cipher, NULL, NULL, NULL),
+ CHECK_CONDITION(EVP_DecryptInit_ex(ctx, cipher, nullptr, nullptr, nullptr),
COSE_ERR_DECRYPT_FAILED);
TSize /= 8; // Comes in in bits not bytes.
@@ -138,19 +138,19 @@
(void *)&pbCrypto[cbCrypto - TSize]),
COSE_ERR_DECRYPT_FAILED);
- CHECK_CONDITION(EVP_DecryptInit_ex(ctx, 0, NULL, pbKey, rgbIV),
+ CHECK_CONDITION(EVP_DecryptInit_ex(ctx, 0, nullptr, pbKey, rgbIV),
COSE_ERR_DECRYPT_FAILED);
CHECK_CONDITION(
- EVP_DecryptUpdate(ctx, NULL, &cbOut, NULL, (int)cbCrypto - TSize),
+ EVP_DecryptUpdate(ctx, nullptr, &cbOut, nullptr, (int)cbCrypto - TSize),
COSE_ERR_DECRYPT_FAILED);
cbOut = (int)cbCrypto - TSize;
rgbOut = (byte *)COSE_CALLOC(cbOut, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
- EVP_DecryptUpdate(ctx, NULL, &outl, pbAuthData, (int)cbAuthData),
+ EVP_DecryptUpdate(ctx, nullptr, &outl, pbAuthData, (int)cbAuthData),
COSE_ERR_DECRYPT_FAILED);
CHECK_CONDITION(
@@ -176,22 +176,22 @@
{
EVP_CIPHER_CTX *ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
size_t NSize = 15 - (LSize / 8);
int outl = 0;
- const cn_cbor *cbor_iv = NULL;
- cn_cbor *cbor_iv_t = NULL;
+ const cn_cbor *cbor_iv = nullptr;
+ cn_cbor *cbor_iv_t = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
- cn_cbor *cnTmp = NULL;
+ cn_cbor *cnTmp = nullptr;
const EVP_CIPHER *cipher;
byte rgbIV[16];
- byte *pbIV = NULL;
+ byte *pbIV = nullptr;
cn_cbor_errback cbor_error;
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
switch (cbKey * 8) {
case 128:
@@ -214,21 +214,21 @@
cbor_iv =
_COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, perr);
- if (cbor_iv == NULL) {
+ if (cbor_iv == nullptr) {
pbIV = (byte *) COSE_CALLOC(NSize, 1, context);
- CHECK_CONDITION(pbIV != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbIV != nullptr, COSE_ERR_OUT_OF_MEMORY);
rand_bytes(pbIV, NSize);
memcpy(rgbIV, pbIV, NSize);
cbor_iv_t = cn_cbor_data_create2(
pbIV, NSize, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor_iv_t != NULL, cbor_error);
- pbIV = NULL;
+ CHECK_CONDITION_CBOR(cbor_iv_t != nullptr, cbor_error);
+ pbIV = nullptr;
if (!_COSE_map_put(&pcose->m_message, COSE_Header_IV, cbor_iv_t,
COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor_iv_t = NULL;
+ cbor_iv_t = nullptr;
}
else {
CHECK_CONDITION(
@@ -239,7 +239,7 @@
// Setup and run the OpenSSL code
- CHECK_CONDITION(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL),
+ CHECK_CONDITION(EVP_EncryptInit_ex(ctx, cipher, nullptr, nullptr, nullptr),
COSE_ERR_CRYPTO_FAIL);
TSize /= 8; // Comes in in bits not bytes.
@@ -248,21 +248,21 @@
COSE_ERR_CRYPTO_FAIL);
// CHECK_CONDITION(EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_CCM_SET_IVLEN, NSize,
// 0), COSE_ERR_CRYPTO_FAIL);
- CHECK_CONDITION(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, TSize, NULL),
+ CHECK_CONDITION(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, TSize, nullptr),
COSE_ERR_CRYPTO_FAIL); // Say we are doing an 8 byte tag
CHECK_CONDITION(
- EVP_EncryptInit_ex(ctx, 0, NULL, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL);
+ EVP_EncryptInit_ex(ctx, 0, nullptr, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(EVP_EncryptUpdate(ctx, 0, &cbOut, 0, (int)pcose->cbContent),
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
- EVP_EncryptUpdate(ctx, NULL, &outl, pbAuthData, (int)cbAuthData),
+ EVP_EncryptUpdate(ctx, nullptr, &outl, pbAuthData, (int)cbAuthData),
COSE_ERR_CRYPTO_FAIL);
rgbOut = (byte *)COSE_CALLOC(cbOut + TSize, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(EVP_EncryptUpdate(ctx, rgbOut, &cbOut, pcose->pbContent,
(int)pcose->cbContent),
@@ -276,28 +276,28 @@
COSE_ERR_CRYPTO_FAIL);
cnTmp = cn_cbor_data_create2(
- rgbOut, (int)pcose->cbContent + TSize, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- rgbOut = NULL;
+ rgbOut, (int)pcose->cbContent + TSize, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cnTmp, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- cnTmp = NULL;
+ cnTmp = nullptr;
EVP_CIPHER_CTX_free(ctx);
return true;
errorReturn:
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
- if (cbor_iv_t != NULL) {
+ if (cbor_iv_t != nullptr) {
COSE_FREE(cbor_iv_t, context);
}
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
- if (cnTmp != NULL) {
+ if (cnTmp != nullptr) {
COSE_FREE(cnTmp, context);
}
EVP_CIPHER_CTX_free(ctx);
@@ -315,10 +315,10 @@
{
EVP_CIPHER_CTX *ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
int outl = 0;
byte rgbIV[15] = {0};
- const cn_cbor *pIV = NULL;
+ const cn_cbor *pIV = nullptr;
const EVP_CIPHER *cipher;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
@@ -326,18 +326,18 @@
int TSize = 128 / 8;
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
// Setup the IV/Nonce and put it into the message
- pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, NULL);
- if ((pIV == NULL) || (pIV->type != CN_CBOR_BYTES)) {
- if (perr != NULL) {
+ pIV = _COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, nullptr);
+ if ((pIV == nullptr) || (pIV->type != CN_CBOR_BYTES)) {
+ if (perr != nullptr) {
perr->err = COSE_ERR_INVALID_PARAMETER;
}
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
EVP_CIPHER_CTX_free(ctx);
@@ -369,27 +369,27 @@
// Do the setup for OpenSSL
- CHECK_CONDITION(EVP_DecryptInit_ex(ctx, cipher, NULL, NULL, NULL),
+ CHECK_CONDITION(EVP_DecryptInit_ex(ctx, cipher, nullptr, nullptr, nullptr),
COSE_ERR_DECRYPT_FAILED);
CHECK_CONDITION(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, TSize,
(void *)&pbCrypto[cbCrypto - TSize]),
COSE_ERR_DECRYPT_FAILED);
- CHECK_CONDITION(EVP_DecryptInit_ex(ctx, 0, NULL, pbKey, rgbIV),
+ CHECK_CONDITION(EVP_DecryptInit_ex(ctx, 0, nullptr, pbKey, rgbIV),
COSE_ERR_DECRYPT_FAILED);
// Pus in the AAD
CHECK_CONDITION(
- EVP_DecryptUpdate(ctx, NULL, &outl, pbAuthData, (int)cbAuthData),
+ EVP_DecryptUpdate(ctx, nullptr, &outl, pbAuthData, (int)cbAuthData),
COSE_ERR_DECRYPT_FAILED);
//
cbOut = (int)cbCrypto - TSize;
rgbOut = (byte *)COSE_CALLOC(cbOut, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
// Process content
@@ -425,12 +425,12 @@
{
EVP_CIPHER_CTX *ctx;
int cbOut;
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
int outl = 0;
byte rgbIV[16] = {0};
- byte *pbIV = NULL;
- const cn_cbor *cbor_iv = NULL;
- cn_cbor *cbor_iv_t = NULL;
+ byte *pbIV = nullptr;
+ const cn_cbor *cbor_iv = nullptr;
+ cn_cbor *cbor_iv_t = nullptr;
const EVP_CIPHER *cipher;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
@@ -439,13 +439,13 @@
if (false) {
errorReturn:
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
- if (cbor_iv_t != NULL) {
+ if (cbor_iv_t != nullptr) {
COSE_FREE(cbor_iv_t, context);
}
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
EVP_CIPHER_CTX_free(ctx);
@@ -454,27 +454,27 @@
// Make it first so we can clean it up
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
// Setup the IV/Nonce and put it into the message
cbor_iv =
_COSE_map_get_int(&pcose->m_message, COSE_Header_IV, COSE_BOTH, perr);
- if (cbor_iv == NULL) {
+ if (cbor_iv == nullptr) {
pbIV = (byte *) COSE_CALLOC(96, 1, context);
- CHECK_CONDITION(pbIV != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbIV != nullptr, COSE_ERR_OUT_OF_MEMORY);
rand_bytes(pbIV, 96 / 8);
memcpy(rgbIV, pbIV, 96 / 8);
cbor_iv_t = cn_cbor_data_create2(
pbIV, 96 / 8, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(cbor_iv_t != NULL, cbor_error);
- pbIV = NULL;
+ CHECK_CONDITION_CBOR(cbor_iv_t != nullptr, cbor_error);
+ pbIV = nullptr;
if (!_COSE_map_put(&pcose->m_message, COSE_Header_IV, cbor_iv_t,
COSE_UNPROTECT_ONLY, perr)) {
goto errorReturn;
}
- cbor_iv_t = NULL;
+ cbor_iv_t = nullptr;
}
else {
CHECK_CONDITION(
@@ -503,18 +503,18 @@
// Setup and run the OpenSSL code
- CHECK_CONDITION(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL),
+ CHECK_CONDITION(EVP_EncryptInit_ex(ctx, cipher, nullptr, nullptr, nullptr),
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
- EVP_EncryptInit_ex(ctx, 0, NULL, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL);
+ EVP_EncryptInit_ex(ctx, 0, nullptr, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
- EVP_EncryptUpdate(ctx, NULL, &outl, pbAuthData, (int)cbAuthData),
+ EVP_EncryptUpdate(ctx, nullptr, &outl, pbAuthData, (int)cbAuthData),
COSE_ERR_CRYPTO_FAIL);
rgbOut = (byte *)COSE_CALLOC(pcose->cbContent + 128 / 8, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(EVP_EncryptUpdate(ctx, rgbOut, &cbOut, pcose->pbContent,
(int)pcose->cbContent),
@@ -528,16 +528,16 @@
COSE_ERR_CRYPTO_FAIL);
cn_cbor *cnTmp = cn_cbor_data_create2(
- rgbOut, (int)pcose->cbContent + 128 / 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- rgbOut = NULL;
+ rgbOut, (int)pcose->cbContent + 128 / 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cnTmp, INDEX_BODY,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
EVP_CIPHER_CTX_free(ctx);
- if (pbIV != NULL) {
+ if (pbIV != nullptr) {
COSE_FREE(pbIV, context);
}
return true;
@@ -551,23 +551,23 @@
size_t cbAuthData,
cose_errback *perr)
{
- const EVP_CIPHER *pcipher = NULL;
+ const EVP_CIPHER *pcipher = nullptr;
EVP_CIPHER_CTX *ctx;
int cbOut;
byte rgbIV[16] = {0};
- byte *rgbOut = NULL;
+ byte *rgbOut = nullptr;
bool f = false;
unsigned int i;
- cn_cbor *cn = NULL;
+ cn_cbor *cn = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
rgbOut = (byte *) COSE_CALLOC(16, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
switch (cbKey * 8) {
case 128:
@@ -584,7 +584,7 @@
// Setup and run the OpenSSL code
- CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, NULL, pbKey, rgbIV),
+ CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, nullptr, pbKey, rgbIV),
COSE_ERR_CRYPTO_FAIL);
for (i = 0; i < (unsigned int)cbAuthData / 16; i++) {
@@ -601,23 +601,23 @@
COSE_ERR_CRYPTO_FAIL);
}
- cn = cn_cbor_data_create2(rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cn != NULL, COSE_ERR_OUT_OF_MEMORY);
- rgbOut = NULL;
+ cn = cn_cbor_data_create2(rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_OUT_OF_MEMORY);
+ rgbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cn, INDEX_MAC_TAG,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- cn = NULL;
+ cn = nullptr;
EVP_CIPHER_CTX_free(ctx);
return !f;
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
- if (cn != NULL) {
+ if (cn != nullptr) {
CN_CBOR_FREE(cn, context);
}
EVP_CIPHER_CTX_free(ctx);
@@ -632,8 +632,8 @@
size_t cbAuthData,
cose_errback *perr)
{
- const EVP_CIPHER *pcipher = NULL;
- EVP_CIPHER_CTX *ctx = NULL;
+ const EVP_CIPHER *pcipher = nullptr;
+ EVP_CIPHER_CTX *ctx = nullptr;
int cbOut;
byte rgbIV[16] = {0};
byte rgbTag[16] = {0};
@@ -661,8 +661,8 @@
// Setup and run the OpenSSL code
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
- CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, NULL, pbKey, rgbIV),
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, nullptr, pbKey, rgbIV),
COSE_ERR_CRYPTO_FAIL);
TSize /= 8;
@@ -682,7 +682,7 @@
}
cn_cbor *cn = _COSE_arrayget_int(&pcose->m_message, INDEX_MAC_TAG);
- CHECK_CONDITION(cn != NULL, COSE_ERR_CBOR);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_CBOR);
for (i = 0; i < (unsigned int)TSize; i++) {
f |= (cn->v.bytes[i] != rgbTag[i]);
@@ -696,9 +696,9 @@
// We are doing CBC-MAC not CMAC at this time
bool AES_CMAC_Validate(COSE_MacMessage * pcose, int KeySize, int TagSize, const byte * pbAuthData, int cbAuthData, cose_errback * perr)
{
- CMAC_CTX * pctx = NULL;
- const EVP_CIPHER * pcipher = NULL;
- byte * rgbOut = NULL;
+ CMAC_CTX * pctx = nullptr;
+ const EVP_CIPHER * pcipher = nullptr;
+ byte * rgbOut = nullptr;
size_t cbOut;
bool f = false;
unsigned int i;
@@ -716,14 +716,14 @@
}
rgbOut = COSE_CALLOC(128/8, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
- CHECK_CONDITION(CMAC_Init(pctx, pcose->pbKey, pcose->cbKey, pcipher, NULL /*impl*/) == 1, COSE_ERR_CRYPTO_FAIL);
+ CHECK_CONDITION(CMAC_Init(pctx, pcose->pbKey, pcose->cbKey, pcipher, nullptr /*impl*/) == 1, COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(CMAC_Update(pctx, pbAuthData, cbAuthData), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(CMAC_Final(pctx, rgbOut, &cbOut), COSE_ERR_CRYPTO_FAIL);
cn_cbor * cn = _COSE_arrayget_int(&pcose->m_message, INDEX_MAC_TAG);
- CHECK_CONDITION(cn != NULL, COSE_ERR_CBOR);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_CBOR);
for (i = 0; i < (unsigned int)TagSize / 8; i++) f |= (cn->v.bytes[i] != rgbOut[i]);
@@ -751,7 +751,7 @@
size_t cbOutput,
cose_errback *perr)
{
- const EVP_CIPHER *pcipher = NULL;
+ const EVP_CIPHER *pcipher = nullptr;
EVP_CIPHER_CTX *ctx;
int cbOut;
byte rgbIV[16] = {0};
@@ -764,7 +764,7 @@
UNUSED(pcose);
ctx = EVP_CIPHER_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
switch (cbitKey) {
case 128:
@@ -785,7 +785,7 @@
for (ib = 0; ib < cbOutput; ib += 16, bCount += 1) {
size_t ib2;
- CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, NULL, pbPRK, rgbIV),
+ CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, nullptr, pbPRK, rgbIV),
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
@@ -831,11 +831,11 @@
int cbSalt;
cn_cbor *cnSalt;
HMAC_CTX *ctx;
- const EVP_MD *pmd = NULL;
+ const EVP_MD *pmd = nullptr;
unsigned int cbDigest;
ctx = HMAC_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
if (0) {
errorReturn:
@@ -863,13 +863,13 @@
cnSalt = _COSE_map_get_int(pcose, COSE_Header_HKDF_salt, COSE_BOTH, perr);
- if (cnSalt != NULL) {
+ if (cnSalt != nullptr) {
CHECK_CONDITION(
- HMAC_Init_ex(ctx, cnSalt->v.bytes, (int)cnSalt->length, pmd, NULL),
+ HMAC_Init_ex(ctx, cnSalt->v.bytes, (int)cnSalt->length, pmd, nullptr),
COSE_ERR_CRYPTO_FAIL);
}
else {
- CHECK_CONDITION(HMAC_Init_ex(ctx, rgbSalt, cbSalt, pmd, NULL),
+ CHECK_CONDITION(HMAC_Init_ex(ctx, rgbSalt, cbSalt, pmd, nullptr),
COSE_ERR_CRYPTO_FAIL);
}
CHECK_CONDITION(HMAC_Update(ctx, pbKey, (int)cbKey), COSE_ERR_CRYPTO_FAIL);
@@ -891,7 +891,7 @@
cose_errback *perr)
{
HMAC_CTX *ctx;
- const EVP_MD *pmd = NULL;
+ const EVP_MD *pmd = nullptr;
size_t ib;
unsigned int cbDigest = 0;
byte rgbDigest[EVP_MAX_MD_SIZE];
@@ -900,7 +900,7 @@
UNUSED(pcose);
ctx = HMAC_CTX_new();
- CHECK_CONDITION(ctx != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(ctx != nullptr, COSE_ERR_OUT_OF_MEMORY);
if (0) {
errorReturn:
@@ -924,7 +924,7 @@
}
for (ib = 0; ib < cbOutput; ib += cbDigest, bCount += 1) {
- CHECK_CONDITION(HMAC_Init_ex(ctx, pbPRK, (int)cbPRK, pmd, NULL),
+ CHECK_CONDITION(HMAC_Init_ex(ctx, pbPRK, (int)cbPRK, pmd, nullptr),
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
HMAC_Update(ctx, rgbDigest, cbDigest), COSE_ERR_CRYPTO_FAIL);
@@ -950,21 +950,21 @@
cose_errback *perr)
{
HMAC_CTX *ctx;
- const EVP_MD *pmd = NULL;
- byte *rgbOut = NULL;
+ const EVP_MD *pmd = nullptr;
+ byte *rgbOut = nullptr;
unsigned int cbOut;
- cn_cbor *cbor = NULL;
+ cn_cbor *cbor = nullptr;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_message.m_allocContext;
#endif
ctx = HMAC_CTX_new();
- CHECK_CONDITION(NULL != ctx, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(nullptr != ctx, COSE_ERR_OUT_OF_MEMORY);
if (0) {
errorReturn:
COSE_FREE(rgbOut, context);
- if (cbor != NULL) {
+ if (cbor != nullptr) {
COSE_FREE(cbor, context);
}
HMAC_CTX_free(ctx);
@@ -987,19 +987,19 @@
}
rgbOut = (byte *) COSE_CALLOC(EVP_MAX_MD_SIZE, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
- HMAC_Init_ex(ctx, pbKey, (int)cbKey, pmd, NULL), COSE_ERR_CRYPTO_FAIL);
+ HMAC_Init_ex(ctx, pbKey, (int)cbKey, pmd, nullptr), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
HMAC_Update(ctx, pbAuthData, cbAuthData), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(HMAC_Final(ctx, rgbOut, &cbOut), COSE_ERR_CRYPTO_FAIL);
-cbor = cn_cbor_data_create2(rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cbor != NULL, COSE_ERR_OUT_OF_MEMORY);
+cbor = cn_cbor_data_create2(rgbOut, TSize / 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cbor != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(_COSE_array_replace(&pcose->m_message, cbor,
- INDEX_MAC_TAG, CBOR_CONTEXT_PARAM_COMMA NULL),
+ INDEX_MAC_TAG, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
HMAC_CTX_free(ctx);
@@ -1015,9 +1015,9 @@
size_t cbAuthData,
cose_errback *perr)
{
- HMAC_CTX *ctx = NULL;
- const EVP_MD *pmd = NULL;
- byte *rgbOut = NULL;
+ HMAC_CTX *ctx = nullptr;
+ const EVP_MD *pmd = nullptr;
+ byte *rgbOut = nullptr;
unsigned int cbOut = 0 ;
bool f = false;
#ifdef USE_CBOR_CONTEXT
@@ -1026,14 +1026,14 @@
if (false) {
errorReturn:
- if (rgbOut != NULL) {
+ if (rgbOut != nullptr) {
COSE_FREE(rgbOut, context);
}
HMAC_CTX_free(ctx);
return false;
}
ctx = HMAC_CTX_new();
- CHECK_CONDITION(ctx != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(ctx != nullptr, COSE_ERR_OUT_OF_MEMORY);
switch (HSize) {
case 256:
@@ -1051,16 +1051,16 @@
}
rgbOut = (byte *) COSE_CALLOC(EVP_MAX_MD_SIZE, 1, context);
- CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(rgbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
- HMAC_Init_ex(ctx, pbKey, (int)cbKey, pmd, NULL), COSE_ERR_CRYPTO_FAIL);
+ HMAC_Init_ex(ctx, pbKey, (int)cbKey, pmd, nullptr), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
HMAC_Update(ctx, pbAuthData, cbAuthData), COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(HMAC_Final(ctx, rgbOut, &cbOut), COSE_ERR_CRYPTO_FAIL);
cn_cbor *cn = _COSE_arrayget_int(&pcose->m_message, INDEX_MAC_TAG);
- CHECK_CONDITION(cn != NULL, COSE_ERR_CBOR);
+ CHECK_CONDITION(cn != nullptr, COSE_ERR_CBOR);
if (cn->length > cbOut) {
return false;
@@ -1081,19 +1081,19 @@
EC_KEY *ECKey_From(COSE_KEY *pKey, int *cbGroup, cose_errback *perr)
{
- EC_KEY *pNewKey = NULL;
+ EC_KEY *pNewKey = nullptr;
if (false) {
errorReturn:
- if (pNewKey != NULL) {
+ if (pNewKey != nullptr) {
EC_KEY_free(pNewKey);
}
- return NULL;
+ return nullptr;
}
- if (pKey->m_opensslKey != NULL) {
+ if (pKey->m_opensslKey != nullptr) {
EC_KEY *pKeyNew = EVP_PKEY_get1_EC_KEY(pKey->m_opensslKey);
- CHECK_CONDITION(pKeyNew != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pKeyNew != nullptr, COSE_ERR_INVALID_PARAMETER);
return pKeyNew;
}
@@ -1101,13 +1101,13 @@
int cbKey;
const cn_cbor *p;
int nidGroup = -1;
- EC_POINT *pPoint = NULL;
+ EC_POINT *pPoint = nullptr;
pNewKey = EC_KEY_new();
- CHECK_CONDITION(pNewKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pNewKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_Curve);
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
switch (p->v.sint) {
case 1: // P-256
@@ -1130,18 +1130,18 @@
}
EC_GROUP *ecgroup = EC_GROUP_new_by_curve_name(nidGroup);
- CHECK_CONDITION(ecgroup != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(ecgroup != nullptr, COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(
EC_KEY_set_group(pNewKey, ecgroup) == 1, COSE_ERR_CRYPTO_FAIL);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_X);
CHECK_CONDITION(
- (p != NULL) && (p->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
+ (p != nullptr) && (p->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
CHECK_CONDITION(p->length == (size_t)*cbGroup, COSE_ERR_INVALID_PARAMETER);
memcpy(rgbKey + 1, p->v.str, p->length);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_Y);
- CHECK_CONDITION((p != NULL), COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION((p != nullptr), COSE_ERR_INVALID_PARAMETER);
if (p->type == CN_CBOR_BYTES) {
rgbKey[0] = POINT_CONVERSION_UNCOMPRESSED;
cbKey = (*cbGroup * 2) + 1;
@@ -1160,25 +1160,25 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
pPoint = EC_POINT_new(ecgroup);
- CHECK_CONDITION(pPoint != NULL, COSE_ERR_CRYPTO_FAIL);
+ CHECK_CONDITION(pPoint != nullptr, COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
- EC_POINT_oct2point(ecgroup, pPoint, rgbKey, cbKey, NULL) == 1,
+ EC_POINT_oct2point(ecgroup, pPoint, rgbKey, cbKey, nullptr) == 1,
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
EC_KEY_set_public_key(pNewKey, pPoint) == 1, COSE_ERR_CRYPTO_FAIL);
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_EC_d);
- if (p != NULL) {
+ if (p != nullptr) {
BIGNUM *pbn;
- pbn = BN_bin2bn(p->v.bytes, (int)p->length, NULL);
- CHECK_CONDITION(pbn != NULL, COSE_ERR_CRYPTO_FAIL);
+ pbn = BN_bin2bn(p->v.bytes, (int)p->length, nullptr);
+ CHECK_CONDITION(pbn != nullptr, COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
EC_KEY_set_private_key(pNewKey, pbn) == 1, COSE_ERR_CRYPTO_FAIL);
}
pKey->m_opensslKey = EVP_PKEY_new();
- CHECK_CONDITION(pKey->m_opensslKey != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pKey->m_opensslKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(EVP_PKEY_set1_EC_KEY(pKey->m_opensslKey, pNewKey) == 1, COSE_ERR_CRYPTO_FAIL);
@@ -1187,19 +1187,19 @@
COSE_KEY *EC_FromKey(const EC_KEY *pKey, CBOR_CONTEXT_COMMA cose_errback *perr)
{
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
const EC_GROUP *pgroup;
int cose_group;
- cn_cbor *p = NULL;
+ cn_cbor *p = nullptr;
cn_cbor_errback cbor_error;
const EC_POINT *pPoint;
- byte *pbPoint = NULL;
+ byte *pbPoint = nullptr;
size_t cbSize;
- byte *pbOut = NULL;
- COSE_KEY *coseKey = NULL;
+ byte *pbOut = nullptr;
+ COSE_KEY *coseKey = nullptr;
pgroup = EC_KEY_get0_group(pKey);
- CHECK_CONDITION(pgroup != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pgroup != nullptr, COSE_ERR_INVALID_PARAMETER);
switch (EC_GROUP_get_curve_name(pgroup)) {
case NID_X9_62_prime256v1:
@@ -1217,110 +1217,110 @@
}
pkey = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(pkey != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(pkey != nullptr, cbor_error);
p = cn_cbor_int_create(cose_group, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_Curve, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
pPoint = EC_KEY_get0_public_key(pKey);
- CHECK_CONDITION(pPoint != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pPoint != nullptr, COSE_ERR_INVALID_PARAMETER);
if (FUseCompressed) {
cbSize = EC_POINT_point2oct(
- pgroup, pPoint, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
+ pgroup, pPoint, POINT_CONVERSION_COMPRESSED, nullptr, 0, nullptr);
CHECK_CONDITION(cbSize > 0, COSE_ERR_CRYPTO_FAIL);
pbPoint = (byte *) COSE_CALLOC(cbSize, 1, context);
- CHECK_CONDITION(pbPoint != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbPoint != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
EC_POINT_point2oct(pgroup, pPoint, POINT_CONVERSION_COMPRESSED,
- pbPoint, cbSize, NULL) == cbSize,
+ pbPoint, cbSize, nullptr) == cbSize,
COSE_ERR_CRYPTO_FAIL);
}
else {
cbSize = EC_POINT_point2oct(
- pgroup, pPoint, POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL);
+ pgroup, pPoint, POINT_CONVERSION_UNCOMPRESSED, nullptr, 0, nullptr);
CHECK_CONDITION(cbSize > 0, COSE_ERR_CRYPTO_FAIL);
pbPoint = (byte *) COSE_CALLOC(cbSize, 1, context);
- CHECK_CONDITION(pbPoint != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbPoint != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
EC_POINT_point2oct(pgroup, pPoint, POINT_CONVERSION_UNCOMPRESSED,
- pbPoint, cbSize, NULL) == cbSize,
+ pbPoint, cbSize, nullptr) == cbSize,
COSE_ERR_CRYPTO_FAIL);
}
pbOut = (byte *) COSE_CALLOC((int)(cbSize / 2), 1, context);
- CHECK_CONDITION(pbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbOut, pbPoint + 1, (int)(cbSize / 2));
p = cn_cbor_data_create2(
pbOut, (int)(cbSize / 2), 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
- pbOut = NULL;
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
+ pbOut = nullptr;
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_X, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
if (FUseCompressed) {
p = cn_cbor_bool_create(
pbPoint[0] & 1, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_Y, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
}
else {
pbOut = (byte *) COSE_CALLOC((int)(cbSize / 2), 1, context);
- CHECK_CONDITION(pbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
memcpy(pbOut, pbPoint + cbSize / 2 + 1, (int)(cbSize / 2));
p = cn_cbor_data_create2(pbOut, (int)(cbSize / 2), 0,
CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
- pbOut = NULL;
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
+ pbOut = nullptr;
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_EC_Y, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
}
p = cn_cbor_int_create(
COSE_Key_Type_EC2, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION_CBOR(cn_cbor_mapput_int(pkey, COSE_Key_Type, p,
CBOR_CONTEXT_PARAM_COMMA & cbor_error),
cbor_error);
- p = NULL;
+ p = nullptr;
coseKey = (COSE_KEY*) COSE_KEY_FromCbor(pkey, CBOR_CONTEXT_PARAM_COMMA perr);
- CHECK_CONDITION(coseKey != NULL, COSE_ERR_OUT_OF_MEMORY);
- pkey = NULL;
+ CHECK_CONDITION(coseKey != nullptr, COSE_ERR_OUT_OF_MEMORY);
+ pkey = nullptr;
returnHere:
- if (pbPoint != NULL) {
+ if (pbPoint != nullptr) {
COSE_FREE(pbPoint, context);
}
- if (pbOut != NULL) {
+ if (pbOut != nullptr) {
COSE_FREE(pbOut, context);
}
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
return coseKey;
errorReturn:
CN_CBOR_FREE(pkey, context);
- pkey = NULL;
+ pkey = nullptr;
goto returnHere;
}
/*
bool ECDSA_Sign(const cn_cbor * pKey)
{
- byte * digest = NULL;
+ byte * digest = nullptr;
int digestLen = 0;
ECDSA_SIG * sig;
@@ -1340,31 +1340,31 @@
size_t cbToSign,
cose_errback *perr)
{
- EC_KEY *eckey = NULL;
+ EC_KEY *eckey = nullptr;
byte rgbDigest[EVP_MAX_MD_SIZE];
unsigned int cbDigest = sizeof(rgbDigest);
- byte *pbSig = NULL;
+ byte *pbSig = nullptr;
const EVP_MD *digest;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_allocContext;
#endif
- cn_cbor *p = NULL;
- ECDSA_SIG *psig = NULL;
+ cn_cbor *p = nullptr;
+ ECDSA_SIG *psig = nullptr;
cn_cbor_errback cbor_error;
int cbR;
byte rgbSig[66];
int cb;
eckey = ECKey_From(pKey, &cbR, perr);
- if (eckey == NULL) {
+ if (eckey == nullptr) {
errorReturn:
- if (pbSig != NULL) {
+ if (pbSig != nullptr) {
COSE_FREE(pbSig, context);
}
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
- if (eckey != NULL) {
+ if (eckey != nullptr) {
EC_KEY_free(eckey);
}
return false;
@@ -1384,13 +1384,13 @@
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, NULL);
+ EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, nullptr);
psig = ECDSA_do_sign(rgbDigest, cbDigest, eckey);
- CHECK_CONDITION(psig != NULL, COSE_ERR_CRYPTO_FAIL);
+ CHECK_CONDITION(psig != nullptr, COSE_ERR_CRYPTO_FAIL);
pbSig = (byte *) COSE_CALLOC(cbR, 2, context);
- CHECK_CONDITION(pbSig != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbSig != nullptr, COSE_ERR_OUT_OF_MEMORY);
const BIGNUM *r;
const BIGNUM *s;
@@ -1405,15 +1405,15 @@
p = cn_cbor_data_create2(
pbSig, cbR * 2, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION_CBOR(p != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(p != nullptr, cbor_error);
CHECK_CONDITION(
- _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA NULL),
+ _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- pbSig = NULL;
+ pbSig = nullptr;
- if (eckey != NULL) {
+ if (eckey != nullptr) {
EC_KEY_free(eckey);
}
@@ -1428,15 +1428,15 @@
size_t cbToSign,
cose_errback *perr)
{
- EC_KEY *eckey = NULL;
+ EC_KEY *eckey = nullptr;
byte rgbDigest[EVP_MAX_MD_SIZE];
unsigned int cbDigest = sizeof(rgbDigest);
const EVP_MD *digest;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pSigner->m_allocContext;
#endif
- cn_cbor *p = NULL;
- ECDSA_SIG *sig = NULL;
+ cn_cbor *p = nullptr;
+ ECDSA_SIG *sig = nullptr;
int cbR;
cn_cbor *pSig;
size_t cbSignature;
@@ -1444,15 +1444,15 @@
BIGNUM *r, *s;
eckey = ECKey_From(pKey, &cbR, perr);
- if (eckey == NULL) {
+ if (eckey == nullptr) {
errorReturn:
- if (p != NULL) {
+ if (p != nullptr) {
CN_CBOR_FREE(p, context);
}
- if (eckey != NULL) {
+ if (eckey != nullptr) {
EC_KEY_free(eckey);
}
- if (sig != NULL) {
+ if (sig != nullptr) {
ECDSA_SIG_free(sig);
}
return false;
@@ -1471,30 +1471,30 @@
default:
FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
}
- EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, NULL);
+ EVP_Digest(rgbToSign, cbToSign, rgbDigest, &cbDigest, digest, nullptr);
pSig = _COSE_arrayget_int(pSigner, index);
- CHECK_CONDITION(pSig != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pSig != nullptr, COSE_ERR_INVALID_PARAMETER);
cbSignature = pSig->length;
CHECK_CONDITION(cbSignature / 2 == (size_t)cbR, COSE_ERR_INVALID_PARAMETER);
- r = BN_bin2bn(pSig->v.bytes, (int)cbSignature / 2, NULL);
- CHECK_CONDITION(NULL != r, COSE_ERR_OUT_OF_MEMORY);
- s = BN_bin2bn(pSig->v.bytes + cbSignature / 2, (int)cbSignature / 2, NULL);
- CHECK_CONDITION(NULL != s, COSE_ERR_OUT_OF_MEMORY);
+ r = BN_bin2bn(pSig->v.bytes, (int)cbSignature / 2, nullptr);
+ CHECK_CONDITION(nullptr != r, COSE_ERR_OUT_OF_MEMORY);
+ s = BN_bin2bn(pSig->v.bytes + cbSignature / 2, (int)cbSignature / 2, nullptr);
+ CHECK_CONDITION(nullptr != s, COSE_ERR_OUT_OF_MEMORY);
sig = ECDSA_SIG_new();
- CHECK_CONDITION(sig != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(sig != nullptr, COSE_ERR_OUT_OF_MEMORY);
ECDSA_SIG_set0(sig, r, s);
CHECK_CONDITION(ECDSA_do_verify(rgbDigest, cbDigest, sig, eckey) == 1,
COSE_ERR_CRYPTO_FAIL);
- if (eckey != NULL) {
+ if (eckey != nullptr) {
EC_KEY_free(eckey);
}
- if (sig != NULL) {
+ if (sig != nullptr) {
ECDSA_SIG_free(sig);
}
@@ -1514,25 +1514,25 @@
#endif
cn_cbor *p;
cn_cbor_errback cbor_error;
- EVP_PKEY_CTX *keyCtx = NULL;
- EVP_MD_CTX *mdCtx = NULL;
- EVP_PKEY *pkey = NULL;
- byte *pbSig = NULL;
+ EVP_PKEY_CTX *keyCtx = nullptr;
+ EVP_MD_CTX *mdCtx = nullptr;
+ EVP_PKEY *pkey = nullptr;
+ byte *pbSig = nullptr;
int cbSig;
p = cn_cbor_mapget_int(pKeyIn->m_cborKey, COSE_Key_OPK_Curve);
- if (p == NULL) {
+ if (p == nullptr) {
errorReturn:
- if (mdCtx != NULL) {
+ if (mdCtx != nullptr) {
EVP_MD_CTX_free(mdCtx);
}
- if (keyCtx != NULL) {
+ if (keyCtx != nullptr) {
EVP_PKEY_CTX_free(keyCtx);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
EVP_PKEY_free(pkey);
}
- if (pbSig != NULL) {
+ if (pbSig != nullptr) {
COSE_FREE(pbSig, context);
}
return false;
@@ -1556,23 +1556,23 @@
}
p = cn_cbor_mapget_int(pKeyIn->m_cborKey, COSE_Key_EC_d);
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
- pkey = EVP_PKEY_new_raw_private_key(type, NULL, p->v.bytes, p->length);
- CHECK_CONDITION(pkey != NULL, COSE_ERR_CRYPTO_FAIL);
+ pkey = EVP_PKEY_new_raw_private_key(type, nullptr, p->v.bytes, p->length);
+ CHECK_CONDITION(pkey != nullptr, COSE_ERR_CRYPTO_FAIL);
- keyCtx = EVP_PKEY_CTX_new_id(type, NULL);
- CHECK_CONDITION(keyCtx != NULL, COSE_ERR_OUT_OF_MEMORY);
+ keyCtx = EVP_PKEY_CTX_new_id(type, nullptr);
+ CHECK_CONDITION(keyCtx != nullptr, COSE_ERR_OUT_OF_MEMORY);
mdCtx = EVP_MD_CTX_new();
- CHECK_CONDITION(mdCtx != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(mdCtx != nullptr, COSE_ERR_OUT_OF_MEMORY);
- CHECK_CONDITION(EVP_DigestSignInit(mdCtx, &keyCtx, NULL, NULL, pkey) == 1,
+ CHECK_CONDITION(EVP_DigestSignInit(mdCtx, &keyCtx, nullptr, nullptr, pkey) == 1,
COSE_ERR_CRYPTO_FAIL);
- keyCtx = NULL;
+ keyCtx = nullptr;
pbSig = (byte *) COSE_CALLOC(cbSig, 1, context);
- CHECK_CONDITION(pbSig != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbSig != nullptr, COSE_ERR_OUT_OF_MEMORY);
size_t cb2 = cbSig;
CHECK_CONDITION(
@@ -1581,23 +1581,23 @@
p = cn_cbor_data_create2(
pbSig, (int)cb2, 0, CBOR_CONTEXT_PARAM_COMMA & cbor_error);
- CHECK_CONDITION(p != NULL, COSE_ERR_OUT_OF_MEMORY);
- pbSig = NULL;
+ CHECK_CONDITION(p != nullptr, COSE_ERR_OUT_OF_MEMORY);
+ pbSig = nullptr;
CHECK_CONDITION(
- _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA NULL),
+ _COSE_array_replace(pSigner, p, index, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- if (mdCtx != NULL) {
+ if (mdCtx != nullptr) {
EVP_MD_CTX_free(mdCtx);
}
- if (keyCtx != NULL) {
+ if (keyCtx != nullptr) {
EVP_PKEY_CTX_free(keyCtx);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
EVP_PKEY_free(pkey);
}
- if (pbSig != NULL) {
+ if (pbSig != nullptr) {
COSE_FREE(pbSig, context);
}
@@ -1612,12 +1612,12 @@
cose_errback *perr)
{
cn_cbor *pSig;
- EVP_PKEY *pkey = NULL;
+ EVP_PKEY *pkey = nullptr;
cn_cbor *p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_OPK_Curve);
- if (p == NULL) {
+ if (p == nullptr) {
errorReturn:
- if (pkey != NULL) {
+ if (pkey != nullptr) {
EVP_PKEY_free(pkey);
}
return false;
@@ -1639,29 +1639,29 @@
}
p = cn_cbor_mapget_int(pKey->m_cborKey, COSE_Key_OPK_X);
- CHECK_CONDITION(p != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(p != nullptr, COSE_ERR_INVALID_PARAMETER);
- pkey = EVP_PKEY_new_raw_public_key(type, NULL, p->v.bytes, p->length);
- CHECK_CONDITION(pkey != NULL, COSE_ERR_CBOR);
+ pkey = EVP_PKEY_new_raw_public_key(type, nullptr, p->v.bytes, p->length);
+ CHECK_CONDITION(pkey != nullptr, COSE_ERR_CBOR);
pSig = _COSE_arrayget_int(pSigner, index);
- CHECK_CONDITION(pSig != NULL, COSE_ERR_INVALID_PARAMETER);
+ CHECK_CONDITION(pSig != nullptr, COSE_ERR_INVALID_PARAMETER);
EVP_MD_CTX *pmdCtx = EVP_MD_CTX_new();
- EVP_PKEY_CTX *keyCtx = EVP_PKEY_CTX_new_id(type, NULL);
+ EVP_PKEY_CTX *keyCtx = EVP_PKEY_CTX_new_id(type, nullptr);
CHECK_CONDITION(
- EVP_DigestVerifyInit(pmdCtx, &keyCtx, NULL, NULL, pkey) == 1,
+ EVP_DigestVerifyInit(pmdCtx, &keyCtx, nullptr, nullptr, pkey) == 1,
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(EVP_DigestVerify(pmdCtx, pSig->v.bytes, pSig->length,
rgbToSign, cbToSign) == 1,
COSE_ERR_CRYPTO_FAIL);
- if (pmdCtx != NULL) {
+ if (pmdCtx != nullptr) {
EVP_MD_CTX_free(pmdCtx);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
EVP_PKEY_free(pkey);
}
@@ -1687,7 +1687,7 @@
COSE_ERR_CRYPTO_FAIL);
CHECK_CONDITION(
- AES_unwrap_key(&key, NULL, rgbOut, pbCipherText, (int)cbCipherText),
+ AES_unwrap_key(&key, nullptr, rgbOut, pbCipherText, (int)cbCipherText),
COSE_ERR_CRYPTO_FAIL);
memcpy(pbKeyOut, rgbOut, cbCipherText - 8);
@@ -1705,36 +1705,36 @@
int cbContent,
cose_errback *perr)
{
- byte *pbOut = NULL;
+ byte *pbOut = nullptr;
AES_KEY key;
#ifdef USE_CBOR_CONTEXT
cn_cbor_context *context = &pcose->m_encrypt.m_message.m_allocContext;
#endif
- cn_cbor *cnTmp = NULL;
+ cn_cbor *cnTmp = nullptr;
pbOut = (byte *) COSE_CALLOC(cbContent + 8, 1, context);
- CHECK_CONDITION(pbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbOut != nullptr, COSE_ERR_OUT_OF_MEMORY);
CHECK_CONDITION(
AES_set_encrypt_key(pbKeyIn, cbitKey, &key) == 0, COSE_ERR_CRYPTO_FAIL);
- CHECK_CONDITION(AES_wrap_key(&key, NULL, pbOut, pbContent, cbContent),
+ CHECK_CONDITION(AES_wrap_key(&key, nullptr, pbOut, pbContent, cbContent),
COSE_ERR_CRYPTO_FAIL);
cnTmp = cn_cbor_data_create2(
- pbOut, (int)cbContent + 8, 0, CBOR_CONTEXT_PARAM_COMMA NULL);
- CHECK_CONDITION(cnTmp != NULL, COSE_ERR_CBOR);
- pbOut = NULL;
+ pbOut, (int)cbContent + 8, 0, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ CHECK_CONDITION(cnTmp != nullptr, COSE_ERR_CBOR);
+ pbOut = nullptr;
CHECK_CONDITION(_COSE_array_replace(&pcose->m_encrypt.m_message, cnTmp,
- INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA NULL),
+ INDEX_BODY, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_ERR_CBOR);
- cnTmp = NULL;
+ cnTmp = nullptr;
return true;
errorReturn:
COSE_FREE(cnTmp, context);
- if (pbOut != NULL) {
+ if (pbOut != nullptr) {
COSE_FREE(pbOut, context);
}
return false;
@@ -1764,23 +1764,23 @@
size_t *pcbSecret,
CBOR_CONTEXT_COMMA cose_errback *perr)
{
- EC_KEY *peckeyPrivate = NULL;
- EC_KEY *peckeyPublic = NULL;
+ EC_KEY *peckeyPrivate = nullptr;
+ EC_KEY *peckeyPublic = nullptr;
int cbGroup;
int cbsecret;
- byte *pbsecret = NULL;
+ byte *pbsecret = nullptr;
bool fRet = false;
peckeyPublic = ECKey_From(pKeyPublic, &cbGroup, perr);
- if (peckeyPublic == NULL) {
+ if (peckeyPublic == nullptr) {
goto errorReturn;
}
- if (*ppKeyPrivate == NULL) {
+ if (*ppKeyPrivate == nullptr) {
{
cn_cbor *pCompress = _COSE_map_get_int(
pRecipient, COSE_Header_UseCompressedECDH, COSE_BOTH, perr);
- if (pCompress == NULL) {
+ if (pCompress == nullptr) {
FUseCompressed = false;
}
else {
@@ -1793,38 +1793,38 @@
EC_KEY_generate_key(peckeyPrivate) == 1, COSE_ERR_CRYPTO_FAIL);
*ppKeyPrivate =
EC_FromKey(peckeyPrivate, CBOR_CONTEXT_PARAM_COMMA perr);
- if (*ppKeyPrivate == NULL) {
+ if (*ppKeyPrivate == nullptr) {
goto errorReturn;
}
}
else {
peckeyPrivate = ECKey_From(*ppKeyPrivate, &cbGroup, perr);
- if (peckeyPrivate == NULL) {
+ if (peckeyPrivate == nullptr) {
goto errorReturn;
}
}
pbsecret = (byte *) COSE_CALLOC(cbGroup, 1, context);
- CHECK_CONDITION(pbsecret != NULL, COSE_ERR_OUT_OF_MEMORY);
+ CHECK_CONDITION(pbsecret != nullptr, COSE_ERR_OUT_OF_MEMORY);
cbsecret = ECDH_compute_key(pbsecret, cbGroup,
- EC_KEY_get0_public_key(peckeyPublic), peckeyPrivate, NULL);
+ EC_KEY_get0_public_key(peckeyPublic), peckeyPrivate, nullptr);
CHECK_CONDITION(cbsecret > 0, COSE_ERR_CRYPTO_FAIL);
*ppbSecret = pbsecret;
*pcbSecret = cbsecret;
- pbsecret = NULL;
+ pbsecret = nullptr;
fRet = true;
errorReturn:
- if (pbsecret != NULL) {
+ if (pbsecret != nullptr) {
COSE_FREE(pbsecret, context);
}
- if (peckeyPublic != NULL) {
+ if (peckeyPublic != nullptr) {
EC_KEY_free(peckeyPublic);
}
- if (peckeyPrivate != NULL) {
+ if (peckeyPrivate != nullptr) {
EC_KEY_free(peckeyPrivate);
}
diff --git a/test/CounterSign_test.cpp b/test/CounterSign_test.cpp
index c3dfb2b..aeb9536 100644
--- a/test/CounterSign_test.cpp
+++ b/test/CounterSign_test.cpp
@@ -16,15 +16,15 @@
void CounterSign_Corners()
{
- HCOSE_COUNTERSIGN hCounterSign = NULL;
- HCOSE_COUNTERSIGN hBadHandle = NULL;
- HCOSE_COUNTERSIGN hNULL = NULL;
+ HCOSE_COUNTERSIGN hCounterSign = nullptr;
+ HCOSE_COUNTERSIGN hBadHandle = nullptr;
+ HCOSE_COUNTERSIGN hNULL = nullptr;
cose_errback cose_error;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
- hCounterSign = COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
+ hCounterSign = COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
hBadHandle = (HCOSE_COUNTERSIGN)COSE_CALLOC(1, sizeof(COSE), context);
#if INCLUDE_SIGN1
HCOSE_SIGN1 hSign1 = COSE_Sign1_Init(
@@ -52,7 +52,7 @@
hNULL, 1, cn, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_CounterSign_map_put_int(
- hNULL, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ hNULL, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_CounterSign_map_put_int(hCounterSign, 1, cn,
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
@@ -68,7 +68,7 @@
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign1_get_countersignature(hSign1, 3, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
- ((COSE_CounterSign *)hCounterSign)->m_next = NULL;
+ ((COSE_CounterSign *)hCounterSign)->m_next = nullptr;
COSE_Sign1_add_countersignature(hSign1, hCounterSign, &cose_error);
CHECK_FAILURE(COSE_Sign1_get_countersignature(hSign1, 3, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
diff --git a/test/Encrypt_test.cpp b/test/Encrypt_test.cpp
index 312a33e..878e943 100644
--- a/test/Encrypt_test.cpp
+++ b/test/Encrypt_test.cpp
@@ -32,25 +32,25 @@
const cn_cbor *pRecipient2,
int iRecipient2)
{
- HCOSE_ENVELOPED hEnc = NULL;
- HCOSE_RECIPIENT hRecip = NULL;
- HCOSE_RECIPIENT hRecip1 = NULL;
- HCOSE_RECIPIENT hRecip2 = NULL;
+ HCOSE_ENVELOPED hEnc = nullptr;
+ HCOSE_RECIPIENT hRecip = nullptr;
+ HCOSE_RECIPIENT hRecip1 = nullptr;
+ HCOSE_RECIPIENT hRecip2 = nullptr;
bool fRet = false;
int type = 0;
cose_errback cose_err;
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
bool fNoSupport = false;
if (false) {
errorReturn:
- if (hEnc != NULL) {
+ if (hEnc != nullptr) {
COSE_Enveloped_Free(hEnc);
}
- if (hRecip1 != NULL) {
+ if (hRecip1 != nullptr) {
COSE_Recipient_Free(hRecip1);
}
- if (hRecip2 != NULL) {
+ if (hRecip2 != nullptr) {
COSE_Recipient_Free(hRecip2);
}
@@ -59,7 +59,7 @@
hEnc = (HCOSE_ENVELOPED)COSE_Decode(pbEncoded, cbEncoded, &type,
COSE_enveloped_object, CBOR_CONTEXT_PARAM_COMMA & cose_err);
- if (hEnc == NULL) {
+ if (hEnc == nullptr) {
if (fFailBody && (cose_err.err == COSE_ERR_INVALID_PARAMETER)) {
return true;
}
@@ -72,13 +72,13 @@
}
cn_cbor *alg = COSE_Enveloped_map_get_int(
- hEnc, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ hEnc, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fNoSupport = true;
}
- hRecip1 = COSE_Enveloped_GetRecipient(hEnc, iRecipient1, NULL);
- if (hRecip1 == NULL) {
+ hRecip1 = COSE_Enveloped_GetRecipient(hEnc, iRecipient1, nullptr);
+ if (hRecip1 == nullptr) {
goto errorReturn;
}
if (!SetReceivingAttributes(
@@ -86,14 +86,14 @@
goto errorReturn;
}
- if (pRecipient2 != NULL) {
+ if (pRecipient2 != nullptr) {
pkey = BuildKey(cn_cbor_mapget_string(pRecipient2, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto errorReturn;
}
- hRecip2 = COSE_Recipient_GetRecipient(hRecip1, iRecipient2, NULL);
- if (hRecip2 == NULL) {
+ hRecip2 = COSE_Recipient_GetRecipient(hRecip1, iRecipient2, nullptr);
+ if (hRecip2 == nullptr) {
goto errorReturn;
}
@@ -101,16 +101,16 @@
(HCOSE)hRecip2, pRecipient2, Attributes_Recipient_protected)) {
goto errorReturn;
}
- if (!COSE_Recipient_SetKey(hRecip2, pkey, NULL)) {
+ if (!COSE_Recipient_SetKey(hRecip2, pkey, nullptr)) {
goto errorReturn;
}
cn_cbor *cnStatic = cn_cbor_mapget_string(pRecipient2, "sender_key");
- if (cnStatic != NULL) {
+ if (cnStatic != nullptr) {
if (COSE_Recipient_map_get_int(
- hRecip2, COSE_Header_ECDH_SPK, COSE_BOTH, NULL) == 0) {
+ hRecip2, COSE_Header_ECDH_SPK, COSE_BOTH, nullptr) == 0) {
COSE_Recipient_map_put_int(hRecip2, COSE_Header_ECDH_SPK,
- BuildKey(cnStatic, true), COSE_DONT_SEND, NULL);
+ BuildKey(cnStatic, true), COSE_DONT_SEND, nullptr);
}
}
@@ -118,19 +118,19 @@
}
else {
pkey = BuildKey(cn_cbor_mapget_string(pRecipient1, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto errorReturn;
}
- if (!COSE_Recipient_SetKey(hRecip1, pkey, NULL)) {
+ if (!COSE_Recipient_SetKey(hRecip1, pkey, nullptr)) {
goto errorReturn;
}
cn_cbor *cnStatic = cn_cbor_mapget_string(pRecipient1, "sender_key");
- if (cnStatic != NULL) {
+ if (cnStatic != nullptr) {
if (COSE_Recipient_map_get_int(
- hRecip1, COSE_Header_ECDH_SPK, COSE_BOTH, NULL) == 0) {
+ hRecip1, COSE_Header_ECDH_SPK, COSE_BOTH, nullptr) == 0) {
COSE_Recipient_map_put_int(hRecip1, COSE_Header_ECDH_SPK,
- BuildKey(cnStatic, true), COSE_DONT_SEND, NULL);
+ BuildKey(cnStatic, true), COSE_DONT_SEND, nullptr);
}
}
@@ -139,25 +139,25 @@
if (!fFailBody) {
cn_cbor *cn = cn_cbor_mapget_string(pRecipient1, "fail");
- if (cn != NULL && (cn->type == CN_CBOR_TRUE)) {
+ if (cn != nullptr && (cn->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
- if (fFailBody && (pRecipient2 != NULL)) {
+ if (fFailBody && (pRecipient2 != nullptr)) {
cn = cn_cbor_mapget_string(pRecipient2, "fail");
- if (cn != NULL && (cn->type == CN_CBOR_TRUE)) {
+ if (cn != nullptr && (cn->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
}
- if (hRecip2 != NULL) {
+ if (hRecip2 != nullptr) {
alg = COSE_Recipient_map_get_int(
- hRecip2, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ hRecip2, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fNoSupport = true;
}
}
alg = COSE_Recipient_map_get_int(
- hRecip1, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ hRecip1, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fNoSupport = true;
}
@@ -186,10 +186,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList =
cn_cbor_mapget_string(pRecipient1, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fRet = false;
goto errorReturn;
}
@@ -197,7 +197,7 @@
bool forward = true;
if (COSE_Recipient_map_get_int(hRecip1, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto errorReturn;
}
@@ -206,7 +206,7 @@
HCOSE_COUNTERSIGN h =
COSE_Recipient_get_countersignature(hRecip1, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fRet = false;
continue;
}
@@ -216,7 +216,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fRet = false;
COSE_CounterSign_Free(h);
continue;
@@ -230,7 +230,7 @@
}
alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
noSupportSign = true;
fNoSupport = true;
@@ -259,10 +259,10 @@
// Validate counter signatures on signers
countersignList = cn_cbor_mapget_string(pEnveloped, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fRet = false;
goto errorReturn;
}
@@ -270,7 +270,7 @@
bool forward = true;
if (COSE_Enveloped_map_get_int(hEnc, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
fRet = false;
goto errorReturn;
}
@@ -279,7 +279,7 @@
bool noSupportSign = false;
HCOSE_COUNTERSIGN h =
COSE_Enveloped_get_countersignature(hEnc, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fRet = false;
continue;
}
@@ -289,7 +289,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fRet = false;
COSE_CounterSign_Free(h);
continue;
@@ -303,7 +303,7 @@
}
alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
noSupportSign = true;
fNoSupport = true;
@@ -346,37 +346,37 @@
int passCount = 0;
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto errorReturn;
}
pEnveloped = cn_cbor_mapget_string(pInput, "enveloped");
- if ((pEnveloped == NULL) || (pEnveloped->type != CN_CBOR_MAP)) {
+ if ((pEnveloped == nullptr) || (pEnveloped->type != CN_CBOR_MAP)) {
goto errorReturn;
}
pRecipients = cn_cbor_mapget_string(pEnveloped, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto errorReturn;
}
iRecipient = (int)pRecipients->length - 1;
pRecipients = pRecipients->first_child;
- for (; pRecipients != NULL; iRecipient--, pRecipients = pRecipients->next) {
+ for (; pRecipients != nullptr; iRecipient--, pRecipients = pRecipients->next) {
cn_cbor *pRecip2 = cn_cbor_mapget_string(pRecipients, "recipients");
- if (pRecip2 == NULL) {
+ if (pRecip2 == nullptr) {
if (DecryptMessage(pbEncoded, cbEncoded, fFailBody, pEnveloped,
- pRecipients, iRecipient, NULL, 0)) {
+ pRecipients, iRecipient, nullptr, 0)) {
passCount++;
}
}
else {
int iRecipient2 = (int)(pRecip2->length - 1);
pRecip2 = pRecip2->first_child;
- for (; pRecip2 != NULL; pRecip2 = pRecip2->next, iRecipient2--) {
+ for (; pRecip2 != nullptr; pRecip2 = pRecip2->next, iRecipient2--) {
if (DecryptMessage(pbEncoded, cbEncoded, fFailBody, pEnveloped,
pRecipients, iRecipient, pRecip2, iRecipient2)) {
passCount++;
@@ -402,11 +402,11 @@
HCOSE_RECIPIENT BuildRecipient(const cn_cbor *pRecipient)
{
HCOSE_RECIPIENT hRecip = COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecip == NULL) {
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecip == nullptr) {
returnError:
COSE_Recipient_Free(hRecip);
- return NULL;
+ return nullptr;
}
if (!SetSendingAttributes(
@@ -415,25 +415,25 @@
}
cn_cbor *cnKey = cn_cbor_mapget_string(pRecipient, "key");
- if (cnKey != NULL) {
+ if (cnKey != nullptr) {
cn_cbor *pkey = BuildKey(cnKey, true);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
- if (!COSE_Recipient_SetKey(hRecip, pkey, NULL)) {
+ if (!COSE_Recipient_SetKey(hRecip, pkey, nullptr)) {
goto returnError;
}
}
cnKey = cn_cbor_mapget_string(pRecipient, "recipients");
- if (cnKey != NULL) {
- for (cnKey = cnKey->first_child; cnKey != NULL; cnKey = cnKey->next) {
+ if (cnKey != nullptr) {
+ for (cnKey = cnKey->first_child; cnKey != nullptr; cnKey = cnKey->next) {
HCOSE_RECIPIENT hRecip2 = BuildRecipient(cnKey);
- if (hRecip2 == NULL) {
+ if (hRecip2 == nullptr) {
goto returnError;
}
- if (!COSE_Recipient_AddRecipient(hRecip, hRecip2, NULL)) {
+ if (!COSE_Recipient_AddRecipient(hRecip, hRecip2, nullptr)) {
goto returnError;
}
COSE_Recipient_Free(hRecip2);
@@ -441,11 +441,11 @@
}
cn_cbor *pSenderKey = cn_cbor_mapget_string(pRecipient, "sender_key");
- if (pSenderKey != NULL) {
+ if (pSenderKey != nullptr) {
cn_cbor *pSendKey = BuildKey(pSenderKey, false);
cn_cbor *pKid = cn_cbor_mapget_string(pSenderKey, "kid");
if (!COSE_Recipient_SetSenderKey(
- hRecip, pSendKey, (pKid == NULL) ? 2 : 1, NULL)) {
+ hRecip, pSendKey, (pKid == nullptr) ? 2 : 1, nullptr)) {
goto returnError;
}
}
@@ -453,20 +453,20 @@
#if INCLUDE_COUNTERSIGNATURE
// On the Recipient
cn_cbor *countersigns1 = cn_cbor_mapget_string(pRecipient, "countersign");
- if (countersigns1 != NULL) {
+ if (countersigns1 != nullptr) {
countersigns1 = cn_cbor_mapget_string(countersigns1, "signers");
cn_cbor *countersign = countersigns1->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -475,12 +475,12 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
goto returnError;
}
if (!COSE_Recipient_add_countersignature(
- hRecip, hCountersign, NULL)) {
+ hRecip, hCountersign, nullptr)) {
goto returnError;
}
@@ -502,17 +502,17 @@
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_ENVELOPED hEncObj = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (hEncObj != NULL) {
+ if (hEncObj != nullptr) {
COSE_Enveloped_Free(hEncObj);
}
@@ -520,13 +520,13 @@
return 0;
}
const cn_cbor *pEnveloped = cn_cbor_mapget_string(pInputs, "enveloped");
- if (pEnveloped == NULL) {
+ if (pEnveloped == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Enveloped_SetContent(
- hEncObj, pContent->v.bytes, pContent->length, NULL)) {
+ hEncObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -536,26 +536,26 @@
}
const cn_cbor *pAlg =
- COSE_Enveloped_map_get_int(hEncObj, 1, COSE_BOTH, NULL);
- if (pAlg == NULL) {
+ COSE_Enveloped_map_get_int(hEncObj, 1, COSE_BOTH, nullptr);
+ if (pAlg == nullptr) {
goto returnError;
}
const cn_cbor *pRecipients =
cn_cbor_mapget_string(pEnveloped, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pRecipients = pRecipients->first_child;
- for (iRecipient = 0; pRecipients != NULL;
+ for (iRecipient = 0; pRecipients != nullptr;
iRecipient++, pRecipients = pRecipients->next) {
HCOSE_RECIPIENT hRecip = BuildRecipient(pRecipients);
- if (hRecip == NULL) {
+ if (hRecip == nullptr) {
goto returnError;
}
- if (!COSE_Enveloped_AddRecipient(hEncObj, hRecip, NULL)) {
+ if (!COSE_Enveloped_AddRecipient(hEncObj, hRecip, nullptr)) {
COSE_Recipient_Free(hRecip);
goto returnError;
}
@@ -566,20 +566,20 @@
#if INCLUDE_COUNTERSIGNATURE
// On the Evneloped body
cn_cbor *countersigns1 = cn_cbor_mapget_string(pEnveloped, "countersign");
- if (countersigns1 != NULL) {
+ if (countersigns1 != nullptr) {
countersigns1 = cn_cbor_mapget_string(countersigns1, "signers");
cn_cbor *countersign = countersigns1->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -589,13 +589,13 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
if (!COSE_Enveloped_add_countersignature(
- hEncObj, hCountersign, NULL)) {
+ hEncObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -606,13 +606,12 @@
#endif
- if (!COSE_Enveloped_encrypt(hEncObj, NULL)) {
+ if (!COSE_Enveloped_encrypt(hEncObj, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hEncObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hEncObj, nullptr, 0, 0) + 1;
std::shared_ptr<byte> rgb = make_managed_array<byte>(cb);
-
cb = COSE_Encode((HCOSE)hEncObj, rgb.get(), 0, cb);
COSE_Enveloped_Free(hEncObj);
@@ -624,7 +623,7 @@
int EncryptMessage()
{
HCOSE_ENVELOPED hEncObj = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
byte rgbSecret[128 / 8] = {'a', 'b', 'c'};
int cbSecret = 128 / 8;
byte rgbKid[15] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l',
@@ -633,14 +632,14 @@
size_t cb;
byte *rgb;
const char *sz = "This is the content to be used";
- HCOSE_RECIPIENT hRecip = NULL;
+ HCOSE_RECIPIENT hRecip = nullptr;
- if (hEncObj == NULL) {
+ if (hEncObj == nullptr) {
errorReturn:
- if (hEncObj != NULL) {
+ if (hEncObj != nullptr) {
COSE_Enveloped_Free(hEncObj);
}
- if (hRecip != NULL) {
+ if (hRecip != nullptr) {
COSE_Recipient_Free(hRecip);
}
CFails++;
@@ -648,38 +647,38 @@
}
if (!COSE_Enveloped_map_put_int(hEncObj, COSE_Header_Algorithm,
cn_cbor_int_create(COSE_Algorithm_AES_CCM_16_64_128,
- CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
goto errorReturn;
}
- if (!COSE_Enveloped_SetContent(hEncObj, (byte *)sz, strlen(sz), NULL)) {
+ if (!COSE_Enveloped_SetContent(hEncObj, (byte *)sz, strlen(sz), nullptr)) {
goto errorReturn;
}
if (!COSE_Enveloped_map_put_int(hEncObj, COSE_Header_IV,
- cn_cbor_data_create(rgbKid, 13, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_UNPROTECT_ONLY, NULL)) {
+ cn_cbor_data_create(rgbKid, 13, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_UNPROTECT_ONLY, nullptr)) {
goto errorReturn;
}
hRecip = COSE_Recipient_from_shared_secret(
- rgbSecret, cbSecret, rgbKid, cbKid, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecip == NULL) {
+ rgbSecret, cbSecret, rgbKid, cbKid, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecip == nullptr) {
goto errorReturn;
}
- if (!COSE_Enveloped_AddRecipient(hEncObj, hRecip, NULL)) {
+ if (!COSE_Enveloped_AddRecipient(hEncObj, hRecip, nullptr)) {
goto errorReturn;
}
- if (!COSE_Enveloped_encrypt(hEncObj, NULL)) {
+ if (!COSE_Enveloped_encrypt(hEncObj, nullptr)) {
goto errorReturn;
}
- cb = COSE_Encode((HCOSE)hEncObj, NULL, 0, 0);
+ cb = COSE_Encode((HCOSE)hEncObj, nullptr, 0, 0);
if (cb < 1) {
goto errorReturn;
}
rgb = (byte *)malloc(cb);
- if (rgb == NULL) {
+ if (rgb == nullptr) {
goto errorReturn;
}
cb = COSE_Encode((HCOSE)hEncObj, rgb, 0, cb);
@@ -688,7 +687,7 @@
}
COSE_Recipient_Free(hRecip);
- hRecip = NULL;
+ hRecip = nullptr;
FILE *fp = fopen("test.cbor", "wb");
fwrite(rgb, cb, 1, fp);
@@ -698,7 +697,7 @@
char * szX;
int cbPrint = 0;
cn_cbor * cbor = COSE_get_cbor((HCOSE) hEncObj);
- cbPrint = cn_cbor_printer_write(NULL, 0, cbor, " ", "\r\n");
+ cbPrint = cn_cbor_printer_write(nullptr, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
@@ -706,35 +705,35 @@
#endif
COSE_Enveloped_Free(hEncObj);
- hEncObj = NULL;
+ hEncObj = nullptr;
/* */
int typ;
hEncObj = (HCOSE_ENVELOPED)COSE_Decode(rgb, (int)cb, &typ,
- COSE_enveloped_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncObj == NULL) {
+ COSE_enveloped_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncObj == nullptr) {
goto errorReturn;
}
int iRecipient = 0;
do {
- hRecip = COSE_Enveloped_GetRecipient(hEncObj, iRecipient, NULL);
- if (hRecip == NULL) {
+ hRecip = COSE_Enveloped_GetRecipient(hEncObj, iRecipient, nullptr);
+ if (hRecip == nullptr) {
break;
}
if (!COSE_Recipient_SetKey_secret(
- hRecip, rgbSecret, cbSecret, NULL, 0, NULL)) {
+ hRecip, rgbSecret, cbSecret, nullptr, 0, nullptr)) {
goto errorReturn;
}
- if (!COSE_Enveloped_decrypt(hEncObj, hRecip, NULL)) {
+ if (!COSE_Enveloped_decrypt(hEncObj, hRecip, nullptr)) {
goto errorReturn;
}
COSE_Recipient_Free(hRecip);
- hRecip = NULL;
+ hRecip = nullptr;
iRecipient += 1;
@@ -754,11 +753,11 @@
cn_cbor *pcnEncoded)
{
const cn_cbor *pInput = cn_cbor_mapget_string(pControl, "input");
- const cn_cbor *pFail = NULL;
- const cn_cbor *pEncrypt = NULL;
- const cn_cbor *pRecipients = NULL;
- cn_cbor *pkey = NULL;
- HCOSE_ENCRYPT hEnc = NULL;
+ const cn_cbor *pFail = nullptr;
+ const cn_cbor *pEncrypt = nullptr;
+ const cn_cbor *pRecipients = nullptr;
+ cn_cbor *pkey = nullptr;
+ HCOSE_ENCRYPT hEnc = nullptr;
int type;
bool fFail = false;
bool fFailBody = false;
@@ -766,10 +765,10 @@
if (false) {
exitHere:
- if (hEnc != NULL) {
+ if (hEnc != nullptr) {
COSE_Encrypt_Free(hEnc);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
@@ -793,7 +792,7 @@
return fAlgSupport ? 1 : 0;
returnError:
- if (hEnc != NULL) {
+ if (hEnc != nullptr) {
COSE_Encrypt_Free(hEnc);
}
@@ -802,29 +801,29 @@
}
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto returnError;
}
pEncrypt = cn_cbor_mapget_string(pInput, "encrypted");
- if ((pEncrypt == NULL) || (pEncrypt->type != CN_CBOR_MAP)) {
+ if ((pEncrypt == nullptr) || (pEncrypt->type != CN_CBOR_MAP)) {
goto returnError;
}
pRecipients = cn_cbor_mapget_string(pEncrypt, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pRecipients = pRecipients->first_child;
- if (pcnEncoded == NULL) {
+ if (pcnEncoded == nullptr) {
hEnc = (HCOSE_ENCRYPT)COSE_Decode(pbEncoded, cbEncoded, &type,
- COSE_encrypt_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEnc == NULL) {
+ COSE_encrypt_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEnc == nullptr) {
if (fFailBody) {
return 0;
}
@@ -835,8 +834,8 @@
}
else {
hEnc = COSE_Encrypt_Init_From_Object(
- pcnEncoded, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEnc == NULL) {
+ pcnEncoded, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEnc == nullptr) {
if (fFailBody) {
return 0;
}
@@ -852,18 +851,18 @@
}
pkey = BuildKey(cn_cbor_mapget_string(pRecipients, "key"), true);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
cn_cbor *k = cn_cbor_mapget_int(pkey, -1);
- if (k == NULL) {
+ if (k == nullptr) {
fFail = true;
goto exitHere;
}
cn_cbor *alg =
- COSE_Encrypt_map_get_int(hEnc, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ COSE_Encrypt_map_get_int(hEnc, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fAlgSupport = false;
fFail = false;
@@ -871,25 +870,25 @@
}
pFail = cn_cbor_mapget_string(pRecipients, "fail");
- if (COSE_Encrypt_decrypt(hEnc, k->v.bytes, k->length, NULL)) {
+ if (COSE_Encrypt_decrypt(hEnc, k->v.bytes, k->length, nullptr)) {
if (!fAlgSupport) {
fFail = true;
fAlgSupport = false;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ else if ((pFail != nullptr) && (pFail->type != CN_CBOR_TRUE)) {
fFail = true;
}
size_t cb;
const byte *pb;
- pb = COSE_Encrypt_GetContent(hEnc, &cb, NULL);
+ pb = COSE_Encrypt_GetContent(hEnc, &cb, nullptr);
}
else {
if (fAlgSupport) {
fFail = true;
fAlgSupport = false;
}
- else if ((pFail == NULL) || (pFail->type == CN_CBOR_FALSE)) {
+ else if ((pFail == nullptr) || (pFail->type == CN_CBOR_FALSE)) {
fFail = true;
}
}
@@ -899,10 +898,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList = cn_cbor_mapget_string(pEncrypt, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fFail = true;
goto exitHere;
}
@@ -910,7 +909,7 @@
bool forward = true;
if (COSE_Encrypt_map_get_int(hEnc, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto returnError;
}
@@ -920,7 +919,7 @@
HCOSE_COUNTERSIGN h =
COSE_Encrypt0_get_countersignature(hEnc, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -930,7 +929,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -944,7 +943,7 @@
}
alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
noSupportSign = true;
fAlgSupport = false;
@@ -977,43 +976,43 @@
byte *pbEncoded = GetCBOREncoding(pControl, &cbEncoded);
int fRet;
- fRet = _ValidateEncrypt(pControl, pbEncoded, cbEncoded, NULL);
+ fRet = _ValidateEncrypt(pControl, pbEncoded, cbEncoded, nullptr);
if (!fRet) {
return fRet;
}
cn_cbor *cbor =
- cn_cbor_decode(pbEncoded, cbEncoded, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (cbor == NULL) {
+ cn_cbor_decode(pbEncoded, cbEncoded, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (cbor == nullptr) {
return false;
}
- return _ValidateEncrypt(pControl, NULL, 0, cbor);
+ return _ValidateEncrypt(pControl, nullptr, 0, cbor);
}
int BuildEncryptMessage(const cn_cbor *pControl)
{
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
//
// We don't run this for all control sequences - skip those marked fail.
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_ENCRYPT hEncObj =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (hEncObj != NULL) {
+ if (hEncObj != nullptr) {
COSE_Encrypt_Free(hEncObj);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
@@ -1021,13 +1020,13 @@
return 1;
}
const cn_cbor *pEncrypt = cn_cbor_mapget_string(pInputs, "encrypted");
- if (pEncrypt == NULL) {
+ if (pEncrypt == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Encrypt_SetContent(
- hEncObj, pContent->v.bytes, pContent->length, NULL)) {
+ hEncObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -1036,19 +1035,19 @@
goto returnError;
}
- const cn_cbor *pAlg = COSE_Encrypt_map_get_int(hEncObj, 1, COSE_BOTH, NULL);
- if (pAlg == NULL) {
+ const cn_cbor *pAlg = COSE_Encrypt_map_get_int(hEncObj, 1, COSE_BOTH, nullptr);
+ if (pAlg == nullptr) {
goto returnError;
}
const cn_cbor *pRecipients = cn_cbor_mapget_string(pEncrypt, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pRecipients = pRecipients->first_child;
pkey = BuildKey(cn_cbor_mapget_string(pRecipients, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
@@ -1057,20 +1056,20 @@
#if INCLUDE_COUNTERSIGNATURE
// On the Encrypt0 body
cn_cbor *countersigns = cn_cbor_mapget_string(pEncrypt, "countersign");
- if (countersigns != NULL) {
+ if (countersigns != nullptr) {
countersigns = cn_cbor_mapget_string(countersigns, "signers");
cn_cbor *countersign = countersigns->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -1080,13 +1079,13 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
if (!COSE_Encrypt0_add_countersignature(
- hEncObj, hCountersign, NULL)) {
+ hEncObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -1097,19 +1096,19 @@
#endif
- if (!COSE_Encrypt_encrypt(hEncObj, k->v.bytes, k->length, NULL)) {
+ if (!COSE_Encrypt_encrypt(hEncObj, k->v.bytes, k->length, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hEncObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hEncObj, nullptr, 0, 0) + 1;
byte *rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hEncObj, rgb, 0, cb);
COSE_Encrypt_Free(hEncObj);
- int f = _ValidateEncrypt(pControl, rgb, cb, NULL);
+ int f = _ValidateEncrypt(pControl, rgb, cb, nullptr);
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
@@ -1121,29 +1120,29 @@
#if INCLUDE_ENCRYPT
void Enveloped_Corners()
{
- HCOSE_ENVELOPED hEncryptNULL = NULL;
- HCOSE_ENVELOPED hEncrypt = NULL;
- HCOSE_ENVELOPED hEncryptBad = NULL;
- HCOSE_RECIPIENT hRecipientNULL = NULL;
- HCOSE_RECIPIENT hRecipient = NULL;
- HCOSE_RECIPIENT hRecipientBad = NULL;
+ HCOSE_ENVELOPED hEncryptNULL = nullptr;
+ HCOSE_ENVELOPED hEncrypt = nullptr;
+ HCOSE_ENVELOPED hEncryptBad = nullptr;
+ HCOSE_RECIPIENT hRecipientNULL = nullptr;
+ HCOSE_RECIPIENT hRecipient = nullptr;
+ HCOSE_RECIPIENT hRecipientBad = nullptr;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
hEncrypt = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#if INCLUDE_MAC
hEncryptBad = (HCOSE_ENVELOPED)COSE_Mac_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hEncryptBad = (HCOSE_ENVELOPED)COSE_CALLOC(1, sizeof(COSE), context);
#endif
hRecipient = COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#if INCLUDE_MAC
hRecipientBad = (HCOSE_RECIPIENT)COSE_Mac_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hRecipientBad = (HCOSE_RECIPIENT)COSE_CALLOC(1, sizeof(COSE), context);
#endif
@@ -1152,16 +1151,16 @@
//
// Do parameter checks
- // - NULL handle
+ // - nullptr handle
// - Incorrect handle
- // - NULL pointer
+ // - nullptr pointer
//
CHECK_FAILURE(COSE_Enveloped_SetContent(hEncryptNULL, rgb, 10, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Enveloped_SetContent(hEncryptBad, rgb, 10, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Enveloped_SetContent(hEncrypt, NULL, 10, &cose_error),
+ CHECK_FAILURE(COSE_Enveloped_SetContent(hEncrypt, nullptr, 10, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Enveloped_map_put_int(
@@ -1174,7 +1173,7 @@
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Enveloped_map_put_int(
- hEncrypt, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ hEncrypt, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(
@@ -1221,7 +1220,7 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Enveloped_SetExternal(hEncryptBad, rgb, 10, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Enveloped_SetExternal(hEncrypt, NULL, 10, &cose_error),
+ CHECK_FAILURE(COSE_Enveloped_SetExternal(hEncrypt, nullptr, 10, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
if (!COSE_Enveloped_Free(hEncrypt)) {
@@ -1237,20 +1236,20 @@
// Bad Int algorithm
hEncrypt = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncrypt == NULL) {
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncrypt == nullptr) {
CFails++;
}
CHECK_RETURN(
COSE_Enveloped_SetContent(hEncrypt, (byte *)"Message", 7, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Enveloped_map_put_int(hEncrypt, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_NONE, CFails++);
hRecipient = COSE_Recipient_from_shared_secret(
- rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecipient == NULL) {
+ rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecipient == nullptr) {
CFails++;
}
CHECK_RETURN(COSE_Enveloped_AddRecipient(hEncrypt, hRecipient, &cose_error),
@@ -1261,8 +1260,8 @@
COSE_Enveloped_Free(hEncrypt);
hEncrypt = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncrypt == NULL) {
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncrypt == nullptr) {
CFails++;
}
CHECK_RETURN(
@@ -1270,12 +1269,12 @@
COSE_ERR_NONE, CFails++);
CHECK_RETURN(
COSE_Enveloped_map_put_int(hEncrypt, COSE_Header_Algorithm,
- cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL),
+ cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_PROTECT_ONLY, &cose_error),
COE_ERR_NONE, CFails++);
hRecipient = COSE_Recipient_from_shared_secret(
- rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecipient == NULL) {
+ rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecipient == nullptr) {
CFails++;
}
CHECK_RETURN(COSE_Enveloped_AddRecipient(hEncrypt, hRecipient, &cose_error),
@@ -1299,31 +1298,31 @@
#if INCLUDE_ENCRYPT0
void Encrypt_Corners()
{
- HCOSE_ENCRYPT hEncrypt = NULL;
+ HCOSE_ENCRYPT hEncrypt = nullptr;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
// Missing case - addref then release on item
- // NULL Handle checks
+ // nullptr Handle checks
- if (COSE_Encrypt_SetContent(hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Encrypt_SetContent(hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_map_get_int(hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Encrypt_map_get_int(hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_map_put_int(hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ if (COSE_Encrypt_map_put_int(hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_SetExternal(hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Encrypt_SetExternal(hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), NULL)) {
+ if (COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), nullptr)) {
CFails++;
}
- if (COSE_Encrypt_decrypt(hEncrypt, rgb, sizeof(rgb), NULL)) {
+ if (COSE_Encrypt_decrypt(hEncrypt, rgb, sizeof(rgb), nullptr)) {
CFails++;
}
if (COSE_Encrypt_Free((HCOSE_ENCRYPT)hEncrypt)) {
@@ -1334,27 +1333,27 @@
#if INCLUDE_MAC
hEncrypt = (HCOSE_ENCRYPT)COSE_Mac_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hEncrypt = (HCOSE_ENCRYPT)COSE_CALLOC(1, sizeof(COSE), context);
#endif
- if (COSE_Encrypt_SetContent(hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Encrypt_SetContent(hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_map_get_int(hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Encrypt_map_get_int(hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_map_put_int(hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ if (COSE_Encrypt_map_put_int(hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), NULL)) {
+ if (COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), nullptr)) {
CFails++;
}
- if (COSE_Encrypt_SetExternal(hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Encrypt_SetExternal(hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Encrypt_decrypt(hEncrypt, rgb, sizeof(rgb), NULL)) {
+ if (COSE_Encrypt_decrypt(hEncrypt, rgb, sizeof(rgb), nullptr)) {
CFails++;
}
if (COSE_Encrypt_Free(hEncrypt)) {
@@ -1365,16 +1364,16 @@
// Unsupported algorithm
hEncrypt =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncrypt == NULL) {
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncrypt == nullptr) {
CFails++;
}
- if (!COSE_Encrypt_SetContent(hEncrypt, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Encrypt_SetContent(hEncrypt, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Encrypt_map_put_int(hEncrypt, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), &cose_error),
@@ -1382,16 +1381,16 @@
COSE_Encrypt_Free(hEncrypt);
hEncrypt =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncrypt == NULL) {
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncrypt == nullptr) {
CFails++;
}
- if (!COSE_Encrypt_SetContent(hEncrypt, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Encrypt_SetContent(hEncrypt, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Encrypt_map_put_int(hEncrypt, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Encrypt_encrypt(hEncrypt, rgb, sizeof(rgb), &cose_error),
@@ -1404,11 +1403,11 @@
void Recipient_Corners()
{
HCOSE_RECIPIENT hRecip;
- HCOSE_RECIPIENT hRecipNULL = NULL;
+ HCOSE_RECIPIENT hRecipNULL = nullptr;
HCOSE_RECIPIENT hRecipBad;
cose_errback cose_error;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(1, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(1, CBOR_CONTEXT_PARAM_COMMA nullptr);
hRecip = COSE_Recipient_Init(
COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA & cose_error);
@@ -1421,32 +1420,32 @@
// Check for invalid parameters
- CHECK_FAILURE_PTR(COSE_Recipient_from_shared_secret(NULL, 0, NULL, 0,
+ CHECK_FAILURE_PTR(COSE_Recipient_from_shared_secret(nullptr, 0, nullptr, 0,
CBOR_CONTEXT_PARAM_COMMA & cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Recipient_SetKey_secret(
- hRecipNULL, rgb, sizeof(rgb), NULL, 0, &cose_error),
+ hRecipNULL, rgb, sizeof(rgb), nullptr, 0, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Recipient_SetKey_secret(
- hRecipBad, rgb, sizeof(rgb), NULL, 0, &cose_error),
+ hRecipBad, rgb, sizeof(rgb), nullptr, 0, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Recipient_SetKey_secret(
- hRecip, NULL, sizeof(rgb), NULL, 0, &cose_error),
+ hRecip, nullptr, sizeof(rgb), nullptr, 0, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Recipient_SetKey(hRecipNULL, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Recipient_SetKey(hRecipBad, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Recipient_SetKey(hRecip, NULL, &cose_error),
+ CHECK_FAILURE(COSE_Recipient_SetKey(hRecip, nullptr, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Recipient_SetSenderKey(hRecipNULL, cn, 0, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Recipient_SetSenderKey(hRecipBad, cn, 0, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Recipient_SetSenderKey(hRecip, NULL, 0, &cose_error),
+ CHECK_FAILURE(COSE_Recipient_SetSenderKey(hRecip, nullptr, 0, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Recipient_SetSenderKey(hRecip, cn, 3, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
@@ -1474,7 +1473,7 @@
hRecipBad, 1, cn, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Recipient_map_put_int(
- hRecip, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ hRecip, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Recipient_map_put_int(hRecip, 1, cn,
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
@@ -1494,20 +1493,20 @@
// Unknown algorithms
#if INCLUDE_ENCRYPT
HCOSE_ENVELOPED hEnv = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
hRecip = COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
CHECK_RETURN(COSE_Enveloped_map_put_int(hEnv, COSE_Header_Algorithm,
cn_cbor_int_create(COSE_Algorithm_AES_GCM_128,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Enveloped_SetContent(
hEnv, (byte *)"This the body", 13, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Recipient_map_put_int(hRecip, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_UNPROTECT_ONLY, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Enveloped_AddRecipient(hEnv, hRecip, &cose_error),
@@ -1519,13 +1518,13 @@
COSE_Recipient_Free(hRecip);
hEnv = COSE_Enveloped_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
hRecip = COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
CHECK_RETURN(COSE_Enveloped_map_put_int(hEnv, COSE_Header_Algorithm,
cn_cbor_int_create(COSE_Algorithm_AES_GCM_128,
- CBOR_CONTEXT_PARAM_COMMA NULL),
+ CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Enveloped_SetContent(
@@ -1533,7 +1532,7 @@
COSE_ERR_NONE, CFails++);
CHECK_RETURN(
COSE_Recipient_map_put_int(hRecip, COSE_Header_Algorithm,
- cn_cbor_string_create("Unknown", CBOR_CONTEXT_PARAM_COMMA NULL),
+ cn_cbor_string_create("Unknown", CBOR_CONTEXT_PARAM_COMMA nullptr),
COSE_UNPROTECT_ONLY, &cose_error),
COSE_ERR_NONE, CFails++);
CHECK_RETURN(COSE_Enveloped_AddRecipient(hEnv, hRecip, &cose_error),
diff --git a/test/Mac_test.cpp b/test/Mac_test.cpp
index c6fdc57..d3968a5 100644
--- a/test/Mac_test.cpp
+++ b/test/Mac_test.cpp
@@ -35,13 +35,13 @@
cose_errback error;
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
hMAC = (HCOSE_MAC)COSE_Decode(pbEncoded, cbEncoded, &type, COSE_mac_object,
- CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
if (fFailBody) {
return 0;
}
@@ -51,11 +51,11 @@
return 0;
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto failTest;
}
pMac = cn_cbor_mapget_string(pInput, "mac");
- if ((pMac == NULL) || (pMac->type != CN_CBOR_MAP)) {
+ if ((pMac == nullptr) || (pMac->type != CN_CBOR_MAP)) {
goto failTest;
}
@@ -64,23 +64,23 @@
}
pRecipients = cn_cbor_mapget_string(pMac, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto failTest;
}
iRecipient = (int)pRecipients->length - 1;
pRecipients = pRecipients->first_child;
- for (; pRecipients != NULL; iRecipient--, pRecipients = pRecipients->next) {
+ for (; pRecipients != nullptr; iRecipient--, pRecipients = pRecipients->next) {
fAlgNoSupport = false;
cn_cbor *pkey =
BuildKey(cn_cbor_mapget_string(pRecipients, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
fFail = true;
continue;
}
- HCOSE_RECIPIENT hRecip = COSE_Mac_GetRecipient(hMAC, iRecipient, NULL);
- if (hRecip == NULL) {
+ HCOSE_RECIPIENT hRecip = COSE_Mac_GetRecipient(hMAC, iRecipient, nullptr);
+ if (hRecip == nullptr) {
fFail = true;
continue;
}
@@ -91,31 +91,31 @@
goto failTest;
}
- if (!COSE_Recipient_SetKey(hRecip, pkey, NULL)) {
+ if (!COSE_Recipient_SetKey(hRecip, pkey, nullptr)) {
fFail = true;
COSE_Recipient_Free(hRecip);
continue;
}
cn_cbor *cnStatic = cn_cbor_mapget_string(pRecipients, "sender_key");
- if (cnStatic != NULL) {
+ if (cnStatic != nullptr) {
if (COSE_Recipient_map_get_int(
- hRecip, COSE_Header_ECDH_SPK, COSE_BOTH, NULL) == 0) {
+ hRecip, COSE_Header_ECDH_SPK, COSE_BOTH, nullptr) == 0) {
COSE_Recipient_map_put_int(hRecip, COSE_Header_ECDH_SPK,
- BuildKey(cnStatic, true), COSE_DONT_SEND, NULL);
+ BuildKey(cnStatic, true), COSE_DONT_SEND, nullptr);
}
}
pFail = cn_cbor_mapget_string(pRecipients, "fail");
cn_cbor *alg =
- COSE_Mac_map_get_int(hMAC, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ COSE_Mac_map_get_int(hMAC, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fAlgNoSupport = true;
}
alg = COSE_Recipient_map_get_int(
- hRecip, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ hRecip, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fAlgNoSupport = true;
}
@@ -124,7 +124,7 @@
if (fAlgNoSupport) {
fFail = true;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ else if ((pFail != nullptr) && (pFail->type != CN_CBOR_TRUE)) {
fFail = true;
}
}
@@ -137,7 +137,7 @@
else if (fAlgNoSupport) {
returnCode = 0;
}
- else if ((pFail == NULL) || (pFail->type == CN_CBOR_FALSE)) {
+ else if ((pFail == nullptr) || (pFail->type == CN_CBOR_FALSE)) {
fFail = true;
}
}
@@ -148,10 +148,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList =
cn_cbor_mapget_string(pRecipients, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
COSE_Recipient_Free(hRecip);
goto failTest;
}
@@ -159,7 +159,7 @@
bool forward = true;
if (COSE_Recipient_map_get_int(hRecip, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
COSE_Recipient_Free(hRecip);
goto failTest;
}
@@ -168,12 +168,12 @@
bool noSignSupport = false;
HCOSE_COUNTERSIGN h =
COSE_Recipient_get_countersignature(hRecip, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
continue;
}
alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fAlgNoSupport = true;
noSignSupport = true;
@@ -185,7 +185,7 @@
cn_cbor *pkeyCountersign = BuildKey(
cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -224,17 +224,17 @@
// Validate counter signatures on signers
cn_cbor *countersignList = cn_cbor_mapget_string(pMac, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
goto failTest;
}
int count = countersigners->length;
bool forward = true;
if (COSE_Mac_map_get_int(hMAC, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto failTest;
}
@@ -243,7 +243,7 @@
HCOSE_COUNTERSIGN h =
COSE_Mac_get_countersignature(hMAC, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -253,7 +253,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -267,7 +267,7 @@
}
cn_cbor *alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fAlgNoSupport = true;
noSignSupport = true;
@@ -320,40 +320,40 @@
int BuildMacMessage(const cn_cbor *pControl)
{
int iRecipient = 0;
- HCOSE_RECIPIENT hRecip = NULL;
+ HCOSE_RECIPIENT hRecip = nullptr;
//
// We don't run this for all control sequences - skip those marked fail.
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_MAC hMacObj =
- COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (hMacObj != NULL) {
+ if (hMacObj != nullptr) {
COSE_Mac_Free(hMacObj);
}
- if (hRecip != NULL) {
+ if (hRecip != nullptr) {
COSE_Recipient_Free(hRecip);
}
CFails += 1;
return 1;
}
const cn_cbor *pMac = cn_cbor_mapget_string(pInputs, "mac");
- if (pMac == NULL) {
+ if (pMac == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Mac_SetContent(
- hMacObj, pContent->v.bytes, pContent->length, NULL)) {
+ hMacObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -362,22 +362,22 @@
}
const cn_cbor *pRecipients = cn_cbor_mapget_string(pMac, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pRecipients = pRecipients->first_child;
- for (iRecipient = 0; pRecipients != NULL;
+ for (iRecipient = 0; pRecipients != nullptr;
iRecipient++, pRecipients = pRecipients->next) {
cn_cbor *pkey =
BuildKey(cn_cbor_mapget_string(pRecipients, "key"), true);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
hRecip = COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecip == NULL) {
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecip == nullptr) {
goto returnError;
}
@@ -386,19 +386,19 @@
goto returnError;
}
- if (!COSE_Recipient_SetKey(hRecip, pkey, NULL)) {
+ if (!COSE_Recipient_SetKey(hRecip, pkey, nullptr)) {
goto returnError;
}
cn_cbor *pSenderKey = cn_cbor_mapget_string(pRecipients, "sender_key");
- if (pSenderKey != NULL) {
+ if (pSenderKey != nullptr) {
cn_cbor *pSendKey = BuildKey(pSenderKey, false);
- if (!COSE_Recipient_SetSenderKey(hRecip, pSendKey, 2, NULL)) {
+ if (!COSE_Recipient_SetSenderKey(hRecip, pSendKey, 2, nullptr)) {
goto returnError;
}
}
- if (!COSE_Mac_AddRecipient(hMacObj, hRecip, NULL)) {
+ if (!COSE_Mac_AddRecipient(hMacObj, hRecip, nullptr)) {
goto returnError;
}
@@ -406,20 +406,20 @@
// On the Recipient
cn_cbor *countersigns1 =
cn_cbor_mapget_string(pRecipients, "countersign");
- if (countersigns1 != NULL) {
+ if (countersigns1 != nullptr) {
countersigns1 = cn_cbor_mapget_string(countersigns1, "signers");
cn_cbor *countersign = countersigns1->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -429,12 +429,12 @@
}
if (!COSE_CounterSign_SetKey(
- hCountersign, pkeyCountersign, NULL)) {
+ hCountersign, pkeyCountersign, nullptr)) {
goto returnError;
}
if (!COSE_Recipient_add_countersignature(
- hRecip, hCountersign, NULL)) {
+ hRecip, hCountersign, nullptr)) {
goto returnError;
}
@@ -445,26 +445,26 @@
#endif
COSE_Recipient_Free(hRecip);
- hRecip = NULL;
+ hRecip = nullptr;
}
#if INCLUDE_COUNTERSIGNATURE
// On the Evneloped body
cn_cbor *countersigns1 = cn_cbor_mapget_string(pMac, "countersign");
- if (countersigns1 != NULL) {
+ if (countersigns1 != nullptr) {
countersigns1 = cn_cbor_mapget_string(countersigns1, "signers");
cn_cbor *countersign = countersigns1->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -474,12 +474,12 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
- if (!COSE_Mac_add_countersignature(hMacObj, hCountersign, NULL)) {
+ if (!COSE_Mac_add_countersignature(hMacObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -490,11 +490,11 @@
#endif
- if (!COSE_Mac_encrypt(hMacObj, NULL)) {
+ if (!COSE_Mac_encrypt(hMacObj, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hMacObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hMacObj, nullptr, 0, 0) + 1;
byte *rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hMacObj, rgb, 0, cb);
@@ -509,17 +509,17 @@
int MacMessage()
{
HCOSE_MAC hEncObj =
- COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const char *sz = "This is the content to be used";
byte rgbSecret[256 / 8] = {'a', 'b', 'c'};
byte rgbKid[6] = {'a', 'b', 'c', 'd', 'e', 'f'};
int cbKid = 6;
size_t cb = 0;
- byte *rgb = NULL;
+ byte *rgb = nullptr;
- if (hEncObj == NULL) {
- errorReturn:
- if (hEncObj != NULL) {
+ if (hEncObj == nullptr) {
+ errorReturn:
+ if (hEncObj != nullptr) {
COSE_Mac_Free(hEncObj);
}
CFails++;
@@ -528,34 +528,34 @@
if (!COSE_Mac_map_put_int(hEncObj, COSE_Header_Algorithm,
cn_cbor_int_create(
- COSE_Algorithm_HMAC_256_256, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ COSE_Algorithm_HMAC_256_256, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
goto errorReturn;
}
- if (!COSE_Mac_SetContent(hEncObj, (byte *)sz, strlen(sz), NULL)) {
+ if (!COSE_Mac_SetContent(hEncObj, (byte *)sz, strlen(sz), nullptr)) {
goto errorReturn;
}
HCOSE_RECIPIENT hRecip = COSE_Recipient_from_shared_secret(rgbSecret,
- sizeof(rgbSecret), rgbKid, cbKid, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecip == NULL) {
+ sizeof(rgbSecret), rgbKid, cbKid, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecip == nullptr) {
goto errorReturn;
}
- if (!COSE_Mac_AddRecipient(hEncObj, hRecip, NULL)) {
+ if (!COSE_Mac_AddRecipient(hEncObj, hRecip, nullptr)) {
goto errorReturn;
}
- if (!COSE_Mac_encrypt(hEncObj, NULL)) {
+ if (!COSE_Mac_encrypt(hEncObj, nullptr)) {
goto errorReturn;
}
- cb = COSE_Encode((HCOSE)hEncObj, NULL, 0, 0);
+ cb = COSE_Encode((HCOSE)hEncObj, nullptr, 0, 0);
if (cb == 0) {
goto errorReturn;
}
rgb = (byte *)malloc(cb);
- if (rgb == NULL) {
+ if (rgb == nullptr) {
goto errorReturn;
}
cb = COSE_Encode((HCOSE)hEncObj, rgb, 0, cb);
@@ -573,7 +573,7 @@
char * szX;
int cbPrint = 0;
cn_cbor * cbor = COSE_get_cbor((HCOSE)hEncObj);
- cbPrint = cn_cbor_printer_write(NULL, 0, cbor, " ", "\r\n");
+ cbPrint = cn_cbor_printer_write(nullptr, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
@@ -582,8 +582,8 @@
int typ;
hEncObj = (HCOSE_MAC)COSE_Decode(
- rgb, (int)cb, &typ, COSE_mac_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hEncObj == NULL) {
+ rgb, (int)cb, &typ, COSE_mac_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hEncObj == nullptr) {
goto errorReturn;
}
@@ -591,17 +591,17 @@
do {
HCOSE_RECIPIENT hRecip2;
- hRecip2 = COSE_Mac_GetRecipient(hEncObj, iRecipient, NULL);
- if (hRecip2 == NULL) {
+ hRecip2 = COSE_Mac_GetRecipient(hEncObj, iRecipient, nullptr);
+ if (hRecip2 == nullptr) {
break;
}
if (!COSE_Recipient_SetKey_secret(
- hRecip2, rgbSecret, sizeof(rgbSecret), NULL, 0, NULL)) {
+ hRecip2, rgbSecret, sizeof(rgbSecret), nullptr, 0, nullptr)) {
goto errorReturn;
}
- if (!COSE_Mac_validate(hEncObj, hRecip2, NULL)) {
+ if (!COSE_Mac_validate(hEncObj, hRecip2, nullptr)) {
goto errorReturn;
}
@@ -623,11 +623,11 @@
size_t cbEncoded)
{
const cn_cbor *pInput = cn_cbor_mapget_string(pControl, "input");
- const cn_cbor *pFail = NULL;
- const cn_cbor *pMac = NULL;
- const cn_cbor *pRecipients = NULL;
- cn_cbor *pkey = NULL;
- HCOSE_MAC0 hMAC = NULL;
+ const cn_cbor *pFail = nullptr;
+ const cn_cbor *pMac = nullptr;
+ const cn_cbor *pRecipients = nullptr;
+ cn_cbor *pkey = nullptr;
+ HCOSE_MAC0 hMAC = nullptr;
int type;
bool fFail = false;
bool fFailBody = false;
@@ -635,10 +635,10 @@
if (false) {
exitHere:
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
- if (hMAC != NULL) {
+ if (hMAC != nullptr) {
COSE_Mac0_Free(hMAC);
}
@@ -648,7 +648,7 @@
return fUnsuportedAlg ? 0 : 1;
errorReturn:
- if (hMAC != NULL) {
+ if (hMAC != nullptr) {
COSE_Mac0_Free(hMAC);
}
CFails += 1;
@@ -656,13 +656,13 @@
}
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
hMAC = (HCOSE_MAC0)COSE_Decode(pbEncoded, cbEncoded, &type,
- COSE_mac0_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ COSE_mac0_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
if (fFailBody) {
return 0;
}
@@ -671,11 +671,11 @@
}
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto errorReturn;
}
pMac = cn_cbor_mapget_string(pInput, "mac0");
- if ((pMac == NULL) || (pMac->type != CN_CBOR_MAP)) {
+ if ((pMac == nullptr) || (pMac->type != CN_CBOR_MAP)) {
goto errorReturn;
}
@@ -684,14 +684,14 @@
}
pRecipients = cn_cbor_mapget_string(pMac, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto errorReturn;
}
pRecipients = pRecipients->first_child;
pkey = BuildKey(cn_cbor_mapget_string(pRecipients, "key"), true);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
fFail = true;
goto exitHere;
}
@@ -699,23 +699,23 @@
cn_cbor *k = cn_cbor_mapget_int(pkey, -1);
cn_cbor *alg =
- COSE_Mac0_map_get_int(hMAC, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ COSE_Mac0_map_get_int(hMAC, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fUnsuportedAlg = true;
}
pFail = cn_cbor_mapget_string(pRecipients, "fail");
- if (COSE_Mac0_validate(hMAC, k->v.bytes, k->length, NULL)) {
+ if (COSE_Mac0_validate(hMAC, k->v.bytes, k->length, nullptr)) {
if (fUnsuportedAlg) {
fFail = true;
fUnsuportedAlg = false;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ else if ((pFail != nullptr) && (pFail->type != CN_CBOR_TRUE)) {
fFail = true;
}
}
else {
- if ((pFail == NULL) || (pFail->type == CN_CBOR_FALSE)) {
+ if ((pFail == nullptr) || (pFail->type == CN_CBOR_FALSE)) {
fFail = true;
}
if (fUnsuportedAlg) {
@@ -728,10 +728,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList = cn_cbor_mapget_string(pMac, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fFail = true;
goto exitHere;
}
@@ -739,7 +739,7 @@
bool forward = true;
if (COSE_Mac0_map_get_int(hMAC, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
fFail = true;
goto exitHere;
}
@@ -749,7 +749,7 @@
HCOSE_COUNTERSIGN h =
COSE_Mac0_get_countersignature(hMAC, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -759,7 +759,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -773,7 +773,7 @@
}
alg = COSE_CounterSign_map_get_int(
- h, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ h, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fUnsuportedAlg = true;
noSignAlg = true;
@@ -818,24 +818,24 @@
int BuildMac0Message(const cn_cbor *pControl)
{
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
//
// We don't run this for all control sequences - skip those marked fail.
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_MAC0 hMacObj =
- COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
COSE_Mac0_Free(hMacObj);
@@ -843,13 +843,13 @@
return 1;
}
const cn_cbor *pMac = cn_cbor_mapget_string(pInputs, "mac0");
- if (pMac == NULL) {
+ if (pMac == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Mac0_SetContent(
- hMacObj, pContent->v.bytes, pContent->length, NULL)) {
+ hMacObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -859,14 +859,14 @@
}
const cn_cbor *pRecipients = cn_cbor_mapget_string(pMac, "recipients");
- if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) {
+ if ((pRecipients == nullptr) || (pRecipients->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pRecipients = pRecipients->first_child;
pkey = BuildKey(cn_cbor_mapget_string(pRecipients, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
@@ -875,20 +875,20 @@
#if INCLUDE_COUNTERSIGNATURE
// On the sign body
cn_cbor *countersigns = cn_cbor_mapget_string(pMac, "countersign");
- if (countersigns != NULL) {
+ if (countersigns != nullptr) {
countersigns = cn_cbor_mapget_string(countersigns, "signers");
cn_cbor *countersign = countersigns->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -898,12 +898,12 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
- if (!COSE_Mac0_add_countersignature(hMacObj, hCountersign, NULL)) {
+ if (!COSE_Mac0_add_countersignature(hMacObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -914,11 +914,11 @@
#endif
- if (!COSE_Mac0_encrypt(hMacObj, k->v.bytes, k->length, NULL)) {
+ if (!COSE_Mac0_encrypt(hMacObj, k->v.bytes, k->length, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hMacObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hMacObj, nullptr, 0, 0) + 1;
byte *rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hMacObj, rgb, 0, cb);
@@ -935,11 +935,11 @@
#if INCLUDE_MAC
void MAC_Corners()
{
- HCOSE_MAC hMAC = NULL;
- HCOSE_ENCRYPT hEncrypt = NULL;
- HCOSE_RECIPIENT hRecipient = NULL;
+ HCOSE_MAC hMAC = nullptr;
+ HCOSE_ENCRYPT hEncrypt = nullptr;
+ HCOSE_RECIPIENT hRecipient = nullptr;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
// Missing case - addref then release on item
@@ -947,34 +947,34 @@
// Incorrect algorithm
hMAC = (HCOSE_MAC)COSE_Mac_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
// Invalid Handle checks
- if (COSE_Mac_SetContent((HCOSE_MAC)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac_SetContent((HCOSE_MAC)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac_map_get_int((HCOSE_MAC)hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Mac_map_get_int((HCOSE_MAC)hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
if (COSE_Mac_map_put_int(
- (HCOSE_MAC)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ (HCOSE_MAC)hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Mac_encrypt((HCOSE_MAC)hEncrypt, NULL)) {
+ if (COSE_Mac_encrypt((HCOSE_MAC)hEncrypt, nullptr)) {
CFails++;
}
- if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) {
+ if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, nullptr)) {
CFails++;
}
if (COSE_Mac_AddRecipient(
- (HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) {
+ (HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, nullptr)) {
CFails++;
}
- if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, NULL)) {
+ if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, nullptr)) {
CFails++;
}
- if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, NULL)) {
+ if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, nullptr)) {
CFails++;
}
if (COSE_Mac_Free((HCOSE_MAC)hEncrypt)) {
@@ -983,35 +983,35 @@
#if INCLUDE_ENCRYPT0
hEncrypt =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hEncrypt = (HCOSE_ENCRYPT)COSE_CALLOC(1, sizeof(COSE), context);
#endif
- if (COSE_Mac_SetContent((HCOSE_MAC)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac_SetContent((HCOSE_MAC)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac_map_get_int((HCOSE_MAC)hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Mac_map_get_int((HCOSE_MAC)hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
if (COSE_Mac_map_put_int(
- (HCOSE_MAC)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ (HCOSE_MAC)hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Mac_encrypt((HCOSE_MAC)hEncrypt, NULL)) {
+ if (COSE_Mac_encrypt((HCOSE_MAC)hEncrypt, nullptr)) {
CFails++;
}
- if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) {
+ if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, nullptr)) {
CFails++;
}
if (COSE_Mac_AddRecipient(
- (HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) {
+ (HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, nullptr)) {
CFails++;
}
- if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, NULL)) {
+ if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, nullptr)) {
CFails++;
}
- if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, NULL)) {
+ if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, nullptr)) {
CFails++;
}
if (COSE_Mac_Free((HCOSE_MAC)hEncrypt)) {
@@ -1021,24 +1021,24 @@
//
// Unsupported algorithm
- hMAC = COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ hMAC = COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
CFails++;
}
- if (!COSE_Mac_SetContent(hMAC, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Mac_SetContent(hMAC, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Mac_map_put_int(hMAC, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
hRecipient = COSE_Recipient_from_shared_secret(
- rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecipient == NULL) {
+ rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecipient == nullptr) {
CFails++;
}
- if (!COSE_Mac_AddRecipient(hMAC, hRecipient, NULL)) {
+ if (!COSE_Mac_AddRecipient(hMAC, hRecipient, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Mac_encrypt(hMAC, &cose_error),
@@ -1046,24 +1046,24 @@
COSE_Mac_Free(hMAC);
COSE_Recipient_Free(hRecipient);
- hMAC = COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ hMAC = COSE_Mac_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
CFails++;
}
- if (!COSE_Mac_SetContent(hMAC, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Mac_SetContent(hMAC, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Mac_map_put_int(hMAC, COSE_Header_Algorithm,
- cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
hRecipient = COSE_Recipient_from_shared_secret(
- rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hRecipient == NULL) {
+ rgb, sizeof(rgb), rgb, sizeof(rgb), CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hRecipient == nullptr) {
CFails++;
}
- if (!COSE_Mac_AddRecipient(hMAC, hRecipient, NULL)) {
+ if (!COSE_Mac_AddRecipient(hMAC, hRecipient, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Mac_encrypt(hMAC, &cose_error),
@@ -1071,7 +1071,7 @@
COSE_Recipient_Free(hRecipient);
COSE_Mac_Free(hMAC);
- if (COSE_Mac_GetRecipient(hMAC, 9, NULL)) {
+ if (COSE_Mac_GetRecipient(hMAC, 9, nullptr)) {
CFails++;
}
}
@@ -1080,36 +1080,36 @@
#if INCLUDE_MAC0
void MAC0_Corners()
{
- HCOSE_ENCRYPT hEncrypt = NULL;
- HCOSE_MAC0 hMAC = NULL;
+ HCOSE_ENCRYPT hEncrypt = nullptr;
+ HCOSE_MAC0 hMAC = nullptr;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
hEncrypt =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
// Missing case - addref then release on item
// Invalid Handle checks
- if (COSE_Mac0_SetContent((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_SetContent((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_map_get_int((HCOSE_MAC0)hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Mac0_map_get_int((HCOSE_MAC0)hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
if (COSE_Mac0_map_put_int(
- (HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ (HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, NULL)) {
+ if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, nullptr)) {
CFails++;
}
if (COSE_Mac0_Free((HCOSE_MAC0)hEncrypt)) {
@@ -1117,25 +1117,25 @@
}
hEncrypt =
- COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Encrypt_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
- if (COSE_Mac0_SetContent((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_SetContent((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_map_get_int((HCOSE_MAC0)hEncrypt, 1, COSE_BOTH, NULL)) {
+ if (COSE_Mac0_map_get_int((HCOSE_MAC0)hEncrypt, 1, COSE_BOTH, nullptr)) {
CFails++;
}
if (COSE_Mac0_map_put_int(
- (HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) {
+ (HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) {
+ if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, nullptr)) {
CFails++;
}
- if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, NULL)) {
+ if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, nullptr)) {
CFails++;
}
@@ -1146,32 +1146,32 @@
//
// Unsupported algorithm
- hMAC = COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ hMAC = COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
CFails++;
}
- if (!COSE_Mac0_SetContent(hMAC, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Mac0_SetContent(hMAC, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Mac0_map_put_int(hMAC, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Mac0_encrypt(hMAC, rgb, sizeof(rgb), &cose_error),
COSE_ERR_UNKNOWN_ALGORITHM, CFails++);
COSE_Mac0_Free(hMAC);
- hMAC = COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hMAC == NULL) {
+ hMAC = COSE_Mac0_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hMAC == nullptr) {
CFails++;
}
- if (!COSE_Mac0_SetContent(hMAC, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Mac0_SetContent(hMAC, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Mac0_map_put_int(hMAC, COSE_Header_Algorithm,
- cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Mac0_encrypt(hMAC, rgb, sizeof(rgb), &cose_error),
diff --git a/test/Sign_test.cpp b/test/Sign_test.cpp
index 72765d1..14c5a87 100644
--- a/test/Sign_test.cpp
+++ b/test/Sign_test.cpp
@@ -31,39 +31,39 @@
const cn_cbor *pFail;
const cn_cbor *pSign;
const cn_cbor *pSigners;
- HCOSE_SIGN hSig = NULL;
- HCOSE_SIGNER hSigner = NULL;
+ HCOSE_SIGN hSig = nullptr;
+ HCOSE_SIGNER hSigner = nullptr;
int type;
int iSigner;
bool fFail = false;
bool fFailBody = false;
bool fNoSupportAlg = false;
- HCOSE_COUNTERSIGN h = NULL;
+ HCOSE_COUNTERSIGN h = nullptr;
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto returnError;
}
pSign = cn_cbor_mapget_string(pInput, "sign");
- if ((pSign == NULL) || (pSign->type != CN_CBOR_MAP)) {
+ if ((pSign == nullptr) || (pSign->type != CN_CBOR_MAP)) {
goto returnError;
}
pSigners = cn_cbor_mapget_string(pSign, "signers");
- if ((pSigners == NULL) || (pSigners->type != CN_CBOR_ARRAY)) {
+ if ((pSigners == nullptr) || (pSigners->type != CN_CBOR_ARRAY)) {
goto returnError;
}
iSigner = (int)pSigners->length - 1;
pSigners = pSigners->first_child;
- for (; pSigners != NULL; iSigner--, pSigners = pSigners->next) {
+ for (; pSigners != nullptr; iSigner--, pSigners = pSigners->next) {
hSig = (HCOSE_SIGN)COSE_Decode(pbEncoded, cbEncoded, &type,
- COSE_sign_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSig == NULL) {
+ COSE_sign_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSig == nullptr) {
if (fFailBody) {
return 0;
}
@@ -77,12 +77,12 @@
}
cn_cbor *pkey = BuildKey(cn_cbor_mapget_string(pSigners, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
- HCOSE_SIGNER hSigner = COSE_Sign_GetSigner(hSig, iSigner, NULL);
- if (hSigner == NULL) {
+ HCOSE_SIGNER hSigner = COSE_Sign_GetSigner(hSig, iSigner, nullptr);
+ if (hSigner == nullptr) {
goto returnError;
}
if (!SetReceivingAttributes(
@@ -90,7 +90,7 @@
goto returnError;
}
- if (!COSE_Signer_SetKey(hSigner, pkey, NULL)) {
+ if (!COSE_Signer_SetKey(hSigner, pkey, nullptr)) {
goto returnError;
}
@@ -101,11 +101,11 @@
}
pFail = cn_cbor_mapget_string(pSigners, "fail");
- if (COSE_Sign_validate(hSig, hSigner, NULL)) {
+ if (COSE_Sign_validate(hSig, hSigner, nullptr)) {
if (fNoSupportAlg) {
fFail = true;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ else if ((pFail != nullptr) && (pFail->type != CN_CBOR_TRUE)) {
fFail = true;
}
}
@@ -114,7 +114,7 @@
fFailBody = false;
fFail = false;
}
- else if ((pFail == NULL) || (pFail->type == CN_CBOR_FALSE)) {
+ else if ((pFail == nullptr) || (pFail->type == CN_CBOR_FALSE)) {
fFail = true;
}
}
@@ -123,10 +123,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList =
cn_cbor_mapget_string(pSigners, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fFail = true;
continue;
}
@@ -134,7 +134,7 @@
bool forward = true;
if (COSE_Signer_map_get_int(hSigner, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto returnError;
}
@@ -142,7 +142,7 @@
bool noSignAlg = false;
h = COSE_Signer_get_countersignature(hSigner, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -152,7 +152,7 @@
cn_cbor *pkeyCountersign = BuildKey(
cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -196,10 +196,10 @@
if (iSigner == 0) {
// Validate counter signatures on signers
countersignList = cn_cbor_mapget_string(pSign, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fFail = true;
continue;
}
@@ -207,7 +207,7 @@
bool forward = true;
if (COSE_Sign_map_get_int(hSig, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto returnError;
}
@@ -216,7 +216,7 @@
HCOSE_COUNTERSIGN h =
COSE_Sign_get_countersignature(hSig, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -226,7 +226,7 @@
cn_cbor *pkeyCountersign = BuildKey(
cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -284,10 +284,10 @@
return fNoSupportAlg ? 0 : 1;
returnError:
- if (hSigner != NULL) {
+ if (hSigner != nullptr) {
COSE_Signer_Free(hSigner);
}
- if (hSig != NULL) {
+ if (hSig != nullptr) {
COSE_Sign_Free(hSig);
}
@@ -306,27 +306,27 @@
int BuildSignedMessage(const cn_cbor *pControl)
{
int iSigner;
- HCOSE_SIGNER hSigner = NULL;
+ HCOSE_SIGNER hSigner = nullptr;
//
// We don't run this for all control sequences - skip those marked fail.
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_SIGN hSignObj =
- COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (hSignObj != NULL) {
+ if (hSignObj != nullptr) {
COSE_Sign_Free(hSignObj);
}
- if (hSigner != NULL) {
+ if (hSigner != nullptr) {
COSE_Signer_Free(hSigner);
}
@@ -334,13 +334,13 @@
return 1;
}
const cn_cbor *pSign = cn_cbor_mapget_string(pInputs, "sign");
- if (pSign == NULL) {
+ if (pSign == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Sign_SetContent(
- hSignObj, pContent->v.bytes, pContent->length, NULL)) {
+ hSignObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -350,19 +350,19 @@
}
const cn_cbor *pSigners = cn_cbor_mapget_string(pSign, "signers");
- if ((pSigners == NULL) || (pSigners->type != CN_CBOR_ARRAY)) {
+ if ((pSigners == nullptr) || (pSigners->type != CN_CBOR_ARRAY)) {
goto returnError;
}
pSigners = pSigners->first_child;
- for (iSigner = 0; pSigners != NULL; iSigner++, pSigners = pSigners->next) {
+ for (iSigner = 0; pSigners != nullptr; iSigner++, pSigners = pSigners->next) {
cn_cbor *pkey = BuildKey(cn_cbor_mapget_string(pSigners, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
- hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSigner == NULL) {
+ hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSigner == nullptr) {
goto returnError;
}
@@ -371,31 +371,31 @@
goto returnError;
}
- if (!COSE_Signer_SetKey(hSigner, pkey, NULL)) {
+ if (!COSE_Signer_SetKey(hSigner, pkey, nullptr)) {
goto returnError;
}
- if (!COSE_Sign_AddSigner(hSignObj, hSigner, NULL)) {
+ if (!COSE_Sign_AddSigner(hSignObj, hSigner, nullptr)) {
goto returnError;
}
#if INCLUDE_COUNTERSIGNATURE
// On the signer object
cn_cbor *countersigns = cn_cbor_mapget_string(pSigners, "countersign");
- if (countersigns != NULL) {
+ if (countersigns != nullptr) {
countersigns = cn_cbor_mapget_string(countersigns, "signers");
cn_cbor *countersign = countersigns->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -406,13 +406,13 @@
}
if (!COSE_CounterSign_SetKey(
- hCountersign, pkeyCountersign, NULL)) {
+ hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
if (!COSE_Signer_add_countersignature(
- hSigner, hCountersign, NULL)) {
+ hSigner, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -426,20 +426,20 @@
#if INCLUDE_COUNTERSIGNATURE
// On the sign body
cn_cbor *countersigns1 = cn_cbor_mapget_string(pSign, "countersign");
- if (countersigns1 != NULL) {
+ if (countersigns1 != nullptr) {
countersigns1 = cn_cbor_mapget_string(countersigns1, "signers");
cn_cbor *countersign = countersigns1->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -449,12 +449,12 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
- if (!COSE_Sign_add_countersignature(hSignObj, hCountersign, NULL)) {
+ if (!COSE_Sign_add_countersignature(hSignObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -465,11 +465,11 @@
#endif
- if (!COSE_Sign_Sign(hSignObj, NULL)) {
+ if (!COSE_Sign_Sign(hSignObj, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hSignObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hSignObj, nullptr, 0, 0) + 1;
byte *rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hSignObj, rgb, 0, cb);
@@ -484,7 +484,7 @@
int SignMessage()
{
HCOSE_SIGN hEncObj =
- COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const char *sz = "This is the content to be used";
size_t cb;
byte *rgb;
@@ -503,33 +503,33 @@
0xcd, 0xf2, 0x11, 0x22, 0xbc, 0xe2, 0xbd, 0x68, 0xb5, 0x28, 0x3e, 0x69,
0x07, 0x15, 0x4a, 0xd9, 0x11, 0x84, 0x0f, 0xa2, 0x08, 0xcf};
- cn_cbor *pkey = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *pkey = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, COSE_Key_Type,
- cn_cbor_int_create(COSE_Key_Type_EC2, CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_int_create(COSE_Key_Type_EC2, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, -1,
- cn_cbor_int_create(1, CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_int_create(1, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, -2,
- cn_cbor_data_create(rgbX, sizeof(rgbX), CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_data_create(rgbX, sizeof(rgbX), CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, -3,
- cn_cbor_data_create(rgbY, sizeof(rgbY), CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_data_create(rgbY, sizeof(rgbY), CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, COSE_Key_ID,
- cn_cbor_data_create(kid, sizeof(kid), CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_data_create(kid, sizeof(kid), CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
cn_cbor_mapput_int(pkey, -4,
- cn_cbor_data_create(rgbD, sizeof(rgbD), CBOR_CONTEXT_PARAM_COMMA NULL),
- CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor_data_create(rgbD, sizeof(rgbD), CBOR_CONTEXT_PARAM_COMMA nullptr),
+ CBOR_CONTEXT_PARAM_COMMA nullptr);
- COSE_Sign_SetContent(hEncObj, (byte *)sz, strlen(sz), NULL);
+ COSE_Sign_SetContent(hEncObj, (byte *)sz, strlen(sz), nullptr);
COSE_Signer_Free(COSE_Sign_add_signer(
- hEncObj, pkey, COSE_Algorithm_ECDSA_SHA_256, NULL));
+ hEncObj, pkey, COSE_Algorithm_ECDSA_SHA_256, nullptr));
- COSE_Sign_Sign(hEncObj, NULL);
+ COSE_Sign_Sign(hEncObj, nullptr);
- cb = COSE_Encode((HCOSE)hEncObj, NULL, 0, 0) + 1;
+ cb = COSE_Encode((HCOSE)hEncObj, nullptr, 0, 0) + 1;
rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hEncObj, rgb, 0, cb);
@@ -543,7 +543,7 @@
char * szX;
int cbPrint = 0;
cn_cbor * cbor = COSE_get_cbor((HCOSE)hEncObj);
- cbPrint = cn_cbor_printer_write(NULL, 0, cbor, " ", "\r\n");
+ cbPrint = cn_cbor_printer_write(nullptr, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
@@ -554,19 +554,19 @@
int typ;
hEncObj = (HCOSE_SIGN)COSE_Decode(
- rgb, (int)cb, &typ, COSE_sign_object, CBOR_CONTEXT_PARAM_COMMA NULL);
+ rgb, (int)cb, &typ, COSE_sign_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
#if 0
int iSigner = 0;
do {
HCOSE_RECIPIENT hSigner;
- hSigner = COSE_Encrypt_GetRecipient(hEncObj, iSigner, NULL);
- if (hSigner == NULL) break;
+ hSigner = COSE_Encrypt_GetRecipient(hEncObj, iSigner, nullptr);
+ if (hSigner == nullptr) break;
- COSE_Recipient_SetKey(hSigner, rgbSecret, cbSecret, NULL);
+ COSE_Recipient_SetKey(hSigner, rgbSecret, cbSecret, nullptr);
- COSE_Encrypt_decrypt(hEncObj, hSigner, NULL);
+ COSE_Encrypt_decrypt(hEncObj, hSigner, nullptr);
iSigner += 1;
@@ -587,8 +587,8 @@
const cn_cbor *pInput = cn_cbor_mapget_string(pControl, "input");
const cn_cbor *pFail;
const cn_cbor *pSign;
- HCOSE_SIGN1 hSig = NULL;
- cn_cbor *pkey = NULL;
+ HCOSE_SIGN1 hSig = nullptr;
+ cn_cbor *pkey = nullptr;
int type;
bool fFail = false;
bool fFailBody = false;
@@ -596,20 +596,20 @@
if (false) {
exitHere:
- if (hSig != NULL) {
+ if (hSig != nullptr) {
COSE_Sign1_Free(hSig);
}
if (fFail) {
CFails += 1;
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
return fNoAlgSupport ? 0 : 1;
returnError:
- if (hSig != NULL) {
+ if (hSig != nullptr) {
COSE_Sign1_Free(hSig);
}
@@ -618,21 +618,21 @@
}
pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
fFailBody = true;
}
- if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) {
+ if ((pInput == nullptr) || (pInput->type != CN_CBOR_MAP)) {
goto returnError;
}
pSign = cn_cbor_mapget_string(pInput, "sign0");
- if ((pSign == NULL) || (pSign->type != CN_CBOR_MAP)) {
+ if ((pSign == nullptr) || (pSign->type != CN_CBOR_MAP)) {
goto returnError;
}
hSig = (HCOSE_SIGN1)COSE_Decode(pbEncoded, cbEncoded, &type,
- COSE_sign1_object, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSig == NULL) {
+ COSE_sign1_object, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSig == nullptr) {
if (fFailBody) {
return 0;
}
@@ -647,23 +647,23 @@
}
pkey = BuildKey(cn_cbor_mapget_string(pSign, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
fFail = true;
goto exitHere;
}
cn_cbor *alg =
- COSE_Sign1_map_get_int(hSig, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ COSE_Sign1_map_get_int(hSig, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fNoAlgSupport = true;
}
pFail = cn_cbor_mapget_string(pInput, "fail");
- if (COSE_Sign1_validate(hSig, pkey, NULL)) {
+ if (COSE_Sign1_validate(hSig, pkey, nullptr)) {
if (fNoAlgSupport) {
fFail = true;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ else if ((pFail != nullptr) && (pFail->type != CN_CBOR_TRUE)) {
fFail = true;
}
}
@@ -672,7 +672,7 @@
fFailBody = false;
fFail = false;
}
- else if ((pFail == NULL) || (pFail->type == CN_CBOR_FALSE)) {
+ else if ((pFail == nullptr) || (pFail->type == CN_CBOR_FALSE)) {
fFail = true;
}
}
@@ -682,10 +682,10 @@
// Validate counter signatures on signers
cn_cbor *countersignList = cn_cbor_mapget_string(pSign, "countersign");
- if (countersignList != NULL) {
+ if (countersignList != nullptr) {
cn_cbor *countersigners =
cn_cbor_mapget_string(countersignList, "signers");
- if (countersigners == NULL) {
+ if (countersigners == nullptr) {
fFail = true;
goto exitHere;
}
@@ -693,7 +693,7 @@
bool forward = true;
if (COSE_Sign1_map_get_int(hSig, COSE_Header_CounterSign,
- COSE_UNPROTECT_ONLY, 0) == NULL) {
+ COSE_UNPROTECT_ONLY, 0) == nullptr) {
goto returnError;
}
@@ -702,7 +702,7 @@
HCOSE_COUNTERSIGN h =
COSE_Sign1_get_countersignature(hSig, counterNo, 0);
- if (h == NULL) {
+ if (h == nullptr) {
fFail = true;
continue;
}
@@ -712,7 +712,7 @@
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(counterSigner, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
fFail = true;
COSE_CounterSign_Free(h);
continue;
@@ -726,7 +726,7 @@
}
alg = COSE_Sign1_map_get_int(
- hSig, COSE_Header_Algorithm, COSE_BOTH, NULL);
+ hSig, COSE_Header_Algorithm, COSE_BOTH, nullptr);
if (!IsAlgorithmSupported(alg)) {
fNoAlgSupport = true;
noSignAlg = true;
@@ -771,39 +771,39 @@
int BuildSign1Message(const cn_cbor *pControl)
{
- cn_cbor *pkey = NULL;
+ cn_cbor *pkey = nullptr;
//
// We don't run this for all control sequences - skip those marked fail.
//
const cn_cbor *pFail = cn_cbor_mapget_string(pControl, "fail");
- if ((pFail != NULL) && (pFail->type == CN_CBOR_TRUE)) {
+ if ((pFail != nullptr) && (pFail->type == CN_CBOR_TRUE)) {
return 0;
}
HCOSE_SIGN1 hSignObj =
- COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
const cn_cbor *pInputs = cn_cbor_mapget_string(pControl, "input");
- if (pInputs == NULL) {
+ if (pInputs == nullptr) {
returnError:
- if (hSignObj != NULL) {
+ if (hSignObj != nullptr) {
COSE_Sign1_Free(hSignObj);
}
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
CFails += 1;
return 1;
}
const cn_cbor *pSign = cn_cbor_mapget_string(pInputs, "sign0");
- if (pSign == NULL) {
+ if (pSign == nullptr) {
goto returnError;
}
const cn_cbor *pContent = cn_cbor_mapget_string(pInputs, "plaintext");
if (!COSE_Sign1_SetContent(
- hSignObj, pContent->v.bytes, pContent->length, NULL)) {
+ hSignObj, pContent->v.bytes, pContent->length, nullptr)) {
goto returnError;
}
@@ -813,27 +813,27 @@
}
pkey = BuildKey(cn_cbor_mapget_string(pSign, "key"), false);
- if (pkey == NULL) {
+ if (pkey == nullptr) {
goto returnError;
}
#if INCLUDE_COUNTERSIGNATURE
// On the sign body
cn_cbor *countersigns = cn_cbor_mapget_string(pSign, "countersign");
- if (countersigns != NULL) {
+ if (countersigns != nullptr) {
countersigns = cn_cbor_mapget_string(countersigns, "signers");
cn_cbor *countersign = countersigns->first_child;
- for (; countersign != NULL; countersign = countersign->next) {
+ for (; countersign != nullptr; countersign = countersign->next) {
cn_cbor *pkeyCountersign =
BuildKey(cn_cbor_mapget_string(countersign, "key"), false);
- if (pkeyCountersign == NULL) {
+ if (pkeyCountersign == nullptr) {
goto returnError;
}
HCOSE_COUNTERSIGN hCountersign =
- COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hCountersign == NULL) {
+ COSE_CounterSign_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hCountersign == nullptr) {
goto returnError;
}
@@ -843,13 +843,13 @@
goto returnError;
}
- if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, NULL)) {
+ if (!COSE_CounterSign_SetKey(hCountersign, pkeyCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
if (!COSE_Sign1_add_countersignature(
- hSignObj, hCountersign, NULL)) {
+ hSignObj, hCountersign, nullptr)) {
COSE_CounterSign_Free(hCountersign);
goto returnError;
}
@@ -860,16 +860,16 @@
#endif
- if (!COSE_Sign1_Sign(hSignObj, pkey, NULL)) {
+ if (!COSE_Sign1_Sign(hSignObj, pkey, nullptr)) {
goto returnError;
}
- size_t cb = COSE_Encode((HCOSE)hSignObj, NULL, 0, 0) + 1;
+ size_t cb = COSE_Encode((HCOSE)hSignObj, nullptr, 0, 0) + 1;
byte *rgb = (byte *)malloc(cb);
cb = COSE_Encode((HCOSE)hSignObj, rgb, 0, cb);
COSE_Sign1_Free(hSignObj);
- if (pkey != NULL) {
+ if (pkey != nullptr) {
CN_CBOR_FREE(pkey, context);
}
@@ -883,28 +883,28 @@
#if INCLUDE_SIGN
void Sign_Corners()
{
- HCOSE_SIGN hSign = NULL;
+ HCOSE_SIGN hSign = nullptr;
HCOSE_SIGN hSignBad;
- HCOSE_SIGN hSignNULL = NULL;
- HCOSE_SIGNER hSigner = NULL;
+ HCOSE_SIGN hSignNULL = nullptr;
+ HCOSE_SIGNER hSigner = nullptr;
HCOSE_SIGNER hSignerBad;
- HCOSE_SIGNER hSignerNULL = NULL;
+ HCOSE_SIGNER hSignerNULL = nullptr;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
- hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#if INCLUDE_SIGN1
hSignBad = (HCOSE_SIGN)COSE_Sign1_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hSignBad = (HCOSE_SIGN)COSE_CALLOC(1, sizeof(COSE), context);
#endif
- hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
+ hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
#if INCLUDE_ENCRYPT || INCLUDE_MAC
hSignerBad = (HCOSE_SIGNER)COSE_Recipient_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hSignerBad = (HCOSE_SIGNER)COSE_CALLOC(1, sizeof(COSE), context);
#endif
@@ -922,7 +922,7 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Sign_SetContent(hSignBad, rgb, sizeof(rgb), &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Sign_SetContent(hSign, NULL, sizeof(rgb), &cose_error),
+ CHECK_FAILURE(COSE_Sign_SetContent(hSign, nullptr, sizeof(rgb), &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign_map_get_int(hSignNULL, 1, COSE_BOTH, &cose_error),
@@ -939,7 +939,7 @@
COSE_Sign_map_put_int(hSignBad, 1, cn, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(
- COSE_Sign_map_put_int(hSign, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ COSE_Sign_map_put_int(hSign, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign_map_put_int(hSign, 1, cn,
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
@@ -960,7 +960,7 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Sign_add_signer(hSignBad, cn, 0, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Sign_add_signer(hSign, NULL, 0, &cose_error),
+ CHECK_FAILURE(COSE_Sign_add_signer(hSign, nullptr, 0, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign_GetSigner(hSignNULL, 1, &cose_error),
@@ -988,7 +988,7 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Signer_SetKey(hSignerBad, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Signer_SetKey(hSigner, NULL, &cose_error),
+ CHECK_FAILURE(COSE_Signer_SetKey(hSigner, nullptr, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(
@@ -1007,7 +1007,7 @@
hSignerBad, 1, cn, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Signer_map_put_int(
- hSigner, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ hSigner, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Signer_map_put_int(hSigner, 1, cn,
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
@@ -1025,63 +1025,63 @@
//
// Unsupported algorithm
- hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSign == NULL) {
+ hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSign == nullptr) {
CFails++;
}
- hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSigner == NULL) {
+ hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSigner == nullptr) {
CFails++;
}
- if (!COSE_Sign_SetContent(hSign, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Sign_SetContent(hSign, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Signer_map_put_int(hSigner, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (!COSE_Sign_AddSigner(hSign, hSigner, NULL)) {
+ if (!COSE_Sign_AddSigner(hSign, hSigner, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Sign_Sign(hSign, &cose_error),
COSE_ERR_UNKNOWN_ALGORITHM, CFails++);
- if (COSE_Sign_GetSigner(hSign, 9, NULL)) {
+ if (COSE_Sign_GetSigner(hSign, 9, nullptr)) {
CFails++;
}
COSE_Sign_Free(hSign);
COSE_Signer_Free(hSigner);
- hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSign == NULL) {
+ hSign = COSE_Sign_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSign == nullptr) {
CFails++;
}
- hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSigner == NULL) {
+ hSigner = COSE_Signer_Init(CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSigner == nullptr) {
CFails++;
}
- if (!COSE_Sign_SetContent(hSign, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Sign_SetContent(hSign, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Signer_map_put_int(hSigner, COSE_Header_Algorithm,
- cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
- if (!COSE_Sign_AddSigner(hSign, hSigner, NULL)) {
+ if (!COSE_Sign_AddSigner(hSign, hSigner, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Sign_Sign(hSign, &cose_error),
COSE_ERR_UNKNOWN_ALGORITHM, CFails++);
- if (COSE_Sign_GetSigner(hSign, 9, NULL)) {
+ if (COSE_Sign_GetSigner(hSign, 9, nullptr)) {
CFails++;
}
cn = COSE_Signer_map_get_int(
hSigner, COSE_Header_Algorithm, COSE_BOTH, &cose_error);
- if (cn != NULL) {
+ if (cn != nullptr) {
if (cn->type != CN_CBOR_TEXT) {
CFails++;
}
@@ -1095,19 +1095,19 @@
#if INCLUDE_SIGN1
void Sign1_Corners()
{
- HCOSE_SIGN1 hSign = NULL;
- HCOSE_SIGN1 hSignNULL = NULL;
+ HCOSE_SIGN1 hSign = nullptr;
+ HCOSE_SIGN1 hSignNULL = nullptr;
HCOSE_SIGN1 hSignBad;
byte rgb[10];
- cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+ cn_cbor *cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA nullptr);
cose_errback cose_error;
hSign =
- COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#if INCLUDE_SIGN
hSignBad = (HCOSE_SIGN1)COSE_Sign_Init(
- COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
+ COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
#else
hSignBad = (HCOSE_SIGN1)COSE_CALLOC(1, sizeof(COSE), context);
#endif
@@ -1121,7 +1121,7 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Sign1_SetContent(hSignBad, rgb, 10, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Sign1_SetContent(hSign, NULL, 10, &cose_error),
+ CHECK_FAILURE(COSE_Sign1_SetContent(hSign, nullptr, 10, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign1_map_get_int(hSignNULL, 1, COSE_BOTH, &cose_error),
@@ -1138,7 +1138,7 @@
COSE_Sign1_map_put_int(hSignBad, 1, cn, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(
- COSE_Sign1_map_put_int(hSign, 1, NULL, COSE_PROTECT_ONLY, &cose_error),
+ COSE_Sign1_map_put_int(hSign, 1, nullptr, COSE_PROTECT_ONLY, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign1_map_put_int(hSign, 1, cn,
COSE_PROTECT_ONLY | COSE_UNPROTECT_ONLY, &cose_error),
@@ -1148,14 +1148,14 @@
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Sign1_Sign(hSignBad, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Sign1_Sign(hSign, NULL, &cose_error),
+ CHECK_FAILURE(COSE_Sign1_Sign(hSign, nullptr, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(COSE_Sign1_validate(hSignNULL, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
CHECK_FAILURE(COSE_Sign1_validate(hSignBad, cn, &cose_error),
COSE_ERR_INVALID_HANDLE, CFails++);
- CHECK_FAILURE(COSE_Sign1_validate(hSign, NULL, &cose_error),
+ CHECK_FAILURE(COSE_Sign1_validate(hSign, nullptr, &cose_error),
COSE_ERR_INVALID_PARAMETER, CFails++);
CHECK_FAILURE(
@@ -1171,18 +1171,18 @@
// Unsupported algorithm
hSign =
- COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSign == NULL) {
+ COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSign == nullptr) {
CFails++;
}
- cn = cn_cbor_int_create(15, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (!COSE_Sign1_SetContent(hSign, (byte *)"Message", 7, NULL)) {
+ cn = cn_cbor_int_create(15, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (!COSE_Sign1_SetContent(hSign, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Sign1_map_put_int(hSign, COSE_Header_Algorithm,
- cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Sign1_Sign(hSign, cn, &cose_error),
@@ -1190,18 +1190,18 @@
COSE_Sign1_Free(hSign);
hSign =
- COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA NULL);
- if (hSign == NULL) {
+ COSE_Sign1_Init(COSE_INIT_FLAGS_NONE, CBOR_CONTEXT_PARAM_COMMA nullptr);
+ if (hSign == nullptr) {
CFails++;
}
- if (!COSE_Sign1_SetContent(hSign, (byte *)"Message", 7, NULL)) {
+ if (!COSE_Sign1_SetContent(hSign, (byte *)"Message", 7, nullptr)) {
CFails++;
}
if (!COSE_Sign1_map_put_int(hSign, COSE_Header_Algorithm,
- cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL),
- COSE_PROTECT_ONLY, NULL)) {
+ cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA nullptr),
+ COSE_PROTECT_ONLY, nullptr)) {
CFails++;
}
CHECK_FAILURE(COSE_Sign1_Sign(hSign, cn, &cose_error),