refactor: fix some clang-tidy warnings and remove unneeded extern
diff --git a/.clang-tidy b/.clang-tidy
index d460f98..d3e1aa5 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -24,5 +24,12 @@
-google-readability-namespace-comments, \
-llvm-namespace-comment, \
-modernize-use-trailing-return-type, \
--fuchsia-default-arguments-calls \
+-fuchsia-default-arguments-calls, \
+# TODO remove following lines, \
+-readability-braces-around-statements, \
+-cppcoreguidelines-avoid-magic-numbers, \
+-hicpp-braces-around-statements, \
+-readability-magic-numbers, \
+-cppcoreguidelines-avoid-magic-numbers, \
+-cppcoreguidelines-init-variables, \
"
diff --git a/include/cose/cose.h b/include/cose/cose.h
index dbb08f3..e84235f 100644
--- a/include/cose/cose.h
+++ b/include/cose/cose.h
@@ -7,7 +7,7 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+
typedef unsigned char byte;
typedef struct _cose * HCOSE;
@@ -223,10 +223,10 @@
bool COSE_Enveloped_encrypt(HCOSE_ENVELOPED cose, cose_errback * perror);
bool COSE_Enveloped_decrypt(HCOSE_ENVELOPED, HCOSE_RECIPIENT, cose_errback * perr);
-extern bool COSE_Enveloped_AddRecipient(HCOSE_ENVELOPED hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
+bool COSE_Enveloped_AddRecipient(HCOSE_ENVELOPED hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
HCOSE_RECIPIENT COSE_Enveloped_GetRecipient(HCOSE_ENVELOPED cose, int iRecipient, cose_errback * perr);
-extern bool COSE_Enveloped_AddCounterSigner(HCOSE_ENCRYPT hEnv, HCOSE_COUNTERSIGN hSign, cose_errback * perr);
+bool COSE_Enveloped_AddCounterSigner(HCOSE_ENCRYPT hEnv, HCOSE_COUNTERSIGN hSign, cose_errback * perr);
HCOSE_COUNTERSIGN COSE_Enveloped_GetCounterSigner(HCOSE_ENCRYPT, int iSigner, cose_errback * perr);
/*
@@ -245,7 +245,7 @@
cn_cbor * COSE_Recipient_map_get_string(HCOSE_RECIPIENT cose, const char * key, int flags, cose_errback * errp);
cn_cbor * COSE_Recipient_map_get_int(HCOSE_RECIPIENT cose, int key, int flags, cose_errback * errp);
-extern bool COSE_Recipient_AddRecipient(HCOSE_RECIPIENT hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
+bool COSE_Recipient_AddRecipient(HCOSE_RECIPIENT hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
HCOSE_RECIPIENT COSE_Recipient_GetRecipient(HCOSE_RECIPIENT cose, int iRecipient, cose_errback * perr);
@@ -286,7 +286,7 @@
bool COSE_Mac_encrypt(HCOSE_MAC cose, cose_errback * perror);
bool COSE_Mac_validate(HCOSE_MAC, HCOSE_RECIPIENT, cose_errback * perr);
-extern bool COSE_Mac_AddRecipient(HCOSE_MAC hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
+bool COSE_Mac_AddRecipient(HCOSE_MAC hMac, HCOSE_RECIPIENT hRecip, cose_errback * perr);
HCOSE_RECIPIENT COSE_Mac_GetRecipient(HCOSE_MAC cose, int iRecipient, cose_errback * perr);
// MAC0 calls
@@ -312,7 +312,7 @@
bool COSE_Sign_SetContent(HCOSE_SIGN cose, const byte * rgbContent, size_t cbContent, cose_errback * errp);
HCOSE_SIGNER COSE_Sign_add_signer(HCOSE_SIGN cose, const cn_cbor * pkey, int algId, cose_errback * perr);
-extern bool COSE_Sign_AddSigner(HCOSE_SIGN hSign, HCOSE_SIGNER hSigner, cose_errback * perr);
+bool COSE_Sign_AddSigner(HCOSE_SIGN hSign, HCOSE_SIGNER hSigner, cose_errback * perr);
bool COSE_Sign_Sign(HCOSE_SIGN h, cose_errback * perr);
HCOSE_SIGNER COSE_Sign_GetSigner(HCOSE_SIGN cose, int iSigner, cose_errback * perr);
bool COSE_Sign_validate(HCOSE_SIGN hSign, HCOSE_SIGNER hSigner, cose_errback * perr);
@@ -323,8 +323,8 @@
HCOSE_SIGNER COSE_Signer_Init(CBOR_CONTEXT_COMMA cose_errback * perror);
bool COSE_Signer_Free(HCOSE_SIGNER cose);
bool COSE_Signer_SetKey(HCOSE_SIGNER hSigner, const cn_cbor * pkey, cose_errback * perr);
-extern cn_cbor * COSE_Signer_map_get_int(HCOSE_SIGNER h, int key, int flags, cose_errback * perr);
-extern bool COSE_Signer_map_put_int(HCOSE_SIGNER cose, int key, cn_cbor * value, int flags, cose_errback * errp);
+cn_cbor * COSE_Signer_map_get_int(HCOSE_SIGNER h, int key, int flags, cose_errback * perr);
+bool COSE_Signer_map_put_int(HCOSE_SIGNER cose, int key, cn_cbor * value, int flags, cose_errback * errp);
bool COSE_Signer_SetExternal(HCOSE_SIGNER hcose, const byte * pbExternalData, size_t cbExternalData, cose_errback * perr);
diff --git a/src/Encrypt.c b/src/Encrypt.c
index 8e59329..806a0dd 100644
--- a/src/Encrypt.c
+++ b/src/Encrypt.c
@@ -824,14 +824,13 @@
cn_cbor_context * context = &pMessage->m_allocContext;
#endif
cn_cbor_errback cbor_error;
- byte * pbAuthData;
+ byte * pbAuthData = NULL;
size_t cbAuthData;
- cn_cbor * pAuthData;
- cn_cbor * pItem;
+ cn_cbor * pAuthData = NULL;
+ cn_cbor * pItem = NULL;
cn_cbor * ptmp = NULL;
// Build authenticated data
- pbAuthData = NULL;
pAuthData = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
CHECK_CONDITION_CBOR(pAuthData != NULL, cbor_error);
diff --git a/src/cose_int.h b/src/cose_int.h
index 34b87d0..97b5404 100644
--- a/src/cose_int.h
+++ b/src/cose_int.h
@@ -157,84 +157,84 @@
#endif // USE_CBOR_CONTEXT
-extern cose_error _MapFromCBOR(cn_cbor_errback err);
+cose_error _MapFromCBOR(cn_cbor_errback err);
/*
* Set of routines for handle checking
*/
-extern void _COSE_InsertInList(COSE ** rootNode, COSE * newMsg);
-extern bool _COSE_IsInList(const COSE *const rootNode, const COSE *const thisMsg);
-extern void _COSE_RemoveFromList(COSE ** rootNode, COSE * thisMsg);
+void _COSE_InsertInList(COSE ** rootNode, COSE * newMsg);
+bool _COSE_IsInList(const COSE *const rootNode, const COSE *const thisMsg);
+void _COSE_RemoveFromList(COSE ** rootNode, COSE * thisMsg);
-extern bool IsValidEncryptHandle(HCOSE_ENCRYPT h);
-extern bool IsValidEnvelopedHandle(HCOSE_ENVELOPED h);
-extern bool IsValidRecipientHandle(HCOSE_RECIPIENT h);
-extern bool IsValidSignerHandle(HCOSE_SIGNER h);
-extern bool IsValidCounterSignHandle(HCOSE_COUNTERSIGN h);
+bool IsValidEncryptHandle(HCOSE_ENCRYPT h);
+bool IsValidEnvelopedHandle(HCOSE_ENVELOPED h);
+bool IsValidRecipientHandle(HCOSE_RECIPIENT h);
+bool IsValidSignerHandle(HCOSE_SIGNER h);
+bool IsValidCounterSignHandle(HCOSE_COUNTERSIGN h);
-extern bool _COSE_Init(COSE_INIT_FLAGS flags, COSE * pcose, int msgType, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern bool _COSE_Init_From_Object(COSE* pobj, cn_cbor * pcbor, CBOR_CONTEXT_COMMA cose_errback * perror);
-extern void _COSE_Release(COSE * pcose);
+bool _COSE_Init(COSE_INIT_FLAGS flags, COSE * pcose, int msgType, CBOR_CONTEXT_COMMA cose_errback * errp);
+bool _COSE_Init_From_Object(COSE* pobj, cn_cbor * pcbor, CBOR_CONTEXT_COMMA cose_errback * perror);
+void _COSE_Release(COSE * pcose);
-extern cn_cbor * _COSE_map_get_string(COSE * cose, const char * key, int flags, cose_errback * errp);
-extern cn_cbor * _COSE_map_get_int(COSE * cose, int key, int flags, cose_errback * errp);
-extern bool _COSE_map_put(COSE * cose, int key, cn_cbor * value, int flags, cose_errback * errp);
+cn_cbor * _COSE_map_get_string(COSE * cose, const char * key, int flags, cose_errback * errp);
+cn_cbor * _COSE_map_get_int(COSE * cose, int key, int flags, cose_errback * errp);
+bool _COSE_map_put(COSE * cose, int key, cn_cbor * value, int flags, cose_errback * errp);
bool _COSE_SetExternal(COSE * hcose, const byte * pbExternalData, size_t cbExternalData, cose_errback * perr);
-extern HCOSE_ENVELOPED _COSE_Enveloped_Init_From_Object(cn_cbor *, COSE_Enveloped * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern void _COSE_Enveloped_Release(COSE_Enveloped * p);
-extern bool _COSE_Enveloped_decrypt(COSE_Enveloped * pcose, COSE_RecipientInfo * pRecip, const byte *pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
-extern bool _COSE_Enveloped_encrypt(COSE_Enveloped * pcose, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
-extern bool _COSE_Enveloped_SetContent(COSE_Enveloped * cose, const byte * rgbContent, size_t cbContent, cose_errback * errp);
+HCOSE_ENVELOPED _COSE_Enveloped_Init_From_Object(cn_cbor *, COSE_Enveloped * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
+void _COSE_Enveloped_Release(COSE_Enveloped * p);
+bool _COSE_Enveloped_decrypt(COSE_Enveloped * pcose, COSE_RecipientInfo * pRecip, const byte *pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
+bool _COSE_Enveloped_encrypt(COSE_Enveloped * pcose, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
+bool _COSE_Enveloped_SetContent(COSE_Enveloped * cose, const byte * rgbContent, size_t cbContent, cose_errback * errp);
-extern HCOSE_ENCRYPT _COSE_Encrypt_Init_From_Object(cn_cbor *, COSE_Encrypt * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern void _COSE_Encrypt_Release(COSE_Encrypt * p);
-extern bool _COSE_Encrypt_SetContent(COSE_Encrypt * cose, const byte * rgbContent, size_t cbContent, cose_errback * errp);
-extern bool _COSE_Encrypt_Build_AAD(COSE * pMessage, byte ** ppbAAD, size_t * pcbAAD, const char * szContext, cose_errback * perr);
+HCOSE_ENCRYPT _COSE_Encrypt_Init_From_Object(cn_cbor *, COSE_Encrypt * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
+void _COSE_Encrypt_Release(COSE_Encrypt * p);
+bool _COSE_Encrypt_SetContent(COSE_Encrypt * cose, const byte * rgbContent, size_t cbContent, cose_errback * errp);
+bool _COSE_Encrypt_Build_AAD(COSE * pMessage, byte ** ppbAAD, size_t * pcbAAD, const char * szContext, cose_errback * perr);
-extern COSE_RecipientInfo * _COSE_Recipient_Init_From_Object(cn_cbor *, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern void _COSE_Recipient_Free(COSE_RecipientInfo *);
-extern bool _COSE_Recipient_decrypt(COSE_RecipientInfo * pRecip, COSE_RecipientInfo * pRecipUse, int algIn, size_t cbitKey, byte * pbKey, cose_errback * errp);
-extern bool _COSE_Recipient_encrypt(COSE_RecipientInfo * pRecipient, const byte * pbContent, size_t cbContent, cose_errback * perr);
-extern byte * _COSE_RecipientInfo_generateKey(COSE_RecipientInfo * pRecipient, int algIn, size_t cbitKeySize, cose_errback * perr);
+COSE_RecipientInfo * _COSE_Recipient_Init_From_Object(cn_cbor *, CBOR_CONTEXT_COMMA cose_errback * errp);
+void _COSE_Recipient_Free(COSE_RecipientInfo *);
+bool _COSE_Recipient_decrypt(COSE_RecipientInfo * pRecip, COSE_RecipientInfo * pRecipUse, int algIn, size_t cbitKey, byte * pbKey, cose_errback * errp);
+bool _COSE_Recipient_encrypt(COSE_RecipientInfo * pRecipient, const byte * pbContent, size_t cbContent, cose_errback * perr);
+byte * _COSE_RecipientInfo_generateKey(COSE_RecipientInfo * pRecipient, int algIn, size_t cbitKeySize, cose_errback * perr);
// Signed items
-extern HCOSE_SIGN _COSE_Sign_Init_From_Object(cn_cbor *, COSE_SignMessage * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern void _COSE_Sign_Release(COSE_SignMessage * p);
+HCOSE_SIGN _COSE_Sign_Init_From_Object(cn_cbor *, COSE_SignMessage * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
+void _COSE_Sign_Release(COSE_SignMessage * p);
// Signer items
-extern bool _COSE_SignerInfo_Init(COSE_INIT_FLAGS flags, COSE_SignerInfo * pcose, int msgType, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern bool _COSE_Signer_sign(COSE_SignerInfo * pSigner, const cn_cbor * pcborBody, const cn_cbor * pcborProtected, cose_errback * perr);
-extern COSE_SignerInfo * _COSE_SignerInfo_Init_From_Object(cn_cbor * cbor, COSE_SignerInfo * pIn, CBOR_CONTEXT_COMMA cose_errback * perr);
-extern bool _COSE_SignerInfo_Free(COSE_SignerInfo * pSigner);
-extern bool _COSE_Signer_validate(COSE_SignMessage * pSign, COSE_SignerInfo * pSigner, const cn_cbor * pbContent, const cn_cbor * pbProtected, cose_errback * perr);
+bool _COSE_SignerInfo_Init(COSE_INIT_FLAGS flags, COSE_SignerInfo * pcose, int msgType, CBOR_CONTEXT_COMMA cose_errback * errp);
+bool _COSE_Signer_sign(COSE_SignerInfo * pSigner, const cn_cbor * pcborBody, const cn_cbor * pcborProtected, cose_errback * perr);
+COSE_SignerInfo * _COSE_SignerInfo_Init_From_Object(cn_cbor * cbor, COSE_SignerInfo * pIn, CBOR_CONTEXT_COMMA cose_errback * perr);
+bool _COSE_SignerInfo_Free(COSE_SignerInfo * pSigner);
+bool _COSE_Signer_validate(COSE_SignMessage * pSign, COSE_SignerInfo * pSigner, const cn_cbor * pbContent, const cn_cbor * pbProtected, cose_errback * perr);
// Sign1 items
-extern HCOSE_SIGN1 _COSE_Sign1_Init_From_Object(cn_cbor * cbor, COSE_Sign1Message * pIn, CBOR_CONTEXT_COMMA cose_errback * perr);
-extern void _COSE_Sign1_Release(COSE_Sign1Message * p);
+HCOSE_SIGN1 _COSE_Sign1_Init_From_Object(cn_cbor * cbor, COSE_Sign1Message * pIn, CBOR_CONTEXT_COMMA cose_errback * perr);
+void _COSE_Sign1_Release(COSE_Sign1Message * p);
// Mac-ed items
-extern HCOSE_MAC _COSE_Mac_Init_From_Object(cn_cbor *, COSE_MacMessage * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern bool _COSE_Mac_Release(COSE_MacMessage * p);
-extern bool _COSE_Mac_Build_AAD(COSE * pCose, const char * szContext, byte ** ppbAuthData, size_t * pcbAuthData, CBOR_CONTEXT_COMMA cose_errback * perr);
-extern bool _COSE_Mac_compute(COSE_MacMessage * pcose, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
-extern bool _COSE_Mac_validate(COSE_MacMessage * pcose, COSE_RecipientInfo * pRecip, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
+HCOSE_MAC _COSE_Mac_Init_From_Object(cn_cbor *, COSE_MacMessage * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
+bool _COSE_Mac_Release(COSE_MacMessage * p);
+bool _COSE_Mac_Build_AAD(COSE * pCose, const char * szContext, byte ** ppbAuthData, size_t * pcbAuthData, CBOR_CONTEXT_COMMA cose_errback * perr);
+bool _COSE_Mac_compute(COSE_MacMessage * pcose, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
+bool _COSE_Mac_validate(COSE_MacMessage * pcose, COSE_RecipientInfo * pRecip, const byte * pbKeyIn, size_t cbKeyIn, const char * szContext, cose_errback * perr);
// MAC0 Items
-extern HCOSE_MAC0 _COSE_Mac0_Init_From_Object(cn_cbor *, COSE_Mac0Message * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
-extern bool _COSE_Mac0_Release(COSE_Mac0Message * p);
+HCOSE_MAC0 _COSE_Mac0_Init_From_Object(cn_cbor *, COSE_Mac0Message * pIn, CBOR_CONTEXT_COMMA cose_errback * errp);
+bool _COSE_Mac0_Release(COSE_Mac0Message * p);
// Counter Sign Items
-extern HCOSE_COUNTERSIGN _COSE_CounterSign_get(COSE * pMessage, int iSigner, cose_errback * perr);
-extern bool _COSE_CounterSign_add(COSE * pMessage, HCOSE_COUNTERSIGN hSigner, cose_errback * perr);
-extern bool _COSE_CountSign_create(COSE * pMessage, cn_cbor * pcnBody, CBOR_CONTEXT_COMMA cose_errback * perr);
+HCOSE_COUNTERSIGN _COSE_CounterSign_get(COSE * pMessage, int iSigner, cose_errback * perr);
+bool _COSE_CounterSign_add(COSE * pMessage, HCOSE_COUNTERSIGN hSigner, cose_errback * perr);
+bool _COSE_CountSign_create(COSE * pMessage, cn_cbor * pcnBody, CBOR_CONTEXT_COMMA cose_errback * perr);
//
// Debugging Items
@@ -246,7 +246,7 @@
#define FAIL_CONDITION(error) { DO_ASSERT; if (perr != NULL) {perr->err = error;} goto errorReturn;}
#define CHECK_CONDITION_CBOR(condition, error) { if (!(condition)) { DO_ASSERT; if (perr != NULL) {perr->err = _MapFromCBOR(error);} goto errorReturn;}}
-extern cn_cbor * _COSE_encode_protected(COSE * pMessage, cose_errback * perr);
+cn_cbor * _COSE_encode_protected(COSE * pMessage, cose_errback * perr);
//// Defines on positions
@@ -279,7 +279,7 @@
bool cn_cbor_array_replace(cn_cbor * cb_array, cn_cbor * cb_value, int index, CBOR_CONTEXT_COMMA cn_cbor_errback *errp);
cn_cbor * cn_cbor_bool_create(int boolValue, CBOR_CONTEXT_COMMA cn_cbor_errback * errp);
-extern size_t cn_cbor_encode_size(cn_cbor * object);
+size_t cn_cbor_encode_size(cn_cbor * object);
enum {
COSE_Int_Alg_AES_CBC_MAC_256_64 = -22
diff --git a/test/ReadMe.txt b/test/ReadMe.txt
deleted file mode 100644
index d657473..0000000
--- a/test/ReadMe.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-========================================================================
- CONSOLE APPLICATION : test Project Overview
-========================================================================
-
-AppWizard has created this test application for you.
-
-This file contains a summary of what you will find in each of the files that
-make up your test application.
-
-
-test.vcxproj
- This is the main project file for VC++ projects generated using an Application Wizard.
- It contains information about the version of Visual C++ that generated the file, and
- information about the platforms, configurations, and project features selected with the
- Application Wizard.
-
-test.vcxproj.filters
- This is the filters file for VC++ projects generated using an Application Wizard.
- It contains information about the association between the files in your project
- and the filters. This association is used in the IDE to show grouping of files with
- similar extensions under a specific node (for e.g. ".cpp" files are associated with the
- "Source Files" filter).
-
-test.cpp
- This is the main application source file.
-
-/////////////////////////////////////////////////////////////////////////////
-Other standard files:
-
-StdAfx.h, StdAfx.cpp
- These files are used to build a precompiled header (PCH) file
- named test.pch and a precompiled types file named StdAfx.obj.
-
-/////////////////////////////////////////////////////////////////////////////
-Other notes:
-
-AppWizard uses "TODO:" comments to indicate parts of the source code you
-should add to or customize.
-
-/////////////////////////////////////////////////////////////////////////////
diff --git a/test/context.c b/test/context.c
index 8fc925e..179c4c5 100644
--- a/test/context.c
+++ b/test/context.c
@@ -28,7 +28,7 @@
bool CheckMemory(MyContext * pContext)
{
- MyItem * p;
+ MyItem * p = NULL;
// Walk memory and check every block
for (p = (MyItem *) pContext->pFirst; p != NULL; p = p->pNext) {
@@ -59,7 +59,7 @@
void * MyCalloc(size_t count, size_t size, void * context)
{
- MyItem * pb;
+ MyItem * pb = NULL;
MyContext * myContext = (MyContext *)context;
CheckMemory(myContext);
diff --git a/test/mac_test.c b/test/mac_test.c
index 1be9ea2..9b6828f 100644
--- a/test/mac_test.c
+++ b/test/mac_test.c
@@ -40,8 +40,11 @@
hMAC = (HCOSE_MAC) COSE_Decode(pbEncoded, cbEncoded, &type, COSE_mac_object, CBOR_CONTEXT_PARAM_COMMA NULL);
if (hMAC == NULL) {
- if (fFailBody) return 0; else goto failTest;
- }
+ if (fFailBody) {
+ return 0;
+ }
+ goto failTest;
+ }
if ((pInput == NULL) || (pInput->type != CN_CBOR_MAP)) goto failTest;
pMac = cn_cbor_mapget_string(pInput, "mac");
@@ -85,16 +88,21 @@
pFail = cn_cbor_mapget_string(pRecipients, "fail");
cn_cbor * alg = COSE_Mac_map_get_int(hMAC, COSE_Header_Algorithm, COSE_BOTH, NULL);
- if (!IsAlgorithmSupported(alg)) fAlgNoSupport = true;
+ if (!IsAlgorithmSupported(alg)) {
+ fAlgNoSupport = true;
+ }
alg = COSE_Recipient_map_get_int(hRecip, COSE_Header_Algorithm, COSE_BOTH, NULL);
- if (!IsAlgorithmSupported(alg)) fAlgNoSupport = true;
+ if (!IsAlgorithmSupported(alg)) {
+ fAlgNoSupport = true;
+ }
if (COSE_Mac_validate(hMAC, hRecip, NULL)) {
if (fAlgNoSupport) {
fFail = true;
+ } else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)){
+ fFail = true;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) fFail = true;
}
else {
if (fAlgNoSupport) {
@@ -123,7 +131,7 @@
int ValidateMAC(const cn_cbor * pControl)
{
- int cbEncoded;
+ int cbEncoded = 0;
byte * pbEncoded = GetCBOREncoding(pControl, &cbEncoded);
return _ValidateMAC(pControl, pbEncoded, cbEncoded);
@@ -131,7 +139,7 @@
int BuildMacMessage(const cn_cbor * pControl)
{
- int iRecipient;
+ int iRecipient = 0;
//
// We don't run this for all control sequences - skip those marked fail.
@@ -203,8 +211,8 @@
byte rgbSecret[256 / 8] = { 'a', 'b', 'c' };
byte rgbKid[6] = { 'a', 'b', 'c', 'd', 'e', 'f' };
int cbKid = 6;
- size_t cb;
- byte * rgb;
+ size_t cb = 0;
+ byte * rgb = NULL;
if (hEncObj == NULL) goto errorReturn;
@@ -413,7 +421,7 @@
#if INCLUDE_MAC
void MAC_Corners()
{
- HCOSE_MAC hMAC;
+ HCOSE_MAC hMAC = NULL;
HCOSE_ENCRYPT hEncrypt = NULL;
HCOSE_RECIPIENT hRecipient = NULL;
byte rgb[10];
@@ -479,9 +487,9 @@
COSE_Recipient_Free(hRecipient);
COSE_Mac_Free(hMAC);
- if (COSE_Mac_GetRecipient(hMAC, 9, NULL)) CFails++;
-
- return;
+ if (COSE_Mac_GetRecipient(hMAC, 9, NULL)) {
+ CFails++;
+ }
}
#endif
@@ -489,7 +497,7 @@
void MAC0_Corners()
{
HCOSE_ENCRYPT hEncrypt = NULL;
- HCOSE_MAC0 hMAC;
+ HCOSE_MAC0 hMAC = NULL;
byte rgb[10];
cn_cbor * cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
cose_errback cose_error;
@@ -535,7 +543,5 @@
if (!COSE_Mac0_map_put_int(hMAC, COSE_Header_Algorithm, cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL), COSE_PROTECT_ONLY, NULL)) CFails++;
CHECK_FAILURE(COSE_Mac0_encrypt(hMAC, rgb, sizeof(rgb), &cose_error), COSE_ERR_UNKNOWN_ALGORITHM, CFails++);
COSE_Mac0_Free(hMAC);
-
- return;
}
#endif
diff --git a/test/sign.c b/test/sign.c
index fbd2092..008caaa 100644
--- a/test/sign.c
+++ b/test/sign.c
@@ -324,7 +324,7 @@
int ValidateSign1(const cn_cbor * pControl)
{
- int cbEncoded;
+ int cbEncoded = 0;
byte * pbEncoded = GetCBOREncoding(pControl, &cbEncoded);
return _ValidateSign1(pControl, pbEncoded, cbEncoded);
@@ -569,7 +569,5 @@
CHECK_FAILURE(COSE_Sign1_Sign(hSign, cn, &cose_error), COSE_ERR_UNKNOWN_ALGORITHM, CFails++);
COSE_Sign1_Free(hSign);
-
- return;
}
#endif
diff --git a/test/test.c b/test/test.c
index c6a5911..5195767 100644
--- a/test/test.c
+++ b/test/test.c
@@ -561,12 +561,12 @@
{
cn_cbor * pKeyOut = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA NULL);
cn_cbor * pKty = cn_cbor_mapget_string(pKeyIn, "kty");
- cn_cbor * p;
- cn_cbor * pKey;
- cn_cbor * pValue;
+ cn_cbor * p = NULL;
+ cn_cbor * pKey = NULL;
+ cn_cbor * pValue = NULL;
size_t i;
int kty;
- unsigned char * pb;
+ unsigned char * pb = NULL;
size_t cb;
if (pKeyOut == NULL) return NULL;
@@ -923,8 +923,6 @@
}
#endif
}
-
- return;
}
#ifdef _MSC_VER
@@ -970,7 +968,6 @@
FindClose(hFind);
CFails = cFailTotal;
- return;
}
#else