Always make the unsent map so we don't need to check for it not being there
diff --git a/src/Cose.c b/src/Cose.c
index de37bcc..612f761 100644
--- a/src/Cose.c
+++ b/src/Cose.c
@@ -75,6 +75,7 @@
#ifdef TAG_IN_ARRAY
cn_cbor * cbor;
#endif // TAG_IN_ARRAY
+ cn_cbor_errback cbor_error;
#ifdef USE_CBOR_CONTEXT
if (context != NULL) pobj->m_allocContext = *context;
@@ -116,6 +117,9 @@
CHECK_CONDITION((pobj->m_unprotectMap != NULL) && (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);
+
pobj->m_ownMsg = true;
pobj->m_refCount = 1;
diff --git a/src/Recipient.c b/src/Recipient.c
index e5cd61c..63b659b 100644
--- a/src/Recipient.c
+++ b/src/Recipient.c
@@ -673,10 +673,16 @@
context = &p->m_encrypt.m_message.m_allocContext;
#endif
- cn_Temp = cn_cbor_int_create(COSE_Algorithm_Direct, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
- CHECK_CONDITION_CBOR(cn_Temp != NULL, cbor_error);
- if (!COSE_Recipient_map_put(hRecipient, COSE_Header_Algorithm, cn_Temp, COSE_UNPROTECT_ONLY, perr)) goto errorReturn;
- cn_Temp = NULL;
+ cn_cbor * cnAlg = _COSE_map_get_int(&p->m_encrypt.m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
+ if (cnAlg != NULL) {
+ CHECK_CONDITION(cnAlg->type == CN_CBOR_INT && cnAlg->v.sint == COSE_Algorithm_Direct, COSE_ERR_INVALID_PARAMETER);
+ }
+ else {
+ cn_Temp = cn_cbor_int_create(COSE_Algorithm_Direct, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
+ CHECK_CONDITION_CBOR(cn_Temp != NULL, cbor_error);
+ if (!COSE_Recipient_map_put(hRecipient, COSE_Header_Algorithm, cn_Temp, COSE_UNPROTECT_ONLY, perr)) goto errorReturn;
+ cn_Temp = NULL;
+ }
if (cbKid > 0) {
pbTemp = (byte *)COSE_CALLOC(cbKid, 1, context);