refactor: add missing headers, remove compiler warnings (#86)

* refactor: add missing headers

* refactor: reduce warnings

* chore: remove more unsed stuff

* refactor: remove some sign compare warnings

* fix: less warnings

* fix: more warnings

* refactor: remove UNUSED_PARAM

* fix: typos

* revert: removing f var from test.c

* revert: remove debug info from testing files

* revert: changing build script

* fix: tests
diff --git a/.gitignore b/.gitignore
index d2165dc..bec05a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,6 +67,8 @@
 dist
 test/test.cbor
 *.tcl
+CMakeLists.txt.user
+
 
 # Coverity
 cov-int
diff --git a/dumper/CMakeLists.txt b/dumper/CMakeLists.txt
index 46246cb..21d1ed4 100644
--- a/dumper/CMakeLists.txt
+++ b/dumper/CMakeLists.txt
@@ -6,6 +6,8 @@
   target_link_libraries(cose_dumper PRIVATE ws2_32)
 endif()
 
+target_include_directories(cose_dumper PRIVATE ../src)
+
 if(COSE_C_USE_MBEDTLS)
   # mbedtls
   target_include_directories(cose_dumper
@@ -19,4 +21,4 @@
 
 if(CLANG_TIDY_EXE)
   set_target_properties(cose_dumper PROPERTIES C_CLANG_TIDY "${CLANG_TIDY_EXE}")
-endif()
\ No newline at end of file
+endif()
diff --git a/dumper/dumper.c b/dumper/dumper.c
index 908b968..8b2ec18 100644
--- a/dumper/dumper.c
+++ b/dumper/dumper.c
@@ -1,22 +1,19 @@
 #define _CRT_SECURE_NO_WARNINGS
 
-#include <stdio.h>
-#include <cose/cose.h>
-#include <sys/stat.h>
 #include <cn-cbor/cn-cbor.h>
+#include <cose/cose.h>
+#include <cose_int.h>
 #include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdarg.h>
+#include <sys/stat.h>
 
 #ifdef _MSC_VER
 #include <io.h>
 #endif
 
-#ifndef _countof
-#define _countof(x) (sizeof(x)/sizeof(x[0]))
-#endif
-
 #ifndef _MSC_VER
 #define strcat_s(a, b, c) strcat(a, c)
 #endif
@@ -395,7 +392,7 @@
 			if (pFOO != NULL) {
 				//  Locate the right entry in foo
 				for (i2 = 0, pFoo2 = pFOO->children; i2 < pFOO->count; pFoo2++, i2 += 1) {
-					if (pFoo2->type != cbor2->type) continue;
+					if ((unsigned)pFoo2->type != cbor2->type) continue;
 					switch (cbor2->type) {
 					case CN_CBOR_UINT:
 						if ((group != 0) && (pFoo2->group != 0) && (pFoo2->group != group)) continue;
diff --git a/include/cose/cose.h b/include/cose/cose.h
index d767c85..dbb08f3 100644
--- a/include/cose/cose.h
+++ b/include/cose/cose.h
@@ -1,8 +1,9 @@
+#pragma once
+
+#include <stdbool.h>
 #include <cn-cbor/cn-cbor.h>
 #include "cose/cose_configure.h"
 
-#pragma once
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -368,10 +369,10 @@
 /*
 */
 
-extern cn_cbor * cn_cbor_clone(const cn_cbor * pIn, CBOR_CONTEXT_COMMA cn_cbor_errback * perr);
-extern cn_cbor * cn_cbor_tag_create(int tag, cn_cbor * child, CBOR_CONTEXT_COMMA cn_cbor_errback * perr);
-extern cn_cbor * cn_cbor_bool_create(int boolValue, CBOR_CONTEXT_COMMA cn_cbor_errback * errp);
-extern cn_cbor * cn_cbor_null_create(CBOR_CONTEXT_COMMA cn_cbor_errback * errp);
+cn_cbor * cn_cbor_clone(const cn_cbor * pIn, CBOR_CONTEXT_COMMA cn_cbor_errback * perr);
+cn_cbor * cn_cbor_tag_create(int tag, cn_cbor * child, CBOR_CONTEXT_COMMA cn_cbor_errback * perr);
+cn_cbor * cn_cbor_bool_create(int boolValue, CBOR_CONTEXT_COMMA cn_cbor_errback * errp);
+cn_cbor * cn_cbor_null_create(CBOR_CONTEXT_COMMA cn_cbor_errback * errp);
 
 #ifdef __cplusplus
 }
diff --git a/src/Cose.c b/src/Cose.c
index 6ded3fa..d8c0039 100644
--- a/src/Cose.c
+++ b/src/Cose.c
@@ -498,15 +498,19 @@
 	return;
 }
 
-bool _COSE_IsInList(COSE * root, COSE * thisMsg)
+bool _COSE_IsInList(const COSE *const root, const COSE  *const thisMsg)
 {
-	COSE * walk;
+	if (root == NULL) {
+		return false;
+	}
+	if (thisMsg == NULL) {
+		return false;
+	}
 
-	if (root == NULL) return false;
-	if (thisMsg == NULL) return false;
-
-	for (walk = root; walk != NULL; walk = walk->m_handleList) {
-		if (walk == thisMsg) return true;		
+	for (const COSE * walk = root; walk != NULL; walk = walk->m_handleList) {
+		if (walk == thisMsg) {
+			return true;
+		}
 	}
 	return false;
 }
diff --git a/src/Encrypt.c b/src/Encrypt.c
index a7e140a..8e59329 100644
--- a/src/Encrypt.c
+++ b/src/Encrypt.c
@@ -129,7 +129,7 @@
 bool COSE_Enveloped_Free(HCOSE_ENVELOPED h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_Enveloped * p = (COSE_Enveloped *)h;
 
@@ -141,14 +141,14 @@
 	}
 
 #ifdef USE_CBOR_CONTEXT
-	context = ((COSE_Enveloped *)h)->m_message.m_allocContext;
+	context = &((COSE_Enveloped *)h)->m_message.m_allocContext;
 #endif
 
 	_COSE_RemoveFromList(&EnvelopedRoot, &p->m_message);
 
 	_COSE_Enveloped_Release((COSE_Enveloped *)h);
 
-	COSE_FREE((COSE_Enveloped *)h, &context);
+	COSE_FREE((COSE_Enveloped *)h, context);
 
 	return true;
 }
diff --git a/src/Encrypt0.c b/src/Encrypt0.c
index 132bde4..9012fe2 100644
--- a/src/Encrypt0.c
+++ b/src/Encrypt0.c
@@ -128,21 +128,21 @@
 bool COSE_Encrypt_Free(HCOSE_ENCRYPT h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_Encrypt * pEncrypt = (COSE_Encrypt *)h;
 
 	if (!IsValidEncryptHandle(h)) return false;
 
 #ifdef USE_CBOR_CONTEXT
-	context = ((COSE_Encrypt *)h)->m_message.m_allocContext;
+	context = &((COSE_Encrypt *)h)->m_message.m_allocContext;
 #endif
 
 	_COSE_Encrypt_Release(pEncrypt);
 
 	_COSE_RemoveFromList(&EncryptRoot, &pEncrypt->m_message);
 	
-	COSE_FREE((COSE_Encrypt *)h, &context);
+	COSE_FREE((COSE_Encrypt *)h, context);
 
 	return true;
 }
diff --git a/src/MacMessage.c b/src/MacMessage.c
index 6c4eb34..b09870a 100644
--- a/src/MacMessage.c
+++ b/src/MacMessage.c
@@ -113,7 +113,7 @@
 bool COSE_Mac_Free(HCOSE_MAC h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_MacMessage * p = (COSE_MacMessage *)h;
 
@@ -127,12 +127,12 @@
 	_COSE_RemoveFromList(&MacRoot, &p->m_message);
 
 #ifdef USE_CBOR_CONTEXT
-	context = ((COSE_MacMessage *)h)->m_message.m_allocContext;
+	context = &((COSE_MacMessage *)h)->m_message.m_allocContext;
 #endif
 
 	_COSE_Mac_Release((COSE_MacMessage *)h);
 
-	COSE_FREE((COSE_MacMessage *)h, &context);
+	COSE_FREE((COSE_MacMessage *)h, context);
 
 	return true;
 }
@@ -286,7 +286,7 @@
 	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(cn_cbor_encoder_write(pbAuthData, 0, cbAuthData, pAuthData) == cbAuthData, COSE_ERR_CBOR);
+	CHECK_CONDITION(cn_cbor_encoder_write(pbAuthData, 0, cbAuthData, pAuthData) == (ssize_t)cbAuthData, COSE_ERR_CBOR);
 
 	*ppbAuthData = pbAuthData;
 	*pcbAuthData = cbAuthData;
diff --git a/src/MacMessage0.c b/src/MacMessage0.c
index d445265..e9368d0 100644
--- a/src/MacMessage0.c
+++ b/src/MacMessage0.c
@@ -100,7 +100,7 @@
 bool COSE_Mac0_Free(HCOSE_MAC0 h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_Mac0Message * p = (COSE_Mac0Message *)h;
 
@@ -114,12 +114,12 @@
 	_COSE_RemoveFromList(&Mac0Root, &p->m_message);
 
 #ifdef USE_CBOR_CONTEXT
-	context = p->m_message.m_allocContext;
+	context = &p->m_message.m_allocContext;
 #endif
 
 	_COSE_Mac0_Release(p);
 
-	COSE_FREE(p, &context);
+	COSE_FREE(p, context);
 
 	return true;
 }
diff --git a/src/Recipient.c b/src/Recipient.c
index a7a627c..761f52b 100644
--- a/src/Recipient.c
+++ b/src/Recipient.c
@@ -234,6 +234,7 @@
 
 bool _COSE_Recipient_decrypt(COSE_RecipientInfo * pRecip, COSE_RecipientInfo * pRecipUse, int algIn, size_t cbitKeyOut, byte * pbKeyOut, cose_errback * perr)
 {
+	UNUSED(pRecipUse);
 	int alg;
 	const cn_cbor * cn = NULL;
 	COSE_RecipientInfo * pRecip2;
@@ -251,8 +252,6 @@
 	int cbitKeyX = 0;
 	byte rgbKey[256 / 8];
 
-	UNUSED(pcose);
-
 #ifdef USE_CBOR_CONTEXT
 	context = &pcose->m_message.m_allocContext;
 #else
@@ -279,7 +278,7 @@
 		CHECK_CONDITION(pRecip->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
 		cn = cn_cbor_mapget_int(pRecip->m_pkey, -1);
 		CHECK_CONDITION((cn != NULL) && (cn->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
-		CHECK_CONDITION((cn->length == (unsigned int)cbitKeyOut / 8), COSE_ERR_INVALID_PARAMETER);
+		CHECK_CONDITION(((size_t)cn->length == cbitKeyOut / 8), COSE_ERR_INVALID_PARAMETER);
 		memcpy(pbKeyOut, cn->v.bytes, cn->length);
 
 		return true;
@@ -881,7 +880,7 @@
 		CHECK_CONDITION(pRecipient->m_pkey != NULL, COSE_ERR_INVALID_PARAMETER);
 			pK = cn_cbor_mapget_int(pRecipient->m_pkey, -1);
 			CHECK_CONDITION((pK != NULL) && (pK->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
-			CHECK_CONDITION(pK->length == cbitKeySize / 8, COSE_ERR_INVALID_PARAMETER);
+			CHECK_CONDITION((size_t)pK->length == cbitKeySize / 8, COSE_ERR_INVALID_PARAMETER);
 			memcpy(pb, pK->v.bytes, cbitKeySize / 8);
 	break;
 
@@ -1225,7 +1224,6 @@
 	cn_cbor * cnArrayT = NULL;
 	cn_cbor * cnParam;
 	byte * pbContext = NULL;
-	size_t cbContext;
 
 	pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
 	CHECK_CONDITION_CBOR(pArray != NULL, cbor_error);
@@ -1346,11 +1344,11 @@
 		cnParam = NULL;
 	}
 
-	cbContext = cn_cbor_encode_size(pArray);
+	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(cn_cbor_encoder_write(pbContext, 0, cbContext, pArray) == cbContext, COSE_ERR_CBOR);
+	CHECK_CONDITION(cn_cbor_encoder_write(pbContext, 0, cbContext, pArray) == (ssize_t)cbContext, COSE_ERR_CBOR);
 
 	*ppbContext = pbContext;
 	*pcbContext = cbContext;
diff --git a/src/Sign.c b/src/Sign.c
index 082d5e3..c9c04fd 100644
--- a/src/Sign.c
+++ b/src/Sign.c
@@ -107,7 +107,7 @@
 bool COSE_Sign_Free(HCOSE_SIGN h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_SignMessage * pMessage = (COSE_SignMessage *)h;
 
@@ -122,12 +122,12 @@
 	_COSE_RemoveFromList(&SignRoot, &pMessage->m_message);
 
 #ifdef USE_CBOR_CONTEXT
-	context = pMessage->m_message.m_allocContext;
+	context = &pMessage->m_message.m_allocContext;
 #endif
 
 	_COSE_Sign_Release(pMessage);
 
-	COSE_FREE(pMessage, &context);
+	COSE_FREE(pMessage, context);
 
 	return true;
 }
diff --git a/src/Sign1.c b/src/Sign1.c
index 93364b8..f71c8ce 100644
--- a/src/Sign1.c
+++ b/src/Sign1.c
@@ -92,7 +92,7 @@
 bool COSE_Sign1_Free(HCOSE_SIGN1 h)
 {
 #ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
+	cn_cbor_context *context;
 #endif
 	COSE_Sign1Message * pMessage = (COSE_Sign1Message *)h;
 
@@ -107,12 +107,12 @@
 	_COSE_RemoveFromList(&Sign1Root, &pMessage->m_message);
 
 #ifdef USE_CBOR_CONTEXT
-	context = pMessage->m_message.m_allocContext;
+	context = &pMessage->m_message.m_allocContext;
 #endif
 
 	_COSE_Sign1_Release(pMessage);
 
-	COSE_FREE(pMessage, &context);
+	COSE_FREE(pMessage, context);
 
 	return true;
 }
@@ -294,7 +294,7 @@
 	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(cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray) == cbToSign, COSE_ERR_CBOR);
+	CHECK_CONDITION(cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray) == (ssize_t)cbToSign, COSE_ERR_CBOR);
 
 	*ppbToSign = pbToSign;
 	*pcbToSign = cbToSign;
diff --git a/src/SignerInfo.c b/src/SignerInfo.c
index 82e3a24..45090e9 100644
--- a/src/SignerInfo.c
+++ b/src/SignerInfo.c
@@ -153,7 +153,9 @@
 	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(cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray) == cbToSign, COSE_ERR_CBOR);
+	const ssize_t writtenBits = cn_cbor_encoder_write(pbToSign, 0, cbToSign, pArray);
+	CHECK_CONDITION(writtenBits >= 0, COSE_ERR_CBOR);
+	CHECK_CONDITION((size_t)writtenBits == cbToSign, COSE_ERR_CBOR);
 
 	*ppbToSign = pbToSign;
 	*pcbToSign = cbToSign;
@@ -370,15 +372,13 @@
 
 bool COSE_Signer_map_put_int(HCOSE_SIGNER h, int key, cn_cbor * value, int flags, cose_errback * perr)
 {
-	bool fRet = false;
-
 	CHECK_CONDITION(IsValidSignerHandle(h), COSE_ERR_INVALID_HANDLE);
 	CHECK_CONDITION(value != NULL, COSE_ERR_INVALID_PARAMETER);
 
 	return _COSE_map_put(&((COSE_SignerInfo *)h)->m_message, key, value, flags, perr);
 
 errorReturn:
-	return fRet;
+	return false;
 }
 
 #endif
diff --git a/src/cose_int.h b/src/cose_int.h
index 59e1757..34b87d0 100644
--- a/src/cose_int.h
+++ b/src/cose_int.h
@@ -1,6 +1,9 @@
 #pragma once
 
 #include <assert.h>
+#include <cn-cbor/cn-cbor.h>
+#include <cose/cose.h>
+#include <stdbool.h>
 
 // These definitions are here because they aren't required for the public
 // interface, and they were quite confusing in cn-cbor.h
@@ -12,6 +15,10 @@
 
 #define UNUSED(x) ((void) (x))
 
+#ifndef _countof
+#define _countof(x) (sizeof(x)/sizeof(x[0]))
+#endif
+
 typedef struct _COSE {
 	COSE_INIT_FLAGS m_flags;		//  Not sure what goes here yet
 	int m_ownMsg;		//  Do I own the pointer @ m_cbor?
@@ -149,9 +156,6 @@
 
 #endif // USE_CBOR_CONTEXT
 
-#ifndef UNUSED_PARAM
-#define UNUSED_PARAM(p) ((void)&(p))
-#endif
 
 extern cose_error _MapFromCBOR(cn_cbor_errback err);
 
@@ -160,7 +164,7 @@
  */
 
 extern void _COSE_InsertInList(COSE ** rootNode, COSE * newMsg);
-extern bool _COSE_IsInList(COSE * rootNode, COSE * thisMsg);
+extern bool _COSE_IsInList(const COSE *const rootNode, const COSE  *const thisMsg);
 extern void _COSE_RemoveFromList(COSE ** rootNode, COSE * thisMsg);
 
 extern bool IsValidEncryptHandle(HCOSE_ENCRYPT h);
diff --git a/src/crypto.h b/src/crypto.h
index 9afb3d6..5a069d2 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -1,15 +1,19 @@
 #pragma once
 
+#include <cose/cose.h>
+#include <stdbool.h>
+#include "cose_int.h"
+
 /**
-* Perform an AES-CCM Decryption operation
-*
-* @param[in]   COSE_Enveloped Pointer to COSE Encryption context object
-* @param[in]   int          Size of the Tag value to be create
-* @param[in]   int          Size of the Message Length field
-* @param[in]   byte *       Pointer to authenticated data structure
-* @param[in]   int          Size of authenticated data structure
-* @return                   Did the function succeed?
-*/
+ * Perform an AES-CCM Decryption operation
+ *
+ * @param[in]   COSE_Enveloped Pointer to COSE Encryption context object
+ * @param[in]   int          Size of the Tag value to be create
+ * @param[in]   int          Size of the Message Length field
+ * @param[in]   byte *       Pointer to authenticated data structure
+ * @param[in]   int          Size of authenticated data structure
+ * @return                   Did the function succeed?
+ */
 bool AES_CCM_Decrypt(COSE_Enveloped * pcose, int TSize, int LSize, const byte * pbKey, size_t cbitKey, const byte * pbCrypto, size_t cbCrypto, const byte * pbAuthData, size_t cbAuthData, cose_errback * perr);
 bool AES_GCM_Decrypt(COSE_Enveloped * pcose, const byte * pbKey, size_t cbKey, const byte * pbCrypto, size_t cbCrypto, const byte * pbAuthData, size_t cbAuthData, cose_errback * perr);
 bool AES_KW_Decrypt(COSE_Enveloped * pcose, const byte * pbKeyIn, size_t cbitKey, const byte * pbCipherText, size_t cbCipherText, byte * pbKeyOut, int * pcbKeyOut, cose_errback * perr);
diff --git a/src/mbedtls.c b/src/mbedtls.c
index 334ac3a..fe5a1ff 100644
--- a/src/mbedtls.c
+++ b/src/mbedtls.c
@@ -231,9 +231,7 @@
 bool AES_GCM_Encrypt(COSE_Enveloped * pcose, const byte * pbKey, size_t cbKey, const byte * pbAuthData, size_t cbAuthData, cose_errback * perr)
 {
 	mbedtls_gcm_context ctx;
-	int cbOut;
 	byte * rgbOut = NULL;
-	int outl = 0;
 	byte rgbIV[16] = { 0 };
 	byte * pbIV = NULL;
 	const cn_cbor * cbor_iv = NULL;
@@ -571,20 +569,19 @@
 
 bool HKDF_Expand(COSE * pcose, size_t cbitDigest, const byte * pbPRK, size_t cbPRK, const byte * pbInfo, size_t cbInfo, byte * pbOutput, size_t cbOutput, cose_errback * perr)
 {
+	UNUSED(pcose);
 	mbedtls_md_type_t mdType;
 	mbedtls_md_info_t * pmd;
 
-	size_t ib;
-    int cbSalt;
-    unsigned int cbDigest = 0;
-    byte bCount = 1;
 
-    if (0) {
-    errorReturn:
-        return false;
-    }
+	unsigned int cbDigest = 0;
 
-    switch (cbitDigest) {
+	if (0) {
+	errorReturn:
+		return false;
+	}
+
+	switch (cbitDigest) {
     case 256: mdType = MBEDTLS_MD_SHA256; cbDigest = 256 / 8;  break;
     case 384: mdType = MBEDTLS_MD_SHA384; cbDigest = 384 / 8; break;
     case 512: mdType = MBEDTLS_MD_SHA512; cbDigest = 512 / 8; break;
@@ -600,7 +597,6 @@
     }
 
     return true;
-
 }
 /*
 void dump_output(byte* b, size_t s){
@@ -1175,6 +1171,7 @@
 
 int rand_bytes2(void * pv, unsigned char * pb, size_t cb)
 {
+	UNUSED(pv);
     rand_bytes(pb, cb);
     return 0;
 }
diff --git a/src/openssl.c b/src/openssl.c
index 229ba29..297fa33 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1099,7 +1099,7 @@
 	CHECK_CONDITION(pSig != NULL, COSE_ERR_INVALID_PARAMETER);
 	cbSignature = pSig->length;
 
-	CHECK_CONDITION(cbSignature / 2 == cbR, COSE_ERR_INVALID_PARAMETER);
+	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);
@@ -1197,14 +1197,10 @@
 
 bool EdDSA_Verify(COSE* pSigner, int index, const cn_cbor* pKey, const byte* rgbToSign, size_t cbToSign, cose_errback* perr)
 {
-#ifdef USE_CBOR_CONTEXT
-	cn_cbor_context* context = &pSigner->m_allocContext;
-#endif
-	cn_cbor* p = NULL;
 	cn_cbor* pSig;
 	EVP_PKEY* pkey = NULL;
 
-	p = cn_cbor_mapget_int(pKey, COSE_Key_OPK_Curve);
+	cn_cbor *p = cn_cbor_mapget_int(pKey, COSE_Key_OPK_Curve);
 	if (p == NULL) {
 	errorReturn:
 		if (pkey != NULL) EVP_PKEY_free(pkey);
diff --git a/test/context.c b/test/context.c
index dbdea88..8fc925e 100644
--- a/test/context.c
+++ b/test/context.c
@@ -29,22 +29,19 @@
 bool CheckMemory(MyContext * pContext)
 {
 	MyItem * p;
-	int i;
-
 	//  Walk memory and check every block
 
 	for (p =  (MyItem *) pContext->pFirst; p != NULL; p = p->pNext) {
 		if (p->pad[0] == (byte) 0xab) {
 			//  Block has been freed
-			for (i = 0; i < p->size + 8; i++) {
+			for (unsigned i = 0; i < p->size + 8; i++) {
 				if (p->pad[i] != (byte) 0xab) {
 					fprintf(stderr, "Freed block is modified");
 					assert(false);
 				}
 			}
-		}
-		else if (p->pad[0] == (byte) 0xef) {
-			for (i = 0; i < 4; i++) {
+		} else if (p->pad[0] == (byte) 0xef) {
+			for (unsigned i = 0; i < 4; i++) {
 				if ((p->pad[i] != (byte) 0xef) || (p->pad[i + 4 + p->size] != (byte) 0xef)) {
 					fprintf(stderr, "Curent block was overrun");
 					assert(false);
diff --git a/test/encrypt.c b/test/encrypt.c
index 14eff3e..5a569cc 100644
--- a/test/encrypt.c
+++ b/test/encrypt.c
@@ -421,12 +421,13 @@
 		if (!fAlgSupport) {
 			fFail = true;
 			fAlgSupport = false;
+		} else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+			fFail = true;
 		}
-		else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) fFail = true;
 
-                size_t cb;
-                byte * pb;
-                pb = COSE_Encrypt_GetContent(hEnc, &cb, NULL);
+		size_t cb;
+		byte * pb;
+		pb = COSE_Encrypt_GetContent(hEnc, &cb, NULL);
 	}
 	else {
 		if (fAlgSupport) {
diff --git a/test/json.c b/test/json.c
index 9a99ecd..d3bd7bc 100644
--- a/test/json.c
+++ b/test/json.c
@@ -217,10 +217,10 @@
 
 	for (unsigned int i = 0, j = 0; i < input_length;) {
 
-		uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
-		uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
-		uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
-		uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
+		uint32_t sextet_a = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+		uint32_t sextet_b = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+		uint32_t sextet_c = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+		uint32_t sextet_d = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
 
 		uint32_t triple = (sextet_a << 3 * 6)
 			+ (sextet_b << 2 * 6)
diff --git a/test/test.c b/test/test.c
index bc110f1..c6a5911 100644
--- a/test/test.c
+++ b/test/test.c
@@ -10,6 +10,7 @@
 #include <cose/cose_configure.h>
 #include <cn-cbor/cn-cbor.h>
 #include <assert.h>
+#include <cose_int.h>
 
 #ifndef _MSC_VER
 #include <dirent.h>
@@ -18,7 +19,6 @@
 #endif
 
 #include "json.h"
-
 #include "test.h"
 
 #ifdef USE_MBED_TLS
@@ -330,19 +330,23 @@
 
 bool SetAttributes(HCOSE hHandle, const cn_cbor * pAttributes, int which, int msgType, bool fPublicKey)
 {
-	const cn_cbor * pKey;
-	const cn_cbor * pValue;
-	int keyNew;
-	cn_cbor * pValueNew;
-	bool f = false;
+	int keyNew = 0;
+	cn_cbor * pValueNew = NULL;
+	bool fRet = true;
 
-	if (pAttributes == NULL) return true;
-	if (pAttributes->type != CN_CBOR_MAP) return false;
+	if (pAttributes == NULL) {
+		return true;
+	}
+	if (pAttributes->type != CN_CBOR_MAP) {
+		return false;
+	}
 
-	for (pKey = pAttributes->first_child; pKey != NULL; pKey = pKey->next->next) {
-		pValue = pKey->next;
+	for (const cn_cbor * pKey = pAttributes->first_child; pKey != NULL; pKey = pKey->next->next) {
+		const cn_cbor *  pValue = pKey->next;
 
-		if (pKey->type != CN_CBOR_TEXT) return false;
+		if (pKey->type != CN_CBOR_TEXT) {
+			return false;
+		}
 
 		if (strcmp(pKey->v.str, "alg") == 0) {
 			keyNew = COSE_Header_Algorithm;
@@ -391,57 +395,56 @@
 		switch (msgType) {
 #if INCLUDE_MAC
 		case Attributes_MAC_protected:
-			f = COSE_Mac_map_put_int((HCOSE_MAC)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Mac_map_put_int((HCOSE_MAC)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_MAC0
 		case Attributes_MAC0_protected:
-			f = COSE_Mac0_map_put_int((HCOSE_MAC0)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Mac0_map_put_int((HCOSE_MAC0)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_ENCRYPT || INCLUDE_MAC
 		case Attributes_Recipient_protected:
-			f = COSE_Recipient_map_put_int((HCOSE_RECIPIENT)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Recipient_map_put_int((HCOSE_RECIPIENT)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_ENCRYPT
 		case Attributes_Enveloped_protected:
-			f = COSE_Enveloped_map_put_int((HCOSE_ENVELOPED)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Enveloped_map_put_int((HCOSE_ENVELOPED)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_ENCRYPT0
 		case Attributes_Encrypt_protected:
-			f = COSE_Encrypt_map_put_int((HCOSE_ENCRYPT)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Encrypt_map_put_int((HCOSE_ENCRYPT)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_SIGN
 		case Attributes_Sign_protected:
-			f = COSE_Sign_map_put_int((HCOSE_SIGN)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Sign_map_put_int((HCOSE_SIGN)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_SIGN
 		case Attributes_Signer_protected:
-			f = COSE_Signer_map_put_int((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Signer_map_put_int((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
 
 #if INCLUDE_SIGN1
 		case Attributes_Sign1_protected:
-			f = COSE_Sign1_map_put_int((HCOSE_SIGN1)hHandle, keyNew, pValueNew, which, NULL);
+			fRet &= COSE_Sign1_map_put_int((HCOSE_SIGN1)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 #endif
-
+		assert(fRet);
 		}
-		// assert(f);
 	}
 
-	return true;
+	return fRet;
 }
 
 bool SetSendingAttributes(HCOSE hMsg, const cn_cbor * pIn, int base)
@@ -561,7 +564,7 @@
 	cn_cbor * p;
 	cn_cbor * pKey;
 	cn_cbor * pValue;
-	int i;
+	size_t i;
 	int kty;
 	unsigned char * pb;
 	size_t cb;
@@ -589,7 +592,7 @@
 
 		if (pKey->type == CN_CBOR_TEXT) {
 			for (i = 0; i < sizeof(RgStringKeys)/sizeof(RgStringKeys[0]); i++) {
-				if ((pKey->length == strlen(RgStringKeys[i].szKey)) &&
+				if (((size_t)pKey->length == strlen(RgStringKeys[i].szKey)) &&
 					(strncmp(pKey->v.str, RgStringKeys[i].szKey, strlen(RgStringKeys[i].szKey)) == 0) &&
 					((RgStringKeys[i].kty == 0) || (RgStringKeys[i].kty == kty))) {
 					switch (RgStringKeys[i].operation) {
@@ -632,9 +635,6 @@
 }
 
 
-
-bool cn_cbor_array_replace(cn_cbor * cb_array, cn_cbor * cb_value, int index, CBOR_CONTEXT_COMMA cn_cbor_errback *errp);
-
 bool Test_cn_cbor_array_replace()
 {
 	cn_cbor * pRoot;
diff --git a/test/test.h b/test/test.h
index 8c187af..0c77899 100644
--- a/test/test.h
+++ b/test/test.h
@@ -1,9 +1,6 @@
 #pragma once
 
-#ifndef _countof
-
-#define _countof(x) (sizeof(x)/sizeof(x[0]))
-#endif
+#include <stdbool.h>
 
 #ifdef USE_CBOR_CONTEXT
 cn_cbor_context * context;