Merge branch '1.1-rel'
[platform/upstream/iotivity.git] / resource / csdk / security / src / credresource.c
index 703ec90..07bc8ea 100644 (file)
@@ -139,9 +139,9 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
     *cborSize = 0;
     *cborPayload = NULL;
     const OicSecCred_t *cred = credS;
-    CborEncoder encoder = { {.ptr = NULL }, .end = 0 };
-    CborEncoder credArray = { {.ptr = NULL }, .end = 0 };
-    CborEncoder credRootMap = { {.ptr = NULL }, .end = 0 };
+    CborEncoder encoder;
+    CborEncoder credArray;
+    CborEncoder credRootMap;
 
     if (0 == cborLen)
     {
@@ -167,7 +167,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
 
     while (cred)
     {
-        CborEncoder credMap = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+        CborEncoder credMap;
         size_t mapSize = CRED_MAP_SIZE;
         char *subject = NULL;
         if (cred->period)
@@ -215,7 +215,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
         //PublicData -- Not Mandatory
         if (SIGNED_ASYMMETRIC_KEY == cred->credType && cred->publicData.data)
         {
-            CborEncoder publicMap = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+            CborEncoder publicMap;
             const size_t publicMapSize = 2;
 
             cborEncoderResult = cbor_encode_text_string(&credMap, OIC_JSON_PUBLICDATA_NAME,
@@ -247,7 +247,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
         //PrivateData -- Not Mandatory
         if(cred->privateData.data)
         {
-            CborEncoder privateMap = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+            CborEncoder privateMap;
             const size_t privateMapSize = 2;
 
             cborEncoderResult = cbor_encode_text_string(&credMap, OIC_JSON_PRIVATEDATA_NAME,
@@ -352,7 +352,7 @@ exit:
 OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                                 OicSecCred_t **secCred)
 {
-    if (NULL == cborPayload || NULL == secCred || NULL != *secCred)
+    if (NULL == cborPayload || NULL == secCred || NULL != *secCred || 0 == size)
     {
         return OC_STACK_INVALID_PARAM;
     }
@@ -871,7 +871,7 @@ static OCEntityHandlerResult HandlePutRequest(const OCEntityHandlerRequest * ehR
 
     //Get binary representation of cbor
     OicSecCred_t *cred  = NULL;
-    uint8_t *payload = (((OCSecurityPayload*)ehRequest->payload)->securityData1);
+    uint8_t *payload = (((OCSecurityPayload*)ehRequest->payload)->securityData);
     size_t size = (((OCSecurityPayload*)ehRequest->payload)->payloadSize);
     OCStackResult res = CBORPayloadToCred(payload, size, &cred);
     if (res == OC_STACK_OK)
@@ -1018,7 +1018,7 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
 
     //Get binary representation of CBOR
     OicSecCred_t *cred  = NULL;
-    uint8_t *payload = ((OCSecurityPayload*)ehRequest->payload)->securityData1;
+    uint8_t *payload = ((OCSecurityPayload*)ehRequest->payload)->securityData;
     size_t size = ((OCSecurityPayload*)ehRequest->payload)->payloadSize;
     OCStackResult res = CBORPayloadToCred(payload, size, &cred);
     if ((OC_STACK_OK == res) && cred)
@@ -1104,7 +1104,7 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag,
     }
 
     //Send payload to request originator
-    ret = (SendSRMCBORResponse(ehRequest, ret, NULL, 0) == OC_STACK_OK) ?
+    ret = (SendSRMResponse(ehRequest, ret, NULL, 0) == OC_STACK_OK) ?
                        ret : OC_EH_ERROR;
 
     return ret;
@@ -1441,3 +1441,13 @@ exit:
     return ret;
 }
 
+OCStackResult GetCredRownerId(OicUuid_t *rowneruuid)
+{
+    OCStackResult retVal = OC_STACK_ERROR;
+    if (gCred)
+    {
+        *rowneruuid = gCred->rownerID;
+        retVal = OC_STACK_OK;
+    }
+    return retVal;
+}