Start doing some cleanup
diff --git a/README.md b/README.md
index ecb4147..681dfb7 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-[](https://travis-ci.org/cose-wg/COSE-C
+[](https://travis-ci.org/cose-wg/COSE-C)
[](https://coveralls.io/github/cose-wg/COSE-C?branch=master)
diff --git a/dumper/dumper.c b/dumper/dumper.c
index 926cc59..63cffa9 100644
--- a/dumper/dumper.c
+++ b/dumper/dumper.c
@@ -561,7 +561,7 @@
}
if (forXML) {
- fprintf(out, "<t>Size of binary file is %d bytes</t>\n\n", cb);
+ fprintf(out, "<t>Size of binary file is %lu bytes</t>\n\n", (unsigned long) cb);
fprintf(out, "<figure><artwork type='CBORdiag'><![CDATA[\n");
}
diff --git a/src/Cose.c b/src/Cose.c
index f68a5e7..b33c4c8 100644
--- a/src/Cose.c
+++ b/src/Cose.c
@@ -28,11 +28,7 @@
pobj->m_dontSendMap = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA &errState);
CHECK_CONDITION_CBOR(pobj->m_dontSendMap != NULL, errState);
-#ifdef USE_ARRAY
pobj->m_cbor = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &errState);
-#else
- pobj->m_cbor = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA &errState);
-#endif
CHECK_CONDITION_CBOR(pobj->m_cbor != NULL, errState);
pobj->m_ownMsg = 1;
@@ -81,13 +77,9 @@
}
#endif
-#ifdef USE_ARRAY
pmap = _COSE_arrayget_int(pobj, INDEX_PROTECTED);
CHECK_CONDITION(pmap != NULL, COSE_ERR_INVALID_PARAMETER);
-#else
- pmap = cn_cbor_mapget_int(pcbor, COSE_Header_Protected);
-#endif
if (pmap != NULL) {
CHECK_CONDITION(pmap->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
@@ -101,11 +93,7 @@
}
}
-#ifdef USE_ARRAY
pobj->m_unprotectMap = _COSE_arrayget_int(pobj, INDEX_UNPROTECTED);
-#else
- pobj->m_unprotectMap = cn_cbor_mapget_int(pcbor, COSE_Header_Unprotected);
-#endif
CHECK_CONDITION((pobj->m_unprotectMap != NULL) && (pobj->m_unprotectMap->type == CN_CBOR_MAP), COSE_ERR_INVALID_PARAMETER);
pobj->m_ownUnprotectedMap = false;
@@ -132,7 +120,9 @@
HCOSE COSE_Decode(const byte * rgbData, int cbData, int * ptype, COSE_object_type struct_type, CBOR_CONTEXT_COMMA cose_errback * perr)
{
cn_cbor * cbor = NULL;
+#ifdef TAG_IN_ARRAY
const cn_cbor * pType = NULL;
+#endif
cn_cbor_errback cbor_err;
HCOSE h;
@@ -142,22 +132,9 @@
CHECK_CONDITION_CBOR(cbor != NULL, cbor_err);
#ifdef TAG_IN_ARRAY
-#ifdef USE_ARRAY
CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
-#else
- if (cbor->type != CN_CBOR_MAP) {
- error:
- COSE_FREE(cbor, context);
- if (errp != NULL) errp->err = COSE_ERR_INVALID_PARAMETER;
- return NULL;
- }
-#endif
-#ifdef USE_ARRAY
pType = cn_cbor_index(cbor, 0);
-#else
- pType = cn_cbor_mapget_int(cbor, COSE_Header_Type);
-#endif
CHECK_CONDITION(((pType != NULL) && (pType->type == CN_CBOR_UINT)), COSE_ERR_INVALID_PARAMETER);
*ptype = pType->v.sint;
#else // ! TAG_IN_ARRAY
@@ -316,15 +293,11 @@
cn_cbor_context * context = &pMessage->m_allocContext;
#endif // USE_CBOR_CONTEXT
-#ifdef USE_ARRAY
#ifdef TAG_IN_ARRAY
pProtected = cn_cbor_index(pMessage->m_cbor, INDEX_PROTECTED + (pMessage->m_msgType == 0 ? 0 : 1));
#else
pProtected = cn_cbor_index(pMessage->m_cbor, INDEX_PROTECTED);
#endif
-#else
- pProtected = cn_cbor_mapget_int(pMessage->m_cbor, COSE_Header_Protected);
-#endif
if ((pProtected != NULL) &&(pProtected->type != CN_CBOR_INVALID)) {
errorReturn:
if (pbProtected != NULL) COSE_FREE(pbProtected, context);
@@ -346,11 +319,7 @@
CHECK_CONDITION(pProtected != NULL, COSE_ERR_OUT_OF_MEMORY);
pbProtected = NULL;
-#ifdef USE_ARRAY
CHECK_CONDITION(_COSE_array_replace(pMessage, pProtected, INDEX_PROTECTED, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_ERR_CBOR);
-#else
- CHECK_CONDITION(cn_cbor_mapput_int(pMessage->m_cbor, COSE_Header_Protected, pProtected, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_ERR_CBOR);
-#endif
return pProtected;
}
diff --git a/test/test.c b/test/test.c
index f600a85..0c9df25 100644
--- a/test/test.c
+++ b/test/test.c
@@ -40,14 +40,16 @@
fwrite(rgb, cb, 1, fp);
fclose(fp);
+#if 0
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(NULL, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
- // cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
+ cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
fprintf(stdout, "\r\n");
+#endif
COSE_Mac_Free(hEncObj);
@@ -108,14 +110,40 @@
fwrite(rgb, cb, 1, fp);
fclose(fp);
+#if 0
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(NULL, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
- // cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
+ cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
fprintf(stdout, "\r\n");
+#endif
+
+ COSE_Sign_Free(hEncObj);
+
+ /* */
+
+ int typ;
+ hEncObj = (HCOSE_SIGN)COSE_Decode(rgb, (int)cb, &typ, COSE_sign_object, NULL, NULL);
+
+#if 0
+ int iRecipient = 0;
+ do {
+ HCOSE_RECIPIENT hRecip;
+
+ hRecip = COSE_Encrypt_GetRecipient(hEncObj, iRecipient, NULL);
+ if (hRecip == NULL) break;
+
+ COSE_Recipient_SetKey(hRecip, rgbSecret, cbSecret, NULL);
+
+ COSE_Encrypt_decrypt(hEncObj, hRecip, NULL);
+
+ iRecipient += 1;
+
+ } while (true);
+#endif
COSE_Sign_Free(hEncObj);
@@ -151,14 +179,16 @@
fwrite(rgb, cb, 1, fp);
fclose(fp);
+#if 0
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(NULL, 0, cbor, " ", "\r\n");
szX = malloc(cbPrint);
- // cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
+ cn_cbor_printer_write(szX, cbPrint, cbor, " ", "\r\n");
fprintf(stdout, "%s", szX);
fprintf(stdout, "\r\n");
+#endif
COSE_Encrypt_Free(hEncObj);