bool COSE_Enveloped_AddRecipient(HCOSE_ENVELOPED hEnc, HCOSE_RECIPIENT hRecip, cose_errback * perr) { COSE_RecipientInfo * pRecip; COSE_Enveloped * pEncrypt; cn_cbor * pRecipients = NULL; #ifdef USE_CBOR_CONTEXT cn_cbor_context * context; #endif cn_cbor_errback cbor_error; CHECK_CONDITION(IsValidEnvelopedHandle(hEnc), COSE_ERR_INVALID_HANDLE); CHECK_CONDITION(IsValidRecipientHandle(hRecip), COSE_ERR_INVALID_HANDLE); pEncrypt = (COSE_Enveloped *)hEnc; pRecip = (COSE_RecipientInfo *)hRecip; #ifdef USE_CBOR_CONTEXT context = &pEncrypt->m_message.m_allocContext; #endif // USE_CBOR_CONTEXT pRecip->m_recipientNext = pEncrypt->m_recipientFirst; pEncrypt->m_recipientFirst = pRecip; pRecipients = _COSE_arrayget_int(&pEncrypt->m_message, INDEX_RECIPIENTS); if (pRecipients == NULL) { pRecipients = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA &cbor_error); CHECK_CONDITION_CBOR(pRecipients != NULL, cbor_error); if (!_COSE_array_replace(&pEncrypt->m_message, pRecipients, INDEX_RECIPIENTS, CBOR_CONTEXT_PARAM_COMMA &cbor_error)) { CN_CBOR_FREE(pRecipients, context); if (perr != NULL) perr->err = _MapFromCBOR(cbor_error); goto errorReturn; } } CHECK_CONDITION_CBOR(cn_cbor_array_append(pRecipients, pRecip->m_encrypt.m_message.m_cbor, &cbor_error), cbor_error); pRecip->m_encrypt.m_message.m_refCount++; return true; errorReturn: return false; }
bool _COSE_map_put(COSE * pCose, int key, cn_cbor * value, int flags, cose_errback * perr) { #ifdef USE_CBOR_CONTEXT cn_cbor_context * context = &pCose->m_allocContext; #endif cn_cbor_errback error; bool f; if ((flags & COSE_BOTH) == COSE_BOTH) { if (perr != NULL) perr->err = COSE_ERR_INVALID_PARAMETER; errorReturn: return false; } if (perr != NULL) perr->err = COSE_ERR_NONE; switch (flags) { case COSE_PROTECT_ONLY: f = cn_cbor_mapput_int(pCose->m_protectedMap, key, value, CBOR_CONTEXT_PARAM_COMMA &error); break; case COSE_UNPROTECT_ONLY: f = cn_cbor_mapput_int(pCose->m_unprotectMap, key, value, CBOR_CONTEXT_PARAM_COMMA &error); break; case COSE_DONT_SEND: if (pCose->m_dontSendMap == NULL) { pCose->m_dontSendMap = cn_cbor_map_create(CBOR_CONTEXT_PARAM_COMMA &error); CHECK_CONDITION(pCose->m_dontSendMap != NULL, COSE_ERR_OUT_OF_MEMORY); } f = cn_cbor_mapput_int(pCose->m_dontSendMap, key, value, CBOR_CONTEXT_PARAM_COMMA &error); break; default: FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER); break; } CHECK_CONDITION(f, _MapFromCBOR(error)); return f; }