OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
OicEncodingType_t encodingType, uint16_t *credId)
{
- OIC_LOG(DEBUG, TAG, "IN SRPSaveTrustCertChain");
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
VERIFY_NON_NULL_RET(TAG, trustCertChain, ERROR, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL_RET(TAG, credId, ERROR, OC_STACK_INVALID_PARAM);
res = GetDoxmDeviceID(&cred->subject);
if (OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "Cann't get the device id(GetDoxmDeviceID)");
- DeleteCredList(cred);
- return res;
+ OIC_LOG(ERROR, TAG, "Can't get the device id(GetDoxmDeviceID)");
+ goto exit;
}
cred->credUsage= (char *)OICCalloc(1, strlen(TRUST_CA)+1 );
if (cred->credUsage == NULL)
{
- OIC_LOG_V(ERROR, TAG, "%s cant alloc credUsage", __func__);
- OICFree(cred);
- return OC_STACK_NO_MEMORY;
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc credUsage", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
}
OICStrcpy(cred->credUsage, strlen(TRUST_CA) + 1, TRUST_CA);
cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize + 1);
if (cred->optionalData.data == NULL)
{
- OIC_LOG_V(ERROR, TAG, "%s cant alloc cred->optionalData.data", __func__);
- OICFree(cred);
- return OC_STACK_NO_MEMORY;
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc cred->optionalData.data", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
}
cred->optionalData.len = chainSize + 1;
}
else
{
- cred->optionalData.data = (uint8_t *)OICCalloc(1, chainSize);
- VERIFY_NON_NULL_RET(TAG, cred->optionalData.data, ERROR, OC_STACK_NO_MEMORY);
+ cred->optionalData.data = (uint8_t *)OICCalloc(chainSize, sizeof(uint8_t));
+ if (NULL == cred->optionalData.data)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc cred->optionalData.data", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
+ }
cred->optionalData.len = chainSize;
}
memcpy(cred->optionalData.data, trustCertChain, chainSize);
res = AddCredential(cred);
if(res != OC_STACK_OK)
{
- DeleteCredList(cred);
- return res;
+ OIC_LOG_V(ERROR, TAG, "%s can't add cred", __func__);
+ goto exit;
}
*credId = cred->credId;
if (g_trustCertChainNotifier.callback)
{
- uint8_t *certChain = (uint8_t*)OICCalloc(1, sizeof(uint8_t) * chainSize);
+ uint8_t *certChain = (uint8_t*)OICCalloc(chainSize, sizeof(uint8_t));
VERIFY_NON_NULL_RET(TAG, certChain, ERROR, OC_STACK_NO_MEMORY);
memcpy(certChain, trustCertChain, chainSize);
g_trustCertChainNotifier.callback(g_trustCertChainNotifier.context, *credId,
certChain, chainSize);
OICFree(certChain);
}
+exit:
+ if (OC_STACK_OK != res)
+ {
+ DeleteCredList(cred);
+ }
- OIC_LOG(DEBUG, TAG, "OUT SRPSaveTrustCertChain");
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return res;
}
OCStackResult res = OC_STACK_ERROR;
- OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred));
+ OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t));
VERIFY_NON_NULL_RET(TAG, cred, ERROR, OC_STACK_NO_MEMORY);
- OIC_LOG_V(DEBUG, TAG, "IN: %s", __func__);
-
res = GetDoxmDeviceID(&cred->subject);
if (OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "Cann't get the device id(GetDoxmDeviceID)");
- DeleteCredList(cred);
- return res;
+ OIC_LOG(ERROR, TAG, "Can't get the device id(GetDoxmDeviceID)");
+ goto exit;
}
- cred->credUsage= (char *)OICCalloc(1, strlen(PRIMARY_CERT)+1 );
+ cred->credUsage= (char *)OICCalloc(strlen(PRIMARY_CERT) + 1, sizeof(char));
if (cred->credUsage == NULL)
{
- OIC_LOG_V(ERROR, TAG, "%s cant alloc credUsage", __func__);
- OICFree(cred);
- return OC_STACK_NO_MEMORY;
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc credUsage", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
}
OICStrcpy(cred->credUsage, strlen(PRIMARY_CERT) + 1, PRIMARY_CERT) ;
cred->credType = SIGNED_ASYMMETRIC_KEY;
OicSecKey_t *publicData = &cred->publicData;
- publicData->data = (uint8_t *)OICCalloc(1, cert->len);
- VERIFY_NON_NULL_RET(TAG, publicData->data, ERROR, OC_STACK_NO_MEMORY);
+ publicData->data = (uint8_t *)OICCalloc(cert->len, sizeof(uint8_t));
+ if (NULL == publicData->data)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc publicData", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
+ }
memcpy(publicData->data, cert->data, cert->len);
publicData->len = cert->len;
publicData->encoding = cert->encoding;
OicSecKey_t *privateData = &cred->privateData;
- privateData->data = (uint8_t *)OICCalloc(1, key->len);
- if (privateData->data == NULL)
+ privateData->data = (uint8_t *)OICCalloc(key->len, sizeof(uint8_t));
+ if (NULL == privateData->data)
{
- OIC_LOG_V(ERROR, TAG, "%s cant alloc publicData->data", __func__);
- OICFree(publicData->data);
- return OC_STACK_NO_MEMORY;
+ OIC_LOG_V(ERROR, TAG, "%s can't alloc privateData->data", __func__);
+ res = OC_STACK_NO_MEMORY;
+ goto exit;
}
memcpy(privateData->data, key->data, key->len);
privateData->len = key->len;
res = AddCredential(cred);
if(res != OC_STACK_OK)
{
- DeleteCredList(cred);
- return res;
+ OIC_LOG_V(ERROR, TAG, "%s can't add cred", __func__);
+ goto exit;
}
*credId = cred->credId;
-
+exit:
+ if (OC_STACK_OK != res)
+ {
+ DeleteCredList(cred);
+ }
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return res;