Match the changes from updated Context structure
Match the updates from cose-wg/cose-spec#163 where the context structure
was updated.
Also fix the numbers for a couple of fields in the context structure
diff --git a/dumper/dumper.c b/dumper/dumper.c
index d18a108..728d410 100644
--- a/dumper/dumper.c
+++ b/dumper/dumper.c
@@ -180,7 +180,8 @@
FOO Sign0Body[4] = {
{ "protected", CN_CBOR_BYTES, 0, &RecurseHeaderMap, 1, 0 },
{ "unprotected", CN_CBOR_MAP, 0, HeaderMap, _countof(HeaderMap), 0 },
- { "payload", CN_CBOR_BYTES, 0, NULL, 0, 0 }
+ { "payload", CN_CBOR_BYTES, 0, NULL, 0, 0 },
+ { "signature", CN_CBOR_BYTES, 0, NULL, 0, 0}
};
FOO EnvelopedMessage = {
diff --git a/src/Recipient.c b/src/Recipient.c
index 3b21268..618fef3 100644
--- a/src/Recipient.c
+++ b/src/Recipient.c
@@ -1221,32 +1221,35 @@
cnArrayT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
CHECK_CONDITION_CBOR(cnArrayT != NULL, cbor_error);
- cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_U_nonce, COSE_BOTH, perr);
- if (cnParam != NULL) {
- cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
- }
-
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_U_name, COSE_BOTH, perr);
if (cnParam != NULL) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
}
+ else cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
+ CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
+
+ cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_U_nonce, COSE_BOTH, perr);
+ if (cnParam != NULL) {
+ 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(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_U_other, COSE_BOTH, perr);
if (cnParam != NULL) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
}
+ else cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
+ CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
CHECK_CONDITION_CBOR(cn_cbor_array_append(pArray, cnArrayT, &cbor_error), cbor_error);
cnArrayT = NULL;
@@ -1254,32 +1257,35 @@
cnArrayT = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
CHECK_CONDITION_CBOR(cnArrayT != NULL, cbor_error);
- cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_V_nonce, COSE_BOTH, perr);
- if (cnParam != NULL) {
- cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
- }
-
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_V_name, COSE_BOTH, perr);
if (cnParam != NULL) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
}
+ else cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
+ CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
+
+ cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_V_nonce, COSE_BOTH, perr);
+ if (cnParam != NULL) {
+ 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(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
cnParam = _COSE_map_get_int(pcose, COSE_Header_KDF_V_other, COSE_BOTH, perr);
if (cnParam != NULL) {
cnT = cn_cbor_clone(cnParam, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
- CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
- cnT = NULL;
- cnParam = NULL;
}
+ else cnT = cn_cbor_null_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error);
+ CHECK_CONDITION_CBOR(cnT != NULL, cbor_error);
+ CHECK_CONDITION_CBOR(cn_cbor_array_append(cnArrayT, cnT, &cbor_error), cbor_error);
+ cnT = NULL;
+ cnParam = NULL;
CHECK_CONDITION_CBOR(cn_cbor_array_append(pArray, cnArrayT, &cbor_error), cbor_error);
cnArrayT = NULL;
diff --git a/src/cbor.c b/src/cbor.c
index 40f5144..a229b0f 100644
--- a/src/cbor.c
+++ b/src/cbor.c
@@ -172,3 +172,14 @@
pcn->type = CN_CBOR_FALSE + (boolValue != 0);
return pcn;
}
+
+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) errp->err = CN_CBOR_ERR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ pcn->type = CN_CBOR_NULL;
+ return pcn;
+}
diff --git a/src/cose.h b/src/cose.h
index 6d1cecd..12be235 100644
--- a/src/cose.h
+++ b/src/cose.h
@@ -148,11 +148,11 @@
COSE_Header_Operation_Time = 8,
COSE_Header_HKDF_salt = -20,
- COSE_Header_KDF_U_nonce = -21,
- COSE_Header_KDF_U_name = -22,
+ COSE_Header_KDF_U_name = -21,
+ COSE_Header_KDF_U_nonce = -22,
COSE_Header_KDF_U_other = -23,
- COSE_Header_KDF_V_nonce = -24,
- COSE_Header_KDF_V_name = -25,
+ COSE_Header_KDF_V_name = -24,
+ COSE_Header_KDF_V_nonce = -25,
COSE_Header_KDF_V_other = -26,
COSE_Header_KDF_PUB_other = -999,